mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
more changes to the odbc driver, now works for a simple test program
This commit is contained in:
parent
ba40f54c85
commit
90797c0121
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "connectparams.h"
|
#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,
|
static void *no_unused_var_warn[] = {software_version,
|
||||||
no_unused_var_warn};
|
no_unused_var_warn};
|
||||||
|
|
||||||
@ -413,11 +413,13 @@ SQLRETURN SQL_API SQLBindCol(
|
|||||||
SQLINTEGER cbValueMax,
|
SQLINTEGER cbValueMax,
|
||||||
SQLINTEGER FAR *pcbValue)
|
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(
|
SQLRETURN SQL_API SQLCancel(
|
||||||
@ -608,15 +610,15 @@ SQLRETURN SQL_API SQLExecute(
|
|||||||
SQLRETURN SQL_API SQLFetch(
|
SQLRETURN SQL_API SQLFetch(
|
||||||
SQLHSTMT hstmt)
|
SQLHSTMT hstmt)
|
||||||
{
|
{
|
||||||
int ret;
|
struct _hstmt *stmt = (struct _hstmt *) hstmt;
|
||||||
int i;
|
struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
|
||||||
struct _hstmt *stmt;
|
struct _henv *env = (struct _henv *) dbc->henv;
|
||||||
SQLINTEGER len=0;
|
|
||||||
unsigned char *src;
|
|
||||||
int srclen;
|
|
||||||
|
|
||||||
stmt=(struct _hstmt *)hstmt;
|
|
||||||
|
|
||||||
|
if (mdb_fetch_row(env->sql->cur_table)) {
|
||||||
|
return SQL_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return SQL_NO_DATA_FOUND;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLRETURN SQL_API SQLFreeHandle(
|
SQLRETURN SQL_API SQLFreeHandle(
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#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,
|
static void *no_unused_var_warn[] = {software_version,
|
||||||
no_unused_var_warn};
|
no_unused_var_warn};
|
||||||
|
|
||||||
@ -62,6 +62,8 @@ static void printStatementError(HSTMT hstmt, char *msg)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
retcode = SQLAllocEnv(&henv);
|
retcode = SQLAllocEnv(&henv);
|
||||||
|
|
||||||
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
|
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
|
||||||
@ -117,15 +119,9 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
retcode = SQLConnect(hdbc,
|
retcode = SQLConnect(hdbc,
|
||||||
/*
|
|
||||||
(UCHAR *)"SYBASE", SQL_NTS,
|
|
||||||
(UCHAR *)"ken", SQL_NTS,
|
|
||||||
(UCHAR *)"asdfasdf", SQL_NTS);
|
|
||||||
*/
|
|
||||||
(UCHAR *)"Northwind", SQL_NTS,
|
(UCHAR *)"Northwind", SQL_NTS,
|
||||||
(UCHAR *)"", SQL_NTS,
|
(UCHAR *)"", SQL_NTS,
|
||||||
(UCHAR *)"", SQL_NTS);
|
(UCHAR *)"", SQL_NTS);
|
||||||
/* sleep(600); */
|
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
||||||
{
|
{
|
||||||
UCHAR szSqlState[6];
|
UCHAR szSqlState[6];
|
||||||
@ -159,53 +155,23 @@ int main()
|
|||||||
exit(1);
|
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. */
|
/* Prepare the SQL statement with parameter markers. */
|
||||||
|
|
||||||
retcode = SQLPrepare(hstmt,
|
retcode = SQLPrepare(hstmt,
|
||||||
(unsigned char *)"select ShipName from Orders where OrderID > 11000",
|
(unsigned char *)"select * from Shippers",
|
||||||
SQL_NTS);
|
SQL_NTS);
|
||||||
|
|
||||||
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
||||||
{
|
{
|
||||||
long p1;
|
long p1;
|
||||||
// char p2[256];
|
|
||||||
long p1Len = sizeof(p1);
|
long p1Len = sizeof(p1);
|
||||||
// long p2Len;
|
|
||||||
long sAge = 1023;
|
long sAge = 1023;
|
||||||
long cbAge = sizeof(long);
|
long cbAge = sizeof(long);
|
||||||
UCHAR szCol1[60];
|
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");
|
printf("excecuting first statement\n");
|
||||||
retcode = SQLExecute(hstmt);
|
retcode = SQLExecute(hstmt);
|
||||||
if (retcode != SQL_SUCCESS)
|
if (retcode != SQL_SUCCESS) {
|
||||||
{
|
|
||||||
UCHAR szSqlState[6];
|
UCHAR szSqlState[6];
|
||||||
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
|
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
|
||||||
SDWORD dwNativeError;
|
SDWORD dwNativeError;
|
||||||
@ -219,23 +185,22 @@ int main()
|
|||||||
szSqlState, szErrorMsg);
|
szSqlState, szErrorMsg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
SQLBindCol(hstmt, 2, SQL_CHAR, szCol1, 60, NULL);
|
||||||
|
|
||||||
|
/* Execute statement with first row. */
|
||||||
|
|
||||||
|
i=0;
|
||||||
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// nop
|
i++;
|
||||||
printf("szCol1 = %s\n",szCol1);
|
printf("%d: szCol1 = %s\n",i,szCol1);
|
||||||
}
|
}
|
||||||
if (retcode != SQL_NO_DATA_FOUND)
|
if (retcode != SQL_NO_DATA_FOUND)
|
||||||
{
|
{
|
||||||
printStatementError(hstmt, "problem with SQLFetch");
|
printStatementError(hstmt, "problem with SQLFetch");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
SQLCloseCursor(hstmt);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
printf("Done\n");
|
printf("Done\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -426,16 +426,13 @@ int found = 0;
|
|||||||
sql->num_columns++;
|
sql->num_columns++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* verify all specified columns exist in this table */
|
||||||
for (i=0;i<sql->num_columns;i++) {
|
for (i=0;i<sql->num_columns;i++) {
|
||||||
sqlcol = g_ptr_array_index(sql->columns,i);
|
sqlcol = g_ptr_array_index(sql->columns,i);
|
||||||
found=0;
|
found=0;
|
||||||
for (j=0;j<table->num_cols;j++) {
|
for (j=0;j<table->num_cols;j++) {
|
||||||
col=g_ptr_array_index(table->columns,j);
|
col=g_ptr_array_index(table->columns,j);
|
||||||
if (!strcasecmp(sqlcol->name, col->name)) {
|
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);
|
sqlcol->disp_size = mdb_col_disp_size(col);
|
||||||
found=1;
|
found=1;
|
||||||
break;
|
break;
|
||||||
@ -453,11 +450,40 @@ int found = 0;
|
|||||||
sql_sarg=g_ptr_array_index(sql->sargs,i);
|
sql_sarg=g_ptr_array_index(sql->sargs,i);
|
||||||
mdb_add_sarg_by_name(table,sql_sarg->col_name, sql_sarg->sarg);
|
mdb_add_sarg_by_name(table,sql_sarg->col_name, sql_sarg->sarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
sql->cur_table = table;
|
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;
|
int j;
|
||||||
MdbSQLColumn *sqlcol;
|
MdbSQLColumn *sqlcol;
|
||||||
|
Loading…
Reference in New Issue
Block a user