9 #define SOCI_DB2_SOURCE 14 #pragma warning(disable:4355) 22 : session_(session),hasVectorUseElements(false),use_binding_method_(details::
db2::
BOUND_BY_NONE)
28 SQLRETURN cliRC = SQL_SUCCESS;
31 if (cliRC != SQL_SUCCESS) {
32 throw db2_soci_error(
"Error while allocation statement handle",cliRC);
38 SQLRETURN cliRC = SQL_SUCCESS;
40 cliRC=SQLFreeHandle(SQL_HANDLE_STMT,
hStmt);
41 if (cliRC != SQL_SUCCESS) {
52 enum { normal, in_quotes, in_name } state = normal;
56 for (std::string::const_iterator it = query.begin(), end = query.end();
71 const std::string::const_iterator next_it = it + 1;
72 if ((next_it != end) && (*next_it ==
':'))
99 if (std::isalnum(*it) || *it ==
'_')
105 names.push_back(name);
107 std::ostringstream ss;
118 if (state == in_name)
120 names.push_back(name);
121 std::ostringstream ss;
126 SQLRETURN cliRC = SQLPrepare(
hStmt, const_cast<SQLCHAR *>((
const SQLCHAR *)
query_.c_str()), SQL_NTS);
127 if (cliRC!=SQL_SUCCESS) {
135 SQLUINTEGER rows_processed = 0;
140 SQLSetStmtAttr(
hStmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &rows_processed, 0);
145 cliRC = SQLFreeStmt(
hStmt,SQL_CLOSE);
146 if (cliRC != SQL_SUCCESS)
151 cliRC = SQLExecute(
hStmt);
152 if (cliRC != SQL_SUCCESS && cliRC != SQL_SUCCESS_WITH_INFO)
157 SQLSMALLINT colCount;
158 SQLNumResultCols(
hStmt, &colCount);
160 if (number > 0 && colCount > 0)
162 return fetch(number);
173 SQLSetStmtAttr(
hStmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);
174 SQLSetStmtAttr(
hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)number, 0);
177 SQLRETURN cliRC = SQLFetch(
hStmt);
179 if (SQL_NO_DATA == cliRC)
184 if (cliRC != SQL_SUCCESS && cliRC != SQL_SUCCESS_WITH_INFO)
196 SQLRETURN cliRC = SQLRowCount(
hStmt, &rows);
197 if (cliRC != SQL_SUCCESS && cliRC != SQL_SUCCESS_WITH_INFO)
203 throw soci_error(
"Error getting affected row count: statement did not perform an update, insert, delete, or merge");
215 std::string
const &query)
223 SQLNumResultCols(
hStmt, &numCols);
228 data_type & type, std::string & columnName )
230 SQLCHAR colNameBuffer[2048];
231 SQLSMALLINT colNameBufferOverflow;
232 SQLSMALLINT dataType;
234 SQLSMALLINT decDigits;
235 SQLSMALLINT isNullable;
237 SQLRETURN cliRC = SQLDescribeCol(
hStmt, static_cast<SQLUSMALLINT>(colNum),
239 &colNameBufferOverflow, &dataType,
240 &colSize, &decDigits, &isNullable);
242 if (cliRC != SQL_SUCCESS)
247 char const *name =
reinterpret_cast<char const *
>(colNameBuffer);
248 columnName.assign(name, std::strlen(name));
254 case SQL_TYPE_TIMESTAMP:
274 case SQL_LONGVARCHAR:
282 SQLCHAR colNameBuffer[2048];
283 SQLSMALLINT colNameBufferOverflow;
284 SQLSMALLINT dataType;
286 SQLSMALLINT decDigits;
287 SQLSMALLINT isNullable;
289 SQLRETURN cliRC = SQLDescribeCol(
hStmt, static_cast<SQLUSMALLINT>(col),
291 &colNameBufferOverflow, &dataType,
292 &colSize, &decDigits, &isNullable);
294 if (cliRC != SQL_SUCCESS)
void prepare(std::string const &query, details::statement_type eType)
exec_fetch_result fetch(int number)
db2_session_backend & session_
db2_vector_into_type_backend * make_vector_into_type_backend()
std::size_t column_size(int col)
void describe_column(int colNum, data_type &dtype, std::string &columnName)
static const std::string sqlState(std::string const &msg, const SQLSMALLINT htype, const SQLHANDLE hndl)
db2_vector_use_type_backend * make_vector_use_type_backend()
std::string rewrite_for_procedure_call(std::string const &query)
bool hasVectorUseElements
db2_statement_backend(db2_session_backend &session)
db2_standard_into_type_backend * make_into_type_backend()
exec_fetch_result execute(int number)
long long get_affected_rows()
SQLUINTEGER numRowsFetched
std::vector< std::string > names
int prepare_for_describe()
SOCI_DB2_DECL db2_backend_factory const db2
db2_standard_use_type_backend * make_use_type_backend()