mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-11-26 02:09:49 +08:00
preping some of the sql stuff for the odbc driver
This commit is contained in:
@@ -12,6 +12,9 @@ typedef struct {
|
|||||||
GPtrArray *tables;
|
GPtrArray *tables;
|
||||||
int num_sargs;
|
int num_sargs;
|
||||||
GPtrArray *sargs;
|
GPtrArray *sargs;
|
||||||
|
MdbTableDef *cur_table;
|
||||||
|
/* FIX ME */
|
||||||
|
char *bound_values[256];
|
||||||
} MdbSQL;
|
} MdbSQL;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ int next_pg, next_pg_off;
|
|||||||
if (mdb->pg_buf[0]==0x01 &&
|
if (mdb->pg_buf[0]==0x01 &&
|
||||||
mdb->pg_buf[1]==0x01 &&
|
mdb->pg_buf[1]==0x01 &&
|
||||||
mdb_get_int32(mdb,4)==2) {
|
mdb_get_int32(mdb,4)==2) {
|
||||||
fprintf(stderr,"cat page %d\n", next_pg);
|
/* fprintf(stderr,"cat page %d\n", next_pg); */
|
||||||
rows = mdb_catalog_rows(mdb);
|
rows = mdb_catalog_rows(mdb);
|
||||||
for (i=0;i<rows;i++) {
|
for (i=0;i<rows;i++) {
|
||||||
if (mdb->pg_buf[11 + 2 * i] & 0x40) continue;
|
if (mdb->pg_buf[11 + 2 * i] & 0x40) continue;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "connectparams.h"
|
#include "connectparams.h"
|
||||||
|
|
||||||
static char software_version[] = "$Id: odbc.c,v 1.1 2001/07/10 22:36:20 brianb Exp $";
|
static char software_version[] = "$Id: odbc.c,v 1.2 2001/07/24 11:00:01 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};
|
||||||
|
|
||||||
@@ -50,6 +50,8 @@ static SQLRETURN SQL_API _SQLFreeStmt(SQLHSTMT hstmt, SQLUSMALLINT fOption);
|
|||||||
#define _MAX_ERROR_LEN 255
|
#define _MAX_ERROR_LEN 255
|
||||||
static char lastError[_MAX_ERROR_LEN+1];
|
static char lastError[_MAX_ERROR_LEN+1];
|
||||||
|
|
||||||
|
extern MdbSQL *g_sql;
|
||||||
|
|
||||||
static void LogError (const char* error)
|
static void LogError (const char* error)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -562,12 +564,26 @@ SQLRETURN SQL_API SQLError(
|
|||||||
static SQLRETURN SQL_API _SQLExecute( SQLHSTMT hstmt)
|
static SQLRETURN SQL_API _SQLExecute( SQLHSTMT hstmt)
|
||||||
{
|
{
|
||||||
struct _hstmt *stmt = (struct _hstmt *) hstmt;
|
struct _hstmt *stmt = (struct _hstmt *) hstmt;
|
||||||
|
struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
|
||||||
|
struct _henv *env = (struct _henv *) dbc->henv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fprintf(stderr,"query = %s\n",stmt->query);
|
fprintf(stderr,"query = %s\n",stmt->query);
|
||||||
_odbc_fix_literals(stmt);
|
_odbc_fix_literals(stmt);
|
||||||
|
|
||||||
return SQL_SUCCESS;
|
/* calls to yyparse would need to be serialized for thread safety */
|
||||||
|
|
||||||
|
/* begin unsafe */
|
||||||
|
g_input_ptr = stmt->query;
|
||||||
|
g_sql = env->sql;
|
||||||
|
if (yyparse()) {
|
||||||
|
/* end unsafe */
|
||||||
|
LogError("Couldn't parse SQL\n");
|
||||||
|
mdb_sql_reset(env->sql);
|
||||||
|
return SQL_ERROR;
|
||||||
|
} else {
|
||||||
|
return SQL_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLRETURN SQL_API SQLExecDirect(
|
SQLRETURN SQL_API SQLExecDirect(
|
||||||
@@ -1040,3 +1056,4 @@ static SQLSMALLINT _odbc_get_client_type(int srv_type)
|
|||||||
switch (srv_type) {
|
switch (srv_type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static char software_version[] = "$Id: unittest.c,v 1.1 2001/07/10 22:36:20 brianb Exp $";
|
static char software_version[] = "$Id: unittest.c,v 1.2 2001/07/24 11:00:01 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};
|
||||||
|
|
||||||
@@ -44,7 +44,6 @@ HENV henv;
|
|||||||
HDBC hdbc;
|
HDBC hdbc;
|
||||||
SQLHSTMT hstmt;
|
SQLHSTMT hstmt;
|
||||||
|
|
||||||
|
|
||||||
static void printStatementError(HSTMT hstmt, char *msg)
|
static void printStatementError(HSTMT hstmt, char *msg)
|
||||||
{
|
{
|
||||||
UCHAR szSqlState[6];
|
UCHAR szSqlState[6];
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include "mdbsql.h"
|
#include "mdbsql.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
void mdb_dump_results(MdbSQL *sql);
|
||||||
|
|
||||||
#ifdef HAVE_WORDEXP_H
|
#ifdef HAVE_WORDEXP_H
|
||||||
#define HAVE_WORDEXP
|
#define HAVE_WORDEXP
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
@@ -384,7 +386,6 @@ MdbCatalogEntry entry;
|
|||||||
MdbHandle *mdb = sql->mdb;
|
MdbHandle *mdb = sql->mdb;
|
||||||
MdbTableDef *table = NULL;
|
MdbTableDef *table = NULL;
|
||||||
MdbSQLTable *sql_tab;
|
MdbSQLTable *sql_tab;
|
||||||
char *bound_values[256];
|
|
||||||
MdbColumn *col;
|
MdbColumn *col;
|
||||||
MdbSQLColumn *sqlcol;
|
MdbSQLColumn *sqlcol;
|
||||||
MdbSQLSarg *sql_sarg;
|
MdbSQLSarg *sql_sarg;
|
||||||
@@ -431,10 +432,10 @@ int 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)) {
|
||||||
bound_values[i] = (char *) malloc(MDB_BIND_SIZE);
|
sql->bound_values[i] = (char *) malloc(MDB_BIND_SIZE);
|
||||||
bound_values[i][0] = '\0';
|
sql->bound_values[i][0] = '\0';
|
||||||
/* bind the column to its listed (SQL) position */
|
/* bind the column to its listed (SQL) position */
|
||||||
mdb_bind_column(table, j+1, bound_values[i]);
|
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;
|
||||||
@@ -452,6 +453,14 @@ 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;
|
||||||
|
mdb_dump_results(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mdb_dump_results(MdbSQL *sql)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
MdbSQLColumn *sqlcol;
|
||||||
|
|
||||||
/* print header */
|
/* print header */
|
||||||
for (j=0;j<sql->num_columns;j++) {
|
for (j=0;j<sql->num_columns;j++) {
|
||||||
@@ -471,10 +480,10 @@ int found = 0;
|
|||||||
fprintf(stdout,"\n");
|
fprintf(stdout,"\n");
|
||||||
|
|
||||||
/* print each row */
|
/* print each row */
|
||||||
while(mdb_fetch_row(table)) {
|
while(mdb_fetch_row(sql->cur_table)) {
|
||||||
for (j=0;j<sql->num_columns;j++) {
|
for (j=0;j<sql->num_columns;j++) {
|
||||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||||
print_value(bound_values[j],sqlcol->disp_size,!j);
|
print_value(sql->bound_values[j],sqlcol->disp_size,!j);
|
||||||
}
|
}
|
||||||
fprintf(stdout,"\n");
|
fprintf(stdout,"\n");
|
||||||
}
|
}
|
||||||
@@ -488,7 +497,7 @@ int found = 0;
|
|||||||
fprintf(stdout,"\n");
|
fprintf(stdout,"\n");
|
||||||
/* clean up */
|
/* clean up */
|
||||||
for (j=0;j<sql->num_columns;j++) {
|
for (j=0;j<sql->num_columns;j++) {
|
||||||
if (bound_values[j]) free(bound_values[j]);
|
if (sql->bound_values[j]) free(sql->bound_values[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the column and table names are no good now */
|
/* the column and table names are no good now */
|
||||||
|
|||||||
Reference in New Issue
Block a user