8 #define SOCI_ODBC_SOURCE 18 #pragma warning(disable:4312) 26 : session_(session), hstmt_(0), numRowsFetched_(0),
27 hasVectorUseElements_(false), boundByName_(false), boundByPos_(false),
41 "Allocating statement");
49 SQLFreeHandle(SQL_HANDLE_STMT,
hstmt_);
59 enum { eNormal, eInQuotes, eInName, eInAccessDate } state = eNormal;
62 query_.reserve(query.length());
64 for (std::string::const_iterator it = query.begin(), end = query.end();
78 state = eInAccessDate;
101 if (std::isalnum(*it) || *it ==
'_')
128 if (state == eInName)
134 SQLRETURN rc = SQLPrepare(
hstmt_, (SQLCHAR*)
query_.c_str(), (SQLINTEGER)
query_.size());
146 SQLULEN rows_processed = 0;
149 SQLSetStmtAttr(
hstmt_, SQL_ATTR_PARAMS_PROCESSED_PTR, &rows_processed, 0);
156 SQLRETURN rc = SQLExecute(
hstmt_);
170 rc = SQLGetDiagField(SQL_HANDLE_STMT,
hstmt_, 0, SQL_DIAG_ROW_COUNT, &res, 0, NULL);
178 while (rows_processed > 0 && SQLMoreResults(
hstmt_) == SQL_SUCCESS);
181 "Statement Execute");
191 SQLRETURN rc = SQLRowCount(
hstmt_, &res);
195 "Getting number of affected rows");
202 SQLSMALLINT colCount;
203 SQLNumResultCols(
hstmt_, &colCount);
205 if (number > 0 && colCount > 0)
207 return fetch(number);
217 SQLULEN
const row_array_size =
static_cast<SQLULEN
>(number);
219 SQLSetStmtAttr(
hstmt_, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);
220 SQLSetStmtAttr(
hstmt_, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)row_array_size, 0);
223 SQLRETURN rc = SQLFetch(
hstmt_);
225 if (SQL_NO_DATA == rc)
250 std::string
const &query)
258 SQLNumResultCols(
hstmt_, &numCols);
263 std::string & columnName)
265 SQLCHAR colNameBuffer[2048];
266 SQLSMALLINT colNameBufferOverflow;
267 SQLSMALLINT dataType;
269 SQLSMALLINT decDigits;
270 SQLSMALLINT isNullable;
272 SQLRETURN rc = SQLDescribeCol(
hstmt_, static_cast<SQLUSMALLINT>(colNum),
274 &colNameBufferOverflow, &dataType,
275 &colSize, &decDigits, &isNullable);
283 char const *name =
reinterpret_cast<char const *
>(colNameBuffer);
284 columnName.assign(name, std::strlen(name));
290 case SQL_TYPE_TIMESTAMP:
310 case SQL_LONGVARCHAR:
319 SQLCHAR colNameBuffer[2048];
320 SQLSMALLINT colNameBufferOverflow;
321 SQLSMALLINT dataType;
323 SQLSMALLINT decDigits;
324 SQLSMALLINT isNullable;
326 SQLRETURN rc = SQLDescribeCol(
hstmt_, static_cast<SQLUSMALLINT>(colNum),
328 &colNameBufferOverflow, &dataType,
329 &colSize, &decDigits, &isNullable);
virtual odbc_standard_into_type_backend * make_into_type_backend()
virtual exec_fetch_result fetch(int number)
std::size_t column_size(int position)
virtual odbc_standard_use_type_backend * make_use_type_backend()
virtual odbc_vector_use_type_backend * make_vector_use_type_backend()
bool is_odbc_error(SQLRETURN rc)
odbc_session_backend & session_
virtual void prepare(std::string const &query, details::statement_type eType)
std::vector< std::string > names_
virtual void describe_column(int colNum, data_type &dtype, std::string &columnName)
virtual exec_fetch_result execute(int number)
virtual long long get_affected_rows()
virtual int prepare_for_describe()
virtual odbc_vector_into_type_backend * make_vector_into_type_backend()
bool hasVectorUseElements_
virtual std::string rewrite_for_procedure_call(std::string const &query)
odbc_statement_backend(odbc_session_backend &session)
virtual int get_number_of_rows()