more changes to the odbc driver, now works for a simple test program

This commit is contained in:
brianb 2001-07-25 01:55:43 +00:00
parent ba40f54c85
commit 90797c0121
3 changed files with 58 additions and 65 deletions

View File

@ -32,7 +32,7 @@
#include "connectparams.h"
static char software_version[] = "$Id: odbc.c,v 1.2 2001/07/24 11:00:01 brianb Exp $";
static char software_version[] = "$Id: odbc.c,v 1.3 2001/07/25 01:55:43 brianb Exp $";
static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn};
@ -413,11 +413,13 @@ SQLRETURN SQL_API SQLBindCol(
SQLINTEGER cbValueMax,
SQLINTEGER FAR *pcbValue)
{
struct _hstmt *stmt;
struct _hstmt *stmt = (struct _hstmt *) hstmt;
struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
struct _henv *env = (struct _henv *) dbc->henv;
stmt = (struct _hstmt *) hstmt;
mdbsql_bind_column(env->sql, icol, rgbValue);
return SQL_SUCCESS;
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLCancel(
@ -608,15 +610,15 @@ SQLRETURN SQL_API SQLExecute(
SQLRETURN SQL_API SQLFetch(
SQLHSTMT hstmt)
{
int ret;
int i;
struct _hstmt *stmt;
SQLINTEGER len=0;
unsigned char *src;
int srclen;
stmt=(struct _hstmt *)hstmt;
struct _hstmt *stmt = (struct _hstmt *) hstmt;
struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
struct _henv *env = (struct _henv *) dbc->henv;
if (mdb_fetch_row(env->sql->cur_table)) {
return SQL_SUCCESS;
} else {
return SQL_NO_DATA_FOUND;
}
}
SQLRETURN SQL_API SQLFreeHandle(

View File

@ -23,7 +23,7 @@
#include <stdio.h>
static char software_version[] = "$Id: unittest.c,v 1.2 2001/07/24 11:00:01 brianb Exp $";
static char software_version[] = "$Id: unittest.c,v 1.3 2001/07/25 01:55:43 brianb Exp $";
static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn};
@ -62,6 +62,8 @@ static void printStatementError(HSTMT hstmt, char *msg)
int main()
{
int i;
retcode = SQLAllocEnv(&henv);
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
@ -117,15 +119,9 @@ int main()
retcode = SQLConnect(hdbc,
/*
(UCHAR *)"SYBASE", SQL_NTS,
(UCHAR *)"ken", SQL_NTS,
(UCHAR *)"asdfasdf", SQL_NTS);
*/
(UCHAR *)"Northwind", SQL_NTS,
(UCHAR *)"", SQL_NTS,
(UCHAR *)"", SQL_NTS);
/* sleep(600); */
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
UCHAR szSqlState[6];
@ -159,53 +155,23 @@ int main()
exit(1);
}
#if 0
retcode = SQLTables(hstmt,
(unsigned char *) NULL, 0,
(unsigned char *) "%", 1,
(unsigned char *) "%", 1,
(unsigned char *) "VIEW,TABLE", 10);
if (! (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO))
{
printf("got table stuff\n");
}
else
{
printStatementError(hstmt, "SQLTable");
}
#else
/* Prepare the SQL statement with parameter markers. */
retcode = SQLPrepare(hstmt,
(unsigned char *)"select ShipName from Orders where OrderID > 11000",
(unsigned char *)"select * from Shippers",
SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
long p1;
// char p2[256];
long p1Len = sizeof(p1);
// long p2Len;
long sAge = 1023;
long cbAge = sizeof(long);
UCHAR szCol1[60];
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
0, 0, szCol1, 0, &p1Len);
// p1Len = SQL_NULL_DATA;
/* Execute statement with first row. */
p1 = 8192;
// p1[0] = '%';
// p1Len = 1;
// p2[0] = '%';
// p2Len = 1;
printf("excecuting first statement\n");
retcode = SQLExecute(hstmt);
if (retcode != SQL_SUCCESS)
{
if (retcode != SQL_SUCCESS) {
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
@ -219,23 +185,22 @@ int main()
szSqlState, szErrorMsg);
exit(1);
}
SQLBindCol(hstmt, 2, SQL_CHAR, szCol1, 60, NULL);
/* Execute statement with first row. */
i=0;
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
{
// nop
printf("szCol1 = %s\n",szCol1);
i++;
printf("%d: szCol1 = %s\n",i,szCol1);
}
if (retcode != SQL_NO_DATA_FOUND)
{
printStatementError(hstmt, "problem with SQLFetch");
exit(1);
}
/*
SQLCloseCursor(hstmt);
*/
}
#endif
printf("Done\n");
return 1;

View File

@ -426,16 +426,13 @@ int found = 0;
sql->num_columns++;
}
}
/* verify all specified columns exist in this table */
for (i=0;i<sql->num_columns;i++) {
sqlcol = g_ptr_array_index(sql->columns,i);
found=0;
for (j=0;j<table->num_cols;j++) {
col=g_ptr_array_index(table->columns,j);
if (!strcasecmp(sqlcol->name, col->name)) {
sql->bound_values[i] = (char *) malloc(MDB_BIND_SIZE);
sql->bound_values[i][0] = '\0';
/* bind the column to its listed (SQL) position */
mdb_bind_column(table, j+1, sql->bound_values[i]);
sqlcol->disp_size = mdb_col_disp_size(col);
found=1;
break;
@ -453,11 +450,40 @@ int found = 0;
sql_sarg=g_ptr_array_index(sql->sargs,i);
mdb_add_sarg_by_name(table,sql_sarg->col_name, sql_sarg->sarg);
}
sql->cur_table = table;
mdb_dump_results(sql);
}
void mdb_dump_results(MdbSQL *sql)
void mdbsql_bind_column(MdbSQL *sql, int colnum, char *varaddr)
{
MdbTableDef *table = sql->cur_table;
MdbSQLColumn *sqlcol;
MdbColumn *col;
int i, j;
/* sql columns are traditionally 1 based, so decrement colnum */
sqlcol = g_ptr_array_index(sql->columns,colnum - 1);
for (j=0;j<table->num_cols;j++) {
col=g_ptr_array_index(table->columns,j);
if (!strcasecmp(sqlcol->name, col->name)) {
/* bind the column to its listed (SQL) position */
mdb_bind_column(table, j+1, varaddr);
break;
}
}
}
void mdbsql_bind_all(MdbSQL *sql)
{
int i;
for (i=0;i<sql->num_columns;i++) {
sql->bound_values[i] = (char *) malloc(MDB_BIND_SIZE);
sql->bound_values[i][0] = '\0';
mdbsql_bind_column(sql, i+1, sql->bound_values[i]);
}
}
void mdbsql_dump_results(MdbSQL *sql)
{
int j;
MdbSQLColumn *sqlcol;