summaryrefslogtreecommitdiff
path: root/libodbcpp/selectcommand.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-09-13 19:57:25 +0000
committerrandomdan <randomdan@localhost>2010-09-13 19:57:25 +0000
commit95bc5ac789c2f29220f76c94fc93d6379dcd00c6 (patch)
tree2af19c25a48dfb13b2db681544ad6fa82407c567 /libodbcpp/selectcommand.cpp
parentUse the right header for BUFSIZ (diff)
downloadlibdbpp-odbc-95bc5ac789c2f29220f76c94fc93d6379dcd00c6.tar.bz2
libdbpp-odbc-95bc5ac789c2f29220f76c94fc93d6379dcd00c6.tar.xz
libdbpp-odbc-95bc5ac789c2f29220f76c94fc93d6379dcd00c6.zip
Remove duplication in ODBC::Connection constructors
Remove pointless specialisation on _Column for strings Set cursor type to scrollable (required to refetch a row) Resize binds if fetched data is truncated Support scrolling fetch (default is old 'next record' behaviour)
Diffstat (limited to 'libodbcpp/selectcommand.cpp')
-rw-r--r--libodbcpp/selectcommand.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/libodbcpp/selectcommand.cpp b/libodbcpp/selectcommand.cpp
index 88a071f..3b903d6 100644
--- a/libodbcpp/selectcommand.cpp
+++ b/libodbcpp/selectcommand.cpp
@@ -3,6 +3,7 @@
#include "column.h"
#include <sqlext.h>
#include <stdio.h>
+#include <string.h>
ODBC::SelectCommand::SelectCommand(const Connection & c, const std::string & s) :
Command(c, s)
@@ -26,12 +27,12 @@ ODBC::SelectCommand::~SelectCommand()
}
bool
-ODBC::SelectCommand::fetch()
+ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset)
{
if (columns.size() == 0) {
execute();
}
- RETCODE rc = SQLFetch(hStmt);
+ RETCODE rc = SQLFetchScroll(hStmt, orientation, offset);
switch (rc) {
case SQL_SUCCESS:
for (Columns::iterator i = columns.begin(); i != columns.end(); i++) {
@@ -42,6 +43,18 @@ ODBC::SelectCommand::fetch()
case SQL_NO_DATA:
return false;
default:
+ {
+ SQLCHAR sqlstatus[5];
+ RETCODE diagrc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, sqlstatus, NULL, NULL, 0, NULL);
+ if (SQL_SUCCEEDED(diagrc)) {
+ if (!strncmp((const char*)sqlstatus, "01004", 5)) {
+ for (Columns::iterator i = columns.begin(); i != columns.end(); i++) {
+ (*i)->resize(hStmt);
+ }
+ return fetch(SQL_FETCH_RELATIVE, 0);
+ }
+ }
+ }
throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: SQLFetch",
__FUNCTION__);
}
@@ -87,7 +100,7 @@ ODBC::SelectCommand::execute()
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
{
- _Column<SQLCHARVEC>* s = new _Column<SQLCHARVEC>(colName, col);
+ StringColumn* s = new StringColumn(colName, col);
s->value.resize(bindSize + 1);
s->bind(hStmt, sqlcol, SQL_C_CHAR, &s->value[0], bindSize + 1);
columns[col] = s;