mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-03-10 00:20:54 +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:
@@ -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