Skip to Content.
Sympa Menu

freetds - RE: [freetds] ODBC prepared statements to sybase 12.5 not working

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Alex Hornby <alex AT anvil.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Cc: Frediano Ziglio <freddyz77 AT tin.it>
  • Subject: RE: [freetds] ODBC prepared statements to sybase 12.5 not working
  • Date: Fri, 08 Aug 2003 13:11:16 -0000


Hi Freddy,

Heres a patch that adds support for the missing statement attributes
used by libobdc++. It helps libodbc++ get a lot further.

Could you review it and apply to CVS?

Cheers,
Alex.

Index: include/tdsodbc.h
===================================================================
RCS file: /cvsroot/freetds/freetds/include/tdsodbc.h,v
retrieving revision 1.40
diff -u -r1.40 tdsodbc.h
--- include/tdsodbc.h 4 Aug 2003 15:14:08 -0000 1.40
+++ include/tdsodbc.h 8 Aug 2003 13:06:17 -0000
@@ -237,6 +237,8 @@
struct _sql_errors errs;
char ard, ird, apd, ipd;
SQLRETURN lastrc;
+ SQLUSMALLINT* row_status_ptr;
+ SQLUINTEGER* rows_fetched_ptr;
};

struct _sql_param_info
Index: src/odbc/odbc.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/odbc/odbc.c,v
retrieving revision 1.205
diff -u -r1.205 odbc.c
--- src/odbc/odbc.c 5 Aug 2003 09:03:36 -0000 1.205
+++ src/odbc/odbc.c 8 Aug 2003 13:06:21 -0000
@@ -948,7 +948,9 @@
stmt->htype = SQL_HANDLE_STMT;
stmt->hdbc = dbc;
*phstmt = (SQLHSTMT) stmt;
-
+ stmt->row_status_ptr = 0;
+ stmt->rows_fetched_ptr = 0;
+
ODBC_RETURN(dbc, SQL_SUCCESS);
}

@@ -1666,8 +1668,12 @@
cur = cur->next;
}
}
- stmt->row++;
+ stmt->row++;

+ if ( stmt->row_status_ptr ) {
+ stmt->row_status_ptr[0] = SQL_ROW_NOROW;
+ }
+
ret = tds_process_row_tokens(stmt->hdbc->tds_socket, &rowtype,
&computeid);
if (ret == TDS_NO_MORE_ROWS) {
tdsdump_log(TDS_DBG_INFO1, "SQLFetch: NO_DATA_FOUND\n");
@@ -1690,8 +1696,12 @@

tds_get_conversion_type(colinfo->column_type,
colinfo->column_size),
src,
srclen,
colinfo->column_bindtype, colinfo->column_varaddr,
colinfo->column_bindlen);
- if (len < 0)
- ODBC_RETURN(stmt, SQL_ERROR);
+ if (len < 0) {
+ if ( stmt->row_status_ptr ) {
+ stmt->row_status_ptr[0] =
SQL_ROW_ERROR;
+ }
+ ODBC_RETURN(stmt, SQL_ERROR);
+ }
}
if (colinfo->column_lenbind) {
if (tds_get_null(resinfo->current_row, i))
@@ -1701,8 +1711,22 @@
}
}
if (ret == TDS_SUCCEED) {
+
+ if ( stmt->rows_fetched_ptr ) {
+ (*(stmt->rows_fetched_ptr))++;
+ tdsdump_log(TDS_DBG_INFO1, "Got row (%d)\n",
*(stmt->rows_fetched_ptr));
+
+ }
+
+ if ( stmt->row_status_ptr ) {
+ stmt->row_status_ptr[0] = SQL_ROW_SUCCESS;
+ }
ODBC_RETURN(stmt, SQL_SUCCESS);
} else {
+ if ( stmt->row_status_ptr ) {
+ stmt->row_status_ptr[0] = SQL_ROW_ERROR;
+ }
+
tdsdump_log(TDS_DBG_INFO1, "SQLFetch: !TDS_SUCCEED (%d)\n",
ret);
ODBC_RETURN(stmt, SQL_ERROR);
}
@@ -1958,7 +1982,7 @@
break;

case SQL_ATTR_ROW_NUMBER:
- *ui_val = 0; /* TODO */
+ *ui_val = (SQLUINTEGER)(stmt->row);
break;

case SQL_ATTR_USE_BOOKMARKS:
@@ -1986,6 +2010,15 @@
*StringLength = sizeof(SQL_IS_POINTER);
break;

+ case SQL_ATTR_ROW_STATUS_PTR:
+ *(SQLPOINTER *) Value = &stmt->row_status_ptr;
+ *StringLength = sizeof(SQL_IS_POINTER);
+ break;
+ case SQL_ATTR_ROWS_FETCHED_PTR:
+ *(SQLPOINTER *) Value = &stmt->rows_fetched_ptr;
+ *StringLength = sizeof(SQL_IS_POINTER);
+ break;
+
/* TODO ?? what to do */
case SQL_ATTR_FETCH_BOOKMARK_PTR:
case SQL_ATTR_METADATA_ID:
@@ -1996,9 +2029,7 @@
case SQL_ATTR_PARAMSET_SIZE:
case SQL_ATTR_ROW_BIND_OFFSET_PTR:
case SQL_ATTR_ROW_BIND_TYPE:
- case SQL_ATTR_ROW_OPERATION_PTR:
- case SQL_ATTR_ROW_STATUS_PTR:
- case SQL_ATTR_ROWS_FETCHED_PTR:
+ case SQL_ATTR_ROW_OPERATION_PTR:
case SQL_ATTR_SIMULATE_CURSOR:
default:
odbc_errs_add(&stmt->errs, "HY092", NULL, NULL);
@@ -3154,6 +3185,21 @@
case SQL_ROWSET_SIZE:
/* Always 1 */
break;
+
+ case SQL_ATTR_ROW_STATUS_PTR:
+ stmt->row_status_ptr = (SQLUSMALLINT*) vParam;
+ break;
+ case SQL_ATTR_ROWS_FETCHED_PTR:
+ stmt->rows_fetched_ptr = (SQLUINTEGER*) vParam;
+ break;
+ case SQL_ATTR_ROW_ARRAY_SIZE:
+ if ( vParam != 1 ) {
+ tdsdump_log(TDS_DBG_INFO1,
"odbc:SQLSetStmtOption: Attempt to set fetch size to %d. Only value of 1
supported\n", vParam);
+ odbc_errs_add(&stmt->errs, "HY092", NULL,
NULL);
+ ODBC_RETURN(stmt, SQL_ERROR);
+ }
+ break;
+
case SQL_CURSOR_TYPE:
if (vParam == SQL_CURSOR_FORWARD_ONLY)
ODBC_RETURN(stmt, SQL_SUCCESS);


--
Alex Hornby <alex AT anvil.com>





Archive powered by MHonArc 2.6.24.

Top of Page