mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-10-21 02:57:42 +08:00
put all unicode convert stuff in iconv.c. Use SQLGetPrivateProfile() if available (handles odbc.ini file in different places). Fix bug for list tables/describe in odbc.
This commit is contained in:
13
ChangeLog
13
ChangeLog
@@ -1,3 +1,16 @@
|
||||
Fri Mar 5 23:24:04 EST 2004 Brian Bruns <brian@bruns.com>
|
||||
* configure.in: AC_SUBST on ODBCINSTLIB
|
||||
* include/mdbtools.h:
|
||||
* src/libmdb/Makefile.am:
|
||||
* src/odbc/Makefile.am:
|
||||
* src/libmdb/data.c:
|
||||
* src/libmdb/iconv.c: move ascii/unicode convert code to iconv.c
|
||||
* include/mdbsql.h:
|
||||
* src/util/mdb-sql.c:
|
||||
* src/odbc/odbc.c:
|
||||
* src/sql/mdbsql.c: new fetch routine to handle worktables
|
||||
* src/odbc/connectparams.c: use odbcinst lib routines if available
|
||||
|
||||
Thu Mar 4 23:24:27 EST 2004 Brian Bruns <brian@bruns.com>
|
||||
* include/mdbtools.h: add prototype for mdb_index_find_next()
|
||||
* src/libmdb/write.c: add mdb_pack_row4() (Jeff Smith). Fix null mask order (Jeff, me)
|
||||
|
@@ -89,6 +89,8 @@ if test "x$odbc" = "xtrue"; then
|
||||
AC_DEFINE_UNQUOTED(HAVE_SQLGETPRIVATEPROFILESTRING, 1, [Define to 1 if you have the SQLGetPrivateProfileString function.])])
|
||||
fi
|
||||
|
||||
AC_SUBST(ODBCINSTLIB)
|
||||
|
||||
dnl check for glib/gtk/gnome
|
||||
AM_PATH_GLIB_2_0(2.0.0)
|
||||
|
||||
|
@@ -72,5 +72,7 @@ extern void mdb_sql_describe_table(MdbSQL *sql);
|
||||
extern int mdb_sql_run_query(MdbSQL *sql, char *query);
|
||||
extern void mdb_sql_set_maxrow(MdbSQL *sql, int maxrow);
|
||||
extern int mdb_sql_eval_expr(MdbSQL *sql, char *const1, int op, char *const2);
|
||||
extern void mdb_sql_bind_all(MdbSQL *sql);
|
||||
extern int mdb_sql_fetch_row(MdbSQL *sql, MdbTableDef *table);
|
||||
|
||||
#endif
|
||||
|
@@ -433,7 +433,6 @@ extern int mdb_find_end_of_row(MdbHandle *mdb, int row);
|
||||
extern int mdb_col_fixed_size(MdbColumn *col);
|
||||
extern int mdb_col_disp_size(MdbColumn *col);
|
||||
extern void mdb_bind_len(MdbTableDef *table, int col_num, int *len_ptr);
|
||||
extern int mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, int len, char *dest);
|
||||
extern int mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr);
|
||||
extern int mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size);
|
||||
extern void mdb_set_date_fmt(const char *);
|
||||
@@ -505,4 +504,8 @@ extern void mdb_temp_table_add_col(MdbTableDef *table, MdbColumn *col);
|
||||
extern int mdb_get_option(unsigned long optnum);
|
||||
void mdb_debug(int klass, char *fmt, ...);
|
||||
|
||||
/* iconv.c */
|
||||
extern int mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, int len, char *dest);
|
||||
extern int mdb_ascii2unicode(MdbHandle *mdb, unsigned char *buf, int offset, int len, char *dest);
|
||||
|
||||
#endif /* _mdbtools_h_ */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
lib_LTLIBRARIES = libmdb.la
|
||||
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c map.c props.c worktable.c options.c
|
||||
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c map.c props.c worktable.c options.c iconv.c
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
LIBS = $(GLIB_LIBS) -lm
|
||||
|
@@ -557,13 +557,14 @@ int mdb_rewind_table(MdbTableDef *table)
|
||||
|
||||
return 0;
|
||||
}
|
||||
int mdb_fetch_row(MdbTableDef *table)
|
||||
int
|
||||
mdb_fetch_row(MdbTableDef *table)
|
||||
{
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
int rows;
|
||||
int rc;
|
||||
guint32 pg;
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
int rows;
|
||||
int rc;
|
||||
guint32 pg;
|
||||
|
||||
if (table->num_rows==0)
|
||||
return 0;
|
||||
@@ -1168,20 +1169,3 @@ int mdb_col_fixed_size(MdbColumn *col)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, int len, char *dest)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (buf[offset]==0xff &&
|
||||
buf[offset+1]==0xfe) {
|
||||
strncpy(dest, &buf[offset+2], len-2);
|
||||
dest[len-2]='\0';
|
||||
} else {
|
||||
/* convert unicode to ascii, rather sloppily */
|
||||
for (i=0;i<len;i+=2)
|
||||
dest[i/2] = buf[offset + i];
|
||||
dest[len/2]='\0';
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ MDBDIR = ../libmdb
|
||||
MDBSOURCES = backend.c index.c money.c catalog.c kkd.c sargs.c \
|
||||
data.c like.c table.c dump.c file.c mem.c \
|
||||
map.c props.c worktable.c options.c \
|
||||
write.c stats.c
|
||||
write.c stats.c iconv.c
|
||||
|
||||
bin_PROGRAMS = unittest
|
||||
lib_LTLIBRARIES = libmdbodbc.la
|
||||
@@ -15,7 +15,7 @@ libmdbodbc_la_LIBADD= $(patsubst %, $(SQLDIR)/%, \
|
||||
$(patsubst %.c, %.lo, $(SQLSOURCES))) \
|
||||
$(patsubst %, $(MDBDIR)/%, \
|
||||
$(patsubst %.c, %.lo, $(MDBSOURCES)))
|
||||
LIBS = @LEXLIB@ $(GLIB_LIBS)
|
||||
LIBS = @LEXLIB@ $(GLIB_LIBS) $(ODBCINSTLIB)
|
||||
unittest_LDADD = libmdbodbc.la ../libmdb/libmdb.la ../sql/libmdbsql.la
|
||||
|
||||
## Need blank statement to avoid compiling odbc.c
|
||||
|
@@ -25,8 +25,9 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "connectparams.h"
|
||||
|
||||
#if !HAVE_SQLGETPRIVATEPROFILESTRING
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* * Last resort place to check for INI file. This is usually set at compile time
|
||||
@@ -36,6 +37,11 @@
|
||||
#define SYS_ODBC_INI "/etc/odbc.ini"
|
||||
#endif
|
||||
|
||||
#if defined(FILENAME_MAX) && FILENAME_MAX < 512
|
||||
#undef FILENAME_MAX
|
||||
#define FILENAME_MAX 512
|
||||
#endif
|
||||
|
||||
#define max_line 256
|
||||
static char line[max_line];
|
||||
|
||||
@@ -85,10 +91,40 @@ void FreeConnectParams (ConnectParams* params)
|
||||
}
|
||||
}
|
||||
|
||||
#if !HAVE_SQLGETPRIVATEPROFILESTRING
|
||||
int LoadDSN (
|
||||
const gchar* iniFileName, const gchar* dsnName, GHashTable* table)
|
||||
{
|
||||
FILE* stream;
|
||||
gchar* name;
|
||||
gchar* value;
|
||||
|
||||
|
||||
if ((stream = fopen (iniFileName, "r" )) != NULL )
|
||||
{
|
||||
if (!FindSection (stream, dsnName))
|
||||
{
|
||||
g_printerr ("Couldn't find DSN %s in %s\n", iniFileName, dsnName);
|
||||
fclose (stream);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (GetNextItem (stream, &name, &value))
|
||||
{
|
||||
g_hash_table_insert (table, strdup (name), strdup (value));
|
||||
}
|
||||
}
|
||||
|
||||
fclose( stream );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the settings for the specified ODBC DSN
|
||||
*/
|
||||
|
||||
gboolean LookupDSN (ConnectParams* params, const gchar* dsnName)
|
||||
{
|
||||
if (!params) {
|
||||
@@ -114,7 +150,6 @@ gboolean LookupDSN (ConnectParams* params, const gchar* dsnName)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the value of a given ODBC Connection Parameter
|
||||
*/
|
||||
@@ -127,6 +162,25 @@ gchar* GetConnectParam (ConnectParams* params, const gchar* paramName)
|
||||
return g_hash_table_lookup (params->table, paramName);
|
||||
}
|
||||
|
||||
#else
|
||||
gboolean LookupDSN (ConnectParams* params, const gchar* dsnName)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
gchar* GetConnectParam (ConnectParams* params, const gchar* paramName)
|
||||
{
|
||||
static char tmp[FILENAME_MAX];
|
||||
|
||||
/* use old servername */
|
||||
tmp[0] = '\0';
|
||||
if (SQLGetPrivateProfileString(params->dsnName->str, paramName, "", tmp, FILENAME_MAX, "odbc.ini") > 0) {
|
||||
return tmp;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
#endif /* !HAVE_SQLGETPRIVATEPROFILESTRING */
|
||||
|
||||
/*
|
||||
* Apply a connection string to the ODBC Parameter Settings
|
||||
*/
|
||||
@@ -346,35 +400,6 @@ static int FindSection (FILE* stream, const char* section)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LoadDSN (
|
||||
const gchar* iniFileName, const gchar* dsnName, GHashTable* table)
|
||||
{
|
||||
FILE* stream;
|
||||
gchar* name;
|
||||
gchar* value;
|
||||
|
||||
if ((stream = fopen (iniFileName, "r" )) != NULL )
|
||||
{
|
||||
if (!FindSection (stream, dsnName))
|
||||
{
|
||||
g_printerr ("Couldn't find DSN %s in %s\n", iniFileName, dsnName);
|
||||
fclose (stream);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (GetNextItem (stream, &name, &value))
|
||||
{
|
||||
g_hash_table_insert (table, strdup (name), strdup (value));
|
||||
}
|
||||
}
|
||||
|
||||
fclose( stream );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a hash from all the characters
|
||||
*/
|
||||
@@ -452,7 +477,6 @@ static gboolean cleanup (gpointer key, gpointer value, gpointer user_data)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_SQLGETPRIVATEPROFILESTRING */
|
||||
|
||||
#ifdef UNIXODBC
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "connectparams.h"
|
||||
|
||||
static char software_version[] = "$Id: odbc.c,v 1.12 2004/02/08 21:54:20 brianb Exp $";
|
||||
static char software_version[] = "$Id: odbc.c,v 1.13 2004/03/06 05:13:28 brianb Exp $";
|
||||
static void *no_unused_var_warn[] = {software_version,
|
||||
no_unused_var_warn};
|
||||
|
||||
@@ -820,7 +820,7 @@ struct _henv *env = (struct _henv *) dbc->henv;
|
||||
//cur = cur->next;
|
||||
//}
|
||||
|
||||
if (mdb_fetch_row(env->sql->cur_table)) {
|
||||
if (mdb_sql_fetch_row(env->sql, env->sql->cur_table)) {
|
||||
stmt->rows_affected++;
|
||||
return SQL_SUCCESS;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user