Commit c0b27c4f authored by Hiroshi Inoue's avatar Hiroshi Inoue

1) Fix a few bugs about SQLGetData()

   reported by Mika Mantyla.
2) Timestamp precision.
3) Separate ODBC3.0 files.
parent 0f450dae
...@@ -424,6 +424,8 @@ create_empty_bindings(int num_columns) ...@@ -424,6 +424,8 @@ create_empty_bindings(int num_columns)
new_bindings[i].buffer = NULL; new_bindings[i].buffer = NULL;
new_bindings[i].used = NULL; new_bindings[i].used = NULL;
new_bindings[i].data_left = -1; new_bindings[i].data_left = -1;
new_bindings[i].ttlbuf = NULL;
new_bindings[i].ttlbuflen = 0;
} }
return new_bindings; return new_bindings;
......
...@@ -22,6 +22,8 @@ struct BindInfoClass_ ...@@ -22,6 +22,8 @@ struct BindInfoClass_
char *buffer; /* pointer to the buffer */ char *buffer; /* pointer to the buffer */
Int4 *used; /* used space in the buffer (for strings Int4 *used; /* used space in the buffer (for strings
* not counting the '\0') */ * not counting the '\0') */
char *ttlbuf; /* to save the large result */
Int4 ttlbuflen; /* the buffer length */
Int2 returntype; /* kind of conversion to be applied when Int2 returntype; /* kind of conversion to be applied when
* returning (SQL_C_DEFAULT, * returning (SQL_C_DEFAULT,
* SQL_C_CHAR...) */ * SQL_C_CHAR...) */
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
*------- *-------
*/ */
#include "pgtypes.h"
#include "columninfo.h" #include "columninfo.h"
#include "connection.h" #include "connection.h"
...@@ -95,7 +96,16 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn) ...@@ -95,7 +96,16 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
new_atttypmod = (Int4) SOCK_get_int(sock, 4); new_atttypmod = (Int4) SOCK_get_int(sock, 4);
/* Subtract the header length */ /* Subtract the header length */
new_atttypmod -= 4; switch (new_adtid)
{
case PG_TYPE_DATETIME:
case PG_TYPE_TIMESTAMP_NO_TMZONE:
case PG_TYPE_TIME:
case PG_TYPE_TIME_WITH_TMZONE:
break;
default:
new_atttypmod -= 4;
}
if (new_atttypmod < 0) if (new_atttypmod < 0)
new_atttypmod = -1; new_atttypmod = -1;
......
This diff is collapsed.
...@@ -27,7 +27,8 @@ typedef struct ...@@ -27,7 +27,8 @@ typedef struct
int hh; int hh;
int mm; int mm;
int ss; int ss;
} SIMPLE_TIME; int fr;
} SIMPLE_TIME;
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col); int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType, int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
......
...@@ -216,32 +216,6 @@ PGAPI_GetInfo( ...@@ -216,32 +216,6 @@ PGAPI_GetInfo(
case SQL_DRIVER_ODBC_VER: case SQL_DRIVER_ODBC_VER:
p = DRIVER_ODBC_VER; p = DRIVER_ODBC_VER;
#ifdef DRIVER_CURSOR_IMPLEMENT
{
static char dver[32];
SQLGetPrivateProfileString(DBMS_NAME,
"DriverODBCVer", "", dver, sizeof(dver), "odbcinst.ini");
if (dver[0])
{
int major,
minor;
mylog("REGISTRY_ODBC_VER = %s\n", dver)
;
if (sscanf(dver, "%x.%x", &major, &minor) >= 2)
{
Int2 drv_ver = (major << 8) + minor;
if (drv_ver > ODBCVER)
{
conn->driver_version = drv_ver;
p = dver;
}
}
}
}
#endif /* DRIVER_CURSOR_IMPLEMENT */
break; break;
case SQL_DRIVER_VER: /* ODBC 1.0 */ case SQL_DRIVER_VER: /* ODBC 1.0 */
...@@ -842,6 +816,7 @@ PGAPI_GetFunctions( ...@@ -842,6 +816,7 @@ PGAPI_GetFunctions(
if (fFunction == SQL_API_ALL_FUNCTIONS) if (fFunction == SQL_API_ALL_FUNCTIONS)
{ {
#if (ODBCVER < 0x0300)
if (ci->drivers.lie) if (ci->drivers.lie)
{ {
int i; int i;
...@@ -856,6 +831,7 @@ PGAPI_GetFunctions( ...@@ -856,6 +831,7 @@ PGAPI_GetFunctions(
pfExists[i] = TRUE; pfExists[i] = TRUE;
} }
else else
#endif
{ {
memset(pfExists, 0, sizeof(UWORD) * 100); memset(pfExists, 0, sizeof(UWORD) * 100);
...@@ -2685,7 +2661,7 @@ PGAPI_PrimaryKeys( ...@@ -2685,7 +2661,7 @@ PGAPI_PrimaryKeys(
/* /*
* Multibyte support stuff for SQLForeignKeys(). * Multibyte support stuff for SQLForeignKeys().
* There may be much more effective way in the * There may be much more effective way in the
* future version. The way is very forcive currently. * future version. The way is very forcible currently.
*/ */
static BOOL static BOOL
isMultibyte(const unsigned char *str) isMultibyte(const unsigned char *str)
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
*------- *-------
*/ */
#ifndef ODBCVER_REP #ifndef ODBCVER
#define ODBCVER_REP 0x0300 #define ODBCVER 0x0300
#endif #endif
#include "psqlodbc.h" #include "psqlodbc.h"
#include <stdio.h> #include <stdio.h>
...@@ -344,7 +344,7 @@ SQLGetStmtAttr(HSTMT StatementHandle, ...@@ -344,7 +344,7 @@ SQLGetStmtAttr(HSTMT StatementHandle,
len = 4; len = 4;
break; break;
case SQL_ATTR_AUTO_IPD: /* 10001 */ case SQL_ATTR_AUTO_IPD: /* 10001 */
case SQL_ATTR_ROW_BIND_TYPE: /* == SQL_BIND_TYPE */ /* case SQL_ATTR_ROW_BIND_TYPE: ** == SQL_BIND_TYPE(ODBC2.0) */
case SQL_ATTR_PARAMSET_SIZE: /* 22 */ case SQL_ATTR_PARAMSET_SIZE: /* 22 */
case SQL_ATTR_PARAM_STATUS_PTR: /* 20 */ case SQL_ATTR_PARAM_STATUS_PTR: /* 20 */
case SQL_ATTR_PARAMS_PROCESSED_PTR: /* 21 */ case SQL_ATTR_PARAMS_PROCESSED_PTR: /* 21 */
...@@ -484,7 +484,7 @@ SQLSetStmtAttr(HSTMT StatementHandle, ...@@ -484,7 +484,7 @@ SQLSetStmtAttr(HSTMT StatementHandle,
case SQL_ATTR_APP_ROW_DESC: /* 10010 */ case SQL_ATTR_APP_ROW_DESC: /* 10010 */
case SQL_ATTR_APP_PARAM_DESC: /* 10011 */ case SQL_ATTR_APP_PARAM_DESC: /* 10011 */
case SQL_ATTR_AUTO_IPD: /* 10001 */ case SQL_ATTR_AUTO_IPD: /* 10001 */
/* case SQL_ATTR_ROW_BIND_TYPE: */ /* == SQL_BIND_TYPE */ /* case SQL_ATTR_ROW_BIND_TYPE: ** == SQL_BIND_TYPE(ODBC2.0) */
case SQL_ATTR_IMP_ROW_DESC: /* 10012 */ case SQL_ATTR_IMP_ROW_DESC: /* 10012 */
case SQL_ATTR_IMP_PARAM_DESC: /* 10013 */ case SQL_ATTR_IMP_PARAM_DESC: /* 10013 */
case SQL_ATTR_METADATA_ID: /* 10014 */ case SQL_ATTR_METADATA_ID: /* 10014 */
......
...@@ -536,6 +536,67 @@ getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si ...@@ -536,6 +536,67 @@ getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
return p; return p;
} }
static Int2
getTimestampScale(StatementClass *stmt, Int4 type, int col)
{
ConnectionClass *conn = SC_get_conn (stmt);
Int4 atttypmod;
QResultClass *result;
ColumnInfoClass *flds;
mylog("getTimestampScale: type=%d, col=%d\n", type, col);
if (col < 0)
return 0;
if (PG_VERSION_LT(conn, 7.2))
return 0;
result = SC_get_Result(stmt);
/*
* Manual Result Sets -- use assigned column width (i.e., from
* set_tuplefield_string)
*/
atttypmod = 0;
if (stmt->manual_result)
{
flds = result->fields;
if (flds)
atttypmod = flds->atttypmod[col];
mylog("atttypmod1=%d\n", atttypmod);
}
else
atttypmod = QR_get_atttypmod(result, col);
mylog("atttypmod2=%d\n", atttypmod);
return (atttypmod > -1 ? atttypmod : 0);
}
static Int4
getTimestampPrecision(StatementClass *stmt, Int4 type, int col)
{
Int4 fixed, scale;
mylog("getTimestampPrecision: type=%d, col=%d\n", type, col);
switch (type)
{
case PG_TYPE_TIME:
fixed = 8;
break;
case PG_TYPE_TIME_WITH_TMZONE:
fixed = 11;
break;
case PG_TYPE_TIMESTAMP_NO_TMZONE:
fixed = 19;
break;
default:
fixed = 22;
break;
}
scale = getTimestampScale(stmt, type, col);
return (scale > 0) ? fixed + 1 + scale : fixed;
}
/* /*
* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, PG_TYPE_NUMERIC, SQLColumns will * For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, PG_TYPE_NUMERIC, SQLColumns will
...@@ -591,7 +652,8 @@ pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si ...@@ -591,7 +652,8 @@ pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
case PG_TYPE_TIMESTAMP: case PG_TYPE_TIMESTAMP:
return 22; return 22;
case PG_TYPE_DATETIME: case PG_TYPE_DATETIME:
return 22; /* return 22; */
return getTimestampPrecision(stmt, type, col);
case PG_TYPE_BOOL: case PG_TYPE_BOOL:
return 1; return 1;
...@@ -728,7 +790,8 @@ pgtype_scale(StatementClass *stmt, Int4 type, int col) ...@@ -728,7 +790,8 @@ pgtype_scale(StatementClass *stmt, Int4 type, int col)
case PG_TYPE_TIMESTAMP: case PG_TYPE_TIMESTAMP:
return 0; return 0;
case PG_TYPE_DATETIME: case PG_TYPE_DATETIME:
return 0; /* return 0; */
return getTimestampScale(stmt, type, col);
case PG_TYPE_NUMERIC: case PG_TYPE_NUMERIC:
return getNumericScale(stmt, type, col); return getNumericScale(stmt, type, col);
......
...@@ -58,8 +58,10 @@ ...@@ -58,8 +58,10 @@
#define PG_TYPE_VARCHAR 1043 #define PG_TYPE_VARCHAR 1043
#define PG_TYPE_DATE 1082 #define PG_TYPE_DATE 1082
#define PG_TYPE_TIME 1083 #define PG_TYPE_TIME 1083
#define PG_TYPE_TIMESTAMP_NO_TMZONE 1114 /* since 7.2 */
#define PG_TYPE_DATETIME 1184 #define PG_TYPE_DATETIME 1184
#define PG_TYPE_TIMESTAMP 1296 #define PG_TYPE_TIME_WITH_TMZONE 1266 /* since 7.1 */
#define PG_TYPE_TIMESTAMP 1296 /* deprecated since 7.0 */
#define PG_TYPE_NUMERIC 1700 #define PG_TYPE_NUMERIC 1700
/* extern Int4 pgtypes_defined[]; */ /* extern Int4 pgtypes_defined[]; */
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Comments: See "notice.txt" for copyright and license information. * Comments: See "notice.txt" for copyright and license information.
* *
* $Id: psqlodbc.h,v 1.53 2001/10/28 06:26:14 momjian Exp $ * $Id: psqlodbc.h,v 1.54 2001/11/05 09:46:17 inoue Exp $
* *
*/ */
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
#include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */ #include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */
/* Must come before sql.h */ /* Must come before sql.h */
#ifdef ODBCVER_REP #ifndef ODBCVER
#define ODBCVER ODBCVER_REP
#else
#define ODBCVER 0x0250 #define ODBCVER 0x0250
#endif /* ODBCVER_REP */ #endif /* ODBCVER_REP */
...@@ -77,18 +75,27 @@ typedef UInt4 Oid; ...@@ -77,18 +75,27 @@ typedef UInt4 Oid;
#endif #endif
/* Driver stuff */ /* Driver stuff */
#define DRIVER_ODBC_VER "02.50"
#define DRIVERNAME "PostgreSQL ODBC" #define DRIVERNAME "PostgreSQL ODBC"
#if (ODBCVER >= 0x0300)
#define DRIVER_ODBC_VER "03.00"
#define DBMS_NAME "PostgreSQL30"
#else
#define DRIVER_ODBC_VER "02.50"
#define DBMS_NAME "PostgreSQL" #define DBMS_NAME "PostgreSQL"
#endif /* ODBCVER */
#define POSTGRESDRIVERVERSION "07.01.0008" #define POSTGRESDRIVERVERSION "07.01.0009"
#ifdef WIN32 #ifdef WIN32
#if (ODBCVER >= 0x0300)
#define DRIVER_FILE_NAME "PSQLODBC30.DLL"
#else
#define DRIVER_FILE_NAME "PSQLODBC.DLL" #define DRIVER_FILE_NAME "PSQLODBC.DLL"
#endif /* ODBCVER */
#else #else
#define DRIVER_FILE_NAME "libpsqlodbc.so" #define DRIVER_FILE_NAME "libpsqlodbc.so"
#endif #endif /* WIN32 */
/* Limits */ /* Limits */
#ifdef WIN32 #ifdef WIN32
......
...@@ -354,8 +354,8 @@ END ...@@ -354,8 +354,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 7,1,0,8 FILEVERSION 7,1,0,9
PRODUCTVERSION 7,1,0,8 PRODUCTVERSION 7,1,0,9
FILEFLAGSMASK 0x3L FILEFLAGSMASK 0x3L
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
...@@ -377,14 +377,14 @@ BEGIN ...@@ -377,14 +377,14 @@ BEGIN
VALUE "CompanyName", "Insight Distribution Systems\0" VALUE "CompanyName", "Insight Distribution Systems\0"
#endif #endif
VALUE "FileDescription", "PostgreSQL Driver\0" VALUE "FileDescription", "PostgreSQL Driver\0"
VALUE "FileVersion", " 07.01.0008\0" VALUE "FileVersion", " 07.01.0009\0"
VALUE "InternalName", "psqlodbc\0" VALUE "InternalName", "psqlodbc\0"
VALUE "LegalCopyright", "\0" VALUE "LegalCopyright", "\0"
VALUE "LegalTrademarks", "ODBC(TM) is a trademark of Microsoft Corporation. Microsoft is a registered trademark of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation.\0" VALUE "LegalTrademarks", "ODBC(TM) is a trademark of Microsoft Corporation. Microsoft is a registered trademark of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation.\0"
VALUE "OriginalFilename", "psqlodbc.dll\0" VALUE "OriginalFilename", "psqlodbc.dll\0"
VALUE "PrivateBuild", "\0" VALUE "PrivateBuild", "\0"
VALUE "ProductName", "Microsoft Open Database Connectivity\0" VALUE "ProductName", "Microsoft Open Database Connectivity\0"
VALUE "ProductVersion", " 07.01.0008\0" VALUE "ProductVersion", " 07.01.0009\0"
VALUE "SpecialBuild", "\0" VALUE "SpecialBuild", "\0"
END END
END END
......
...@@ -320,7 +320,15 @@ SC_Destructor(StatementClass *self) ...@@ -320,7 +320,15 @@ SC_Destructor(StatementClass *self)
*/ */
/* about that here. */ /* about that here. */
if (self->bindings) if (self->bindings)
{
int lf;
for (lf = 0; lf < self->bindings_allocated; lf++)
{
if (self->bindings[lf].ttlbuf != NULL)
free(self->bindings[lf].ttlbuf);
}
free(self->bindings); free(self->bindings);
}
/* Free the parsed table information */ /* Free the parsed table information */
if (self->ti) if (self->ti)
......
...@@ -84,7 +84,6 @@ CLEAN : ...@@ -84,7 +84,6 @@ CLEAN :
-@erase "$(INTDIR)\tuple.obj" -@erase "$(INTDIR)\tuple.obj"
-@erase "$(INTDIR)\tuplelist.obj" -@erase "$(INTDIR)\tuplelist.obj"
-@erase "$(INTDIR)\odbcapi.obj" -@erase "$(INTDIR)\odbcapi.obj"
-@erase "$(INTDIR)\odbcapi30.obj"
-@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\psqlodbc.dll" -@erase "$(OUTDIR)\psqlodbc.dll"
-@erase "$(OUTDIR)\psqlodbc.exp" -@erase "$(OUTDIR)\psqlodbc.exp"
...@@ -169,7 +168,6 @@ LINK32_OBJS= \ ...@@ -169,7 +168,6 @@ LINK32_OBJS= \
"$(INTDIR)\tuple.obj" \ "$(INTDIR)\tuple.obj" \
"$(INTDIR)\tuplelist.obj" \ "$(INTDIR)\tuplelist.obj" \
"$(INTDIR)\odbcapi.obj" \ "$(INTDIR)\odbcapi.obj" \
"$(INTDIR)\odbcapi30.obj" \
"$(INTDIR)\psqlodbc.res" "$(INTDIR)\psqlodbc.res"
"$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) "$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
...@@ -219,7 +217,6 @@ CLEAN : ...@@ -219,7 +217,6 @@ CLEAN :
-@erase "$(INTDIR)\tuple.obj" -@erase "$(INTDIR)\tuple.obj"
-@erase "$(INTDIR)\tuplelist.obj" -@erase "$(INTDIR)\tuplelist.obj"
-@erase "$(INTDIR)\odbcapi.obj" -@erase "$(INTDIR)\odbcapi.obj"
-@erase "$(INTDIR)\odbcapi30.obj"
-@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb" -@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\psqlodbc.dll" -@erase "$(OUTDIR)\psqlodbc.dll"
...@@ -307,7 +304,6 @@ LINK32_OBJS= \ ...@@ -307,7 +304,6 @@ LINK32_OBJS= \
"$(INTDIR)\tuple.obj" \ "$(INTDIR)\tuple.obj" \
"$(INTDIR)\tuplelist.obj" \ "$(INTDIR)\tuplelist.obj" \
"$(INTDIR)\odbcapi.obj" \ "$(INTDIR)\odbcapi.obj" \
"$(INTDIR)\odbcapi30.obj" \
"$(INTDIR)\psqlodbc.res" "$(INTDIR)\psqlodbc.res"
"$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) "$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
...@@ -496,11 +492,6 @@ SOURCE=odbcapi.c ...@@ -496,11 +492,6 @@ SOURCE=odbcapi.c
$(CPP) $(CPP_PROJ) $(SOURCE) $(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=odbcapi30.c
"$(INTDIR)\odbcapi30.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF !ENDIF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment