Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
2  configure.in
@@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(mdbtools, 0.6pre1, [mdbtools-dev@lists.sourceforge.net])
+AC_INIT(mdbtools, 0.7~rc1, [mdbtools-dev@lists.sourceforge.net])
AC_CONFIG_SRCDIR(src/extras/mdb-dump.c)
AM_INIT_AUTOMAKE
View
2  doc/Makefile.am
@@ -6,7 +6,7 @@ PRODUCT = MDBTools
dist_man_MANS = mdb-tables.1 mdb-ver.1 mdb-export.1 mdb-schema.1 mdb-sql.1 \
mdb-array.1 mdb-header.1 mdb-hexdump.1 mdb-parsecsv.1 mdb-prop.1 gmdb2.1
-
+DISTCLEANFILES = ${dist_man_MANS}
EXTRA_DIST = mdb-tables.txt mdb-ver.txt mdb-export.txt mdb-schema.txt mdb-sql.txt faq.html txt2man install.sgml
html: install.tgz
View
4 include/mdbodbc.h
@@ -49,8 +49,8 @@ struct _hstmt {
char query[4096];
struct _sql_bind_info *bind_head;
int rows_affected;
- int icol;
- int pos;
+ int icol; /* SQLGetData: last column */
+ int pos; /* SQLGetData: last position (truncated result) */
};
struct _sql_bind_info {
View
2  src/gmdb2/debug.c
@@ -652,7 +652,7 @@ gmdb_debug_dissect_data_pg3(GtkTreeStore *store, char *fbuf, int offset, int len
row_len = (get_uint16(fbuf+offset+10+(i-1)*2)
& 0x0FFF) - row_start;
str = g_strdup_printf("Row %d", i+1);
- /*container = */gmdb_debug_add_item(store, NULL, str,
+ container = gmdb_debug_add_item(store, NULL, str,
row_start, row_len);
/* usage pages have parent id of 0 (database) and do not
View
2  src/libmdb/Makefile.am
@@ -1,5 +1,5 @@
lib_LTLIBRARIES = libmdb.la
libmdb_la_SOURCES= catalog.c mem.c file.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
-libmdb_la_LDFLAGS = -version-info 1:0:0 -Wl,--version-script=$(srcdir)/libmdb.map
+libmdb_la_LDFLAGS = -version-info 2:0:0 -Wl,--version-script=$(srcdir)/libmdb.map
AM_CPPFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
LIBS = $(GLIB_LIBS) @LIBS@
View
6 src/libmdb/libmdb.map
@@ -1,8 +1,4 @@
-LIBMDB_1.0 {
-# global:
-# *;
-# }
-# LIBMDB_2.0 {
+{
global:
mdb_*;
_mdb_put_int16;
View
2  src/odbc/Makefile.am
@@ -12,7 +12,7 @@ lib_LTLIBRARIES = libmdbodbc.la
AM_CPPFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) $(ODBC_CFLAGS)
libmdbodbc_la_SOURCES= odbc.c connectparams.c
libmdbodbc_la_LIBADD= ../libmdb/libmdb.la ../sql/libmdbsql.la
-libmdbodbc_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmdbodbc.map
+libmdbodbc_la_LDFLAGS = -version-info 1:0:0 -Wl,--version-script=$(srcdir)/libmdbodbc.map
LIBS = @LEXLIB@ $(GLIB_LIBS) $(ODBC_LIBS)
unittest_LDADD = libmdbodbc.la ../libmdb/libmdb.la ../sql/libmdbsql.la
View
7 src/odbc/libmdbodbc.map
@@ -1,10 +1,7 @@
-LIBMDBODBC_0.0 {
-#global:
-# *;
-#}
-#LIBMDBODBC_1.0 {
+{
global:
SQL*;
+ ODBCINST*;
local:
*;
View
188 src/odbc/odbc.c
@@ -35,7 +35,7 @@
static iconv_t iconv_in,iconv_out;
#endif //ENABLE_ODBC_W
-static SQLSMALLINT _odbc_get_client_type(int srv_type);
+static SQLSMALLINT _odbc_get_client_type(MdbColumn *col);
static int _odbc_fix_literals(struct _hstmt *stmt);
//static int _odbc_get_server_type(int clt_type);
static int _odbc_get_string_size(int size, SQLCHAR FAR *str);
@@ -732,15 +732,23 @@ SQLRETURN SQL_API SQLDescribeCol(
break;
}
}
+ if (i==table->num_cols) {
+ fprintf(stderr, "Column %s lost\n", (char*)sqlcol->name);
+ return SQL_ERROR;
+ }
if (szColName) {
namelen = MIN(cbColNameMax,strlen(sqlcol->name));
strncpy((char*)szColName, sqlcol->name, namelen);
szColName[namelen]='\0';
- *pcbColName=namelen;
+ if (pcbColName)
+ *pcbColName=namelen;
+ } else {
+ if (pcbColName)
+ *pcbColName = strlen(sqlcol->name);
}
- if (pfSqlType) { //Currently libmdbodbc.so returns values as string in SQLGetData() even though it is a number.
- *pfSqlType = SQL_VARCHAR;//_odbc_get_client_type(col->col_type);
+ if (pfSqlType) {
+ *pfSqlType = _odbc_get_client_type(col);
}
if (pcbColDef) {
*pcbColDef = col->col_size;
@@ -1302,8 +1310,8 @@ SQLRETURN SQL_API SQLColumns(
ts3 = mdb_ascii2unicode(mdb, col->name, 0, (char*)t3, MDB_BIND_SIZE);
ts5 = mdb_ascii2unicode(mdb, "FIX ME", 0, (char*)t5, MDB_BIND_SIZE);
nullable = SQL_NO_NULLS;
- datatype = _odbc_get_client_type(col->col_type);
- sqldatatype = _odbc_get_client_type(col->col_type);
+ datatype = _odbc_get_client_type(col);
+ sqldatatype = _odbc_get_client_type(col);
ordinal = j+1;
/* Set all fields to NULL */
@@ -1369,8 +1377,8 @@ SQLRETURN SQL_API SQLGetData(
SQLUSMALLINT icol,
SQLSMALLINT fCType,
SQLPOINTER rgbValue,
- SQLINTEGER cbValueMax,
- SQLINTEGER FAR *pcbValue)
+ SQLLEN cbValueMax,
+ SQLLEN FAR *pcbValue)
{
struct _hstmt *stmt;
struct _hdbc *dbc;
@@ -1403,42 +1411,124 @@ SQLRETURN SQL_API SQLGetData(
}
}
- if(icol!=stmt->icol){stmt->icol=icol;stmt->pos=0;}
+ if (icol!=stmt->icol) {
+ stmt->icol=icol;
+ stmt->pos=0;
+ }
+
+ if (!rgbValue) {
+ strcpy(sqlState, "HY009");
+ return SQL_ERROR;
+ }
+ if (pcbValue && *pcbValue<0) {
+ strcpy(sqlState, "HY090");
+ return SQL_ERROR;
+ }
+
if (col->col_type == MDB_BOOL) {
- if(cbValueMax==0){if(pcbValue)*pcbValue=1;return SQL_SUCCESS_WITH_INFO;}
- if(stmt->pos>=1)return SQL_NO_DATA;
- if(!rgbValue){
- strcpy(sqlState,"HY009");
- return SQL_ERROR;
- }
- strcpy(rgbValue, (col->cur_value_len)?"0":"1");
+ // bool cannot be null
+ *(BOOL*)rgbValue = col->cur_value_len ? 0 : 1;
if (pcbValue)
*pcbValue = 1;
- stmt->pos=1;
- } else if (col->cur_value_len) {
- char *str = mdb_col_to_string(mdb,mdb->pg_buf,
- col->cur_value_start,col->col_type,col->cur_value_len);
- if(cbValueMax==0){if(pcbValue)*pcbValue=strlen(str);g_free(str);return SQL_SUCCESS_WITH_INFO;}
- if(stmt->pos>=strlen(str))return SQL_NO_DATA;
- if(!rgbValue){
- strcpy(sqlState,"HY009");
- return SQL_ERROR;
- }
- i=cbValueMax<=strlen(str+stmt->pos)?cbValueMax-1:strlen(str+stmt->pos);
- memcpy(rgbValue,str+stmt->pos,i);
- *((char*)(rgbValue)+i)=0;
- stmt->pos+=i;
- g_free(str);
- if (pcbValue)
- *pcbValue = i;
- } else {
- /* When NULL data is retrieved, non-null pcbValue is required */
- if (pcbValue) {
- *pcbValue = SQL_NULL_DATA;
- } else {
+ return SQL_SUCCESS;
+ }
+ if (col->cur_value_len == 0) {
+ /* When NULL data is retrieved, non-null pcbValue is
+ required */
+ if (!pcbValue) {
strcpy(sqlState, "22002");
return SQL_ERROR;
- }
+ }
+ *pcbValue = SQL_NULL_DATA;
+ return SQL_SUCCESS;
+ }
+
+ switch(col->col_type) {
+ case MDB_BYTE:
+ *(SQLSMALLINT*)rgbValue = mdb_get_byte(mdb->pg_buf, col->cur_value_start);
+ if (pcbValue)
+ *pcbValue = sizeof(SQLSMALLINT);
+ break;
+ case MDB_INT:
+ *(SQLSMALLINT*)rgbValue = (SQLSMALLINT)mdb_get_int16(mdb->pg_buf, col->cur_value_start);
+ if (pcbValue)
+ *pcbValue = sizeof(SQLSMALLINT);
+ break;
+ case MDB_LONGINT:
+ *(SQLINTEGER*)rgbValue = mdb_get_int32(mdb->pg_buf, col->cur_value_start);
+ if (pcbValue)
+ *pcbValue = sizeof(SQLINTEGER);
+ break;
+ // case MDB_MONEY: TODO
+ case MDB_FLOAT:
+ *(float*)rgbValue = mdb_get_single(mdb->pg_buf, col->cur_value_start);
+ if (pcbValue)
+ *pcbValue = sizeof(float);
+ break;
+ case MDB_DOUBLE:
+ *(double*)rgbValue = mdb_get_double(mdb->pg_buf, col->cur_value_start);
+ if (pcbValue)
+ *pcbValue = sizeof(double);
+ break;
+ case MDB_DATETIME: ;
+#if ODBCVER >= 0x0300
+ struct tm tmp_t;
+ mdb_date_to_tm(mdb_get_double(mdb->pg_buf, col->cur_value_start), &tmp_t);
+
+ const char *format = mdb_col_get_prop(col, "Format");
+ if (format && !strcmp(format, "Short Date")) {
+ DATE_STRUCT sql_dt;
+ sql_dt.year = tmp_t.tm_year + 1900;
+ sql_dt.month = tmp_t.tm_mon + 1;
+ sql_dt.day = tmp_t.tm_mday;
+ *(DATE_STRUCT*)rgbValue = sql_dt;
+ if (pcbValue)
+ *pcbValue = sizeof(DATE_STRUCT);
+ } else {
+ TIMESTAMP_STRUCT sql_ts;
+ sql_ts.year = tmp_t.tm_year + 1900;
+ sql_ts.month = tmp_t.tm_mon + 1;
+ sql_ts.day = tmp_t.tm_mday;
+ sql_ts.hour = tmp_t.tm_hour;
+ sql_ts.minute = tmp_t.tm_min;
+ sql_ts.second = tmp_t.tm_sec;
+ sql_ts.fraction = 0;
+
+ *(TIMESTAMP_STRUCT*)rgbValue = sql_ts;
+ if (pcbValue)
+ *pcbValue = sizeof(TIMESTAMP_STRUCT);
+ }
+ break;
+#endif // returns text if old odbc
+ default: ;
+ char *str = mdb_col_to_string(mdb, mdb->pg_buf,
+ col->cur_value_start, col->col_type, col->cur_value_len);
+ int len = strlen(str);
+ if (stmt->pos >= len)
+ return SQL_NO_DATA;
+ if (!cbValueMax) {
+ if (pcbValue)
+ *pcbValue = len;
+ free(str);
+ return SQL_SUCCESS_WITH_INFO;
+ }
+ if (len - stmt->pos > cbValueMax) {
+ /* the buffer we were given is too small, so
+ truncate it to the size of the buffer */
+ strncpy(rgbValue, str, cbValueMax);
+ if (pcbValue)
+ *pcbValue = cbValueMax;
+ stmt->pos += cbValueMax;
+ free(str);
+ strcpy(sqlState, "01004"); // trunctated
+ return SQL_SUCCESS_WITH_INFO;
+ }
+ strncpy(rgbValue, str + stmt->pos, len - stmt->pos);
+ if (pcbValue)
+ *pcbValue = len - stmt->pos;
+ stmt->pos += len - stmt->pos;
+ free(str);
+ break;
}
return SQL_SUCCESS;
}
@@ -1990,33 +2080,33 @@ static int _odbc_get_server_type(int clt_type)
}
return 0;
}*/
-static SQLSMALLINT _odbc_get_client_type(int srv_type)
+static SQLSMALLINT _odbc_get_client_type(MdbColumn *col)
{
- switch (srv_type) {
+ switch (col->col_type) {
case MDB_BOOL:
return SQL_BIT;
- break;
case MDB_BYTE:
return SQL_TINYINT;
- break;
case MDB_INT:
return SQL_SMALLINT;
- break;
case MDB_LONGINT:
return SQL_INTEGER;
- break;
case MDB_MONEY:
return SQL_DECIMAL;
- break;
case MDB_FLOAT:
return SQL_FLOAT;
- break;
case MDB_DOUBLE:
return SQL_DOUBLE;
- break;
+ case MDB_DATETIME: ;
+#if ODBCVER >= 0x0300
+ const char *format = mdb_col_get_prop(col, "Format");
+ if (format && !strcmp(format, "Short Date"))
+ return SQL_TYPE_DATE;
+ else
+ return SQL_TYPE_TIMESTAMP;
+#endif // returns text otherwise
case MDB_TEXT:
return SQL_VARCHAR;
- break;
default:
// fprintf(stderr,"Unknown type %d\n",srv_type);
break;
View
2  src/odbc/unittest.c
@@ -158,7 +158,7 @@ int i;
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
UCHAR szCol1[60];
- SQLINTEGER length;
+ SQLLEN length;
printf("excecuting first statement\n");
retcode = SQLExecute(hstmt);
View
2  src/sql/Makefile.am
@@ -1,6 +1,6 @@
lib_LTLIBRARIES = libmdbsql.la
libmdbsql_la_SOURCES= mdbsql.c parser.y lexer.l
-libmdbsql_la_LDFLAGS = -version-info 1:0:0 -Wl,--version-script=$(srcdir)/libmdbsql.map
+libmdbsql_la_LDFLAGS = -version-info 2:0:0 -Wl,--version-script=$(srcdir)/libmdbsql.map
DISTCLEANFILES = parser.c parser.h lexer.c
AM_CPPFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
LIBS = $(GLIB_LIBS)
View
6 src/sql/libmdbsql.map
@@ -1,8 +1,4 @@
-LIBMDBSQL_1.0 {
-#global:
-# *;
-#}
-#LIBMDBSQL_2.0 {
+{
global:
mdb_sql_*;

No commit comments for this range

Something went wrong with that request. Please try again.