Commit 4b47467a authored by Hiroshi Inoue's avatar Hiroshi Inoue

1) Implement SQLParamOptions().

2) Handle Multiple results and implement SQLMoreResult().
3) Improve multibyte handling thanks to Eiji Tokuya.
4) Add new options.
   LF <-> CR/LF converion.
   TRUE is -1 (for VB).
5) Introduce unicode(UCS-2) support.
6) Reduce the length of connection strings.
7) Improve SQLError, SQLGetDiagRec(ODBC 3.0).
8) Implement SQLTablePrivileges().
9) Miscellaneous changes for ODBC 3.0 support.
parent 21f8aa39
......@@ -7,7 +7,7 @@
* Classes: BindInfoClass, ParameterInfoClass
*
* API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
* SQLParamOptions(NI)
* SQLParamOptions
*
* Comments: See "notice.txt" for copyright and license information.
*-------
......@@ -331,17 +331,9 @@ PGAPI_ParamOptions(
mylog("%s: entering... %d %x\n", func, crow, pirow);
if (crow == 1) /* temporary solution and must be
* rewritten later */
{
if (pirow)
*pirow = 1;
return SQL_SUCCESS;
}
stmt->errornumber = CONN_UNSUPPORTED_OPTION;
stmt->errormsg = "Function not implemented";
SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
return SQL_ERROR;
stmt->options.paramset_size = crow;
stmt->options.param_processed_ptr = pirow;
return SQL_SUCCESS;
}
......
This diff is collapsed.
......@@ -151,6 +151,8 @@ typedef struct
char focus_password;
char disallow_premature;
char updatable_cursors;
char lf_conversion;
char true_is_minus1;
GLOBAL_VALUES drivers; /* moved from driver's option */
} ConnInfo;
......@@ -271,6 +273,7 @@ struct ConnectionClass_
char *client_encoding;
char *server_encoding;
#endif /* MULTIBYTE */
int ccsc;
};
......@@ -290,6 +293,7 @@ struct ConnectionClass_
/* prototypes */
ConnectionClass *CC_Constructor(void);
void CC_conninfo_init(ConnInfo *conninfo);
char CC_Destructor(ConnectionClass *self);
int CC_cursor_count(ConnectionClass *self);
char CC_cleanup(ConnectionClass *self);
......@@ -301,7 +305,7 @@ char CC_connect(ConnectionClass *self, char do_password);
char CC_add_statement(ConnectionClass *self, StatementClass *stmt);
char CC_remove_statement(ConnectionClass *self, StatementClass *stmt);
char CC_get_error(ConnectionClass *self, int *number, char **message);
QResultClass *CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi);
QResultClass *CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, BOOL);
void CC_clear_error(ConnectionClass *self);
char *CC_create_errormsg(ConnectionClass *self);
int CC_send_function(ConnectionClass *conn, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
......@@ -309,7 +313,7 @@ char CC_send_settings(ConnectionClass *self);
void CC_lookup_lo(ConnectionClass *conn);
void CC_lookup_pg_version(ConnectionClass *conn);
void CC_initialize_pg_version(ConnectionClass *conn);
void CC_log_error(char *func, char *desc, ConnectionClass *self);
void CC_log_error(const char *func, const char *desc, const ConnectionClass *self);
int CC_get_max_query_len(const ConnectionClass *self);
#endif
This diff is collapsed.
......@@ -21,7 +21,7 @@
/* convert_escape results */
#define CONVERT_ESCAPE_OK 0
#define CONVERT_ESCAPE_OVERFLOW 1
#define CONVERT_ESCAPE_ERROR 2
#define CONVERT_ESCAPE_ERROR -1
typedef struct
{
......@@ -43,8 +43,8 @@ int convert_escape(const char *value, StatementClass *stmt,
int *npos, int *stsize, const char **val_resume);
BOOL convert_money(const char *s, char *sout, size_t soutmax);
char parse_datetime(char *buf, SIMPLE_TIME *st);
int convert_linefeeds(const char *s, char *dst, size_t max, BOOL *changed);
int convert_special_chars(const char *si, char *dst, int used);
int convert_linefeeds(const char *s, char *dst, size_t max, BOOL convlf, BOOL *changed);
int convert_special_chars(const char *si, char *dst, int used, BOOL convlf,int ccsc);
int convert_pgbinary_to_char(const char *value, char *rgbValue, int cbValueMax);
int convert_from_pgbinary(const unsigned char *value, unsigned char *rgbValue, int cbValueMax);
......
This diff is collapsed.
......@@ -89,6 +89,35 @@
#define INI_TRANSLATIONOPTION "TranslationOption"
#define INI_DISALLOWPREMATURE "DisallowPremature"
#define INI_UPDATABLECURSORS "UpdatableCursors"
#define INI_LFCONVERSION "LFConversion"
#define INI_TRUEISMINUS1 "TrueIsMinus1"
/* Bit representaion for abbreviated connection strings */
#define BIT_LFCONVERSION (1L)
#define BIT_UPDATABLECURSORS (1L<<1)
#define BIT_DISALLOWPREMATURE (1L<<2)
#define BIT_UNIQUEINDEX (1L<<3)
#define BIT_PROTOCOL_63 (1L<<4)
#define BIT_PROTOCOL_64 (1L<<5)
#define BIT_UNKNOWN_DONTKNOW (1L<<6)
#define BIT_UNKNOWN_ASMAX (1L<<7)
#define BIT_OPTIMIZER (1L<<8)
#define BIT_KSQO (1L<<9)
#define BIT_COMMLOG (1L<<10)
#define BIT_DEBUG (1L<<11)
#define BIT_PARSE (1L<<12)
#define BIT_CANCELASFREESTMT (1L<<13)
#define BIT_USEDECLAREFETCH (1L<<14)
#define BIT_READONLY (1L<<15)
#define BIT_TEXTASLONGVARCHAR (1L<<16)
#define BIT_UNKNOWNSASLONGVARCHAR (1L<<17)
#define BIT_BOOLSASCHAR (1L<<18)
#define BIT_ROWVERSIONING (1L<<19)
#define BIT_SHOWSYSTEMTABLES (1L<<20)
#define BIT_SHOWOIDCOLUMN (1L<<21)
#define BIT_FAKEOIDINDEX (1L<<22)
#define BIT_TRUEISMINUS1 (1L<<23)
#define EFFECTIVE_BIT_COUNT 24
/* Connection Defaults */
......@@ -119,6 +148,19 @@
#define DEFAULT_EXTRASYSTABLEPREFIXES "dd_;"
#define DEFAULT_DISALLOWPREMATURE 0
#define DEFAULT_TRUEISMINUS1 0
#ifdef DRIVER_CURSOR_IMPLEMENT
#define DEFAULT_UPDATABLECURSORS 1
#else
#define DEFAULT_UPDATABLECURSORS 0
#endif /* DRIVER_CURSOR_IMPLEMENT */
#ifdef WIN32
#define DEFAULT_LFCONVERSION 1
#else
#define DEFAULT_LFCONVERSION 0
#endif /* WIN32 */
/* prototypes */
void getCommonDefaults(const char *section, const char *filename, ConnInfo *ci);
......
......@@ -242,7 +242,7 @@ dialog:
qlog("conn=%u, PGAPI_DriverConnect(out)='%s'\n", conn, szConnStrOut);
mylog("PGAPI_DRiverConnect: returning %d\n", result);
mylog("PGAPI_DriverConnect: returning %d\n", result);
return result;
}
......@@ -351,10 +351,7 @@ dconn_get_connect_attributes(const UCHAR FAR * connect_string, ConnInfo *ci)
*equals;
char *strtok_arg;
memset(ci, 0, sizeof(ConnInfo));
#ifdef DRIVER_CURSOR_IMPLEMENT
ci->updatable_cursors = 1;
#endif /* DRIVER_CURSOR_IMPLEMENT */
CC_conninfo_init(ci);
our_connect_string = strdup(connect_string);
strtok_arg = our_connect_string;
......
This diff is collapsed.
......@@ -17,7 +17,8 @@
struct EnvironmentClass_
{
char *errormsg;
int errornumber;
int errornumber;
Int4 flag;
};
/* Environment prototypes */
......@@ -28,4 +29,10 @@ char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn);
char EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn);
void EN_log_error(char *func, char *desc, EnvironmentClass *self);
#define EN_OV_ODBC2 1L
#define EN_is_odbc2(env) ((env->flag & EN_OV_ODBC2) != 0)
#define EN_is_odbc3(env) ((env->flag & EN_OV_ODBC2) == 0)
#define EN_set_odbc2(env) (env->flag |= EN_OV_ODBC2)
#define EN_set_odbc3(env) (env->flag &= EN_OV_ODBC2)
#endif
......@@ -267,6 +267,7 @@ PGAPI_Execute(
if (stmt->status == STMT_FINISHED)
{
mylog("%s: recycling statement (should have been done by app)...\n", func);
/******** Is this really NEEDED ? ******/
SC_recycle_statement(stmt);
}
......@@ -291,6 +292,7 @@ PGAPI_Execute(
{
if (stmt->options.param_processed_ptr)
*stmt->options.param_processed_ptr = 0;
SC_recycle_statement(stmt);
}
next_param_row:
......@@ -434,26 +436,24 @@ next_param_row:
}
/* we are now in a transaction */
CC_set_in_trans(conn);
stmt->result = res = CC_send_query(conn, stmt->stmt_with_params, NULL);
if (!res || QR_aborted(res))
res = CC_send_query(conn, stmt->stmt_with_params, NULL, TRUE);
if (!res)
{
CC_abort(conn);
stmt->errornumber = STMT_EXEC_ERROR;
stmt->errormsg = "Handle prepare error";
return SQL_ERROR;
}
else
SC_set_Result(stmt, res);
if (CC_is_in_autocommit(conn))
{
if (CC_is_in_autocommit(conn))
{
if (issued_begin)
CC_commit(conn);
else if (!in_trans && begin_included)
CC_set_no_trans(conn);
}
stmt->status = STMT_FINISHED;
return SQL_SUCCESS;
if (issued_begin)
CC_commit(conn);
else if (!in_trans && begin_included)
CC_set_no_trans(conn);
}
stmt->status = STMT_FINISHED;
return SQL_SUCCESS;
}
else
return SQL_SUCCESS;
......@@ -518,7 +518,7 @@ PGAPI_Transact(
{
mylog("PGAPI_Transact: sending on conn %d '%s'\n", conn, stmt_string);
res = CC_send_query(conn, stmt_string, NULL);
res = CC_send_query(conn, stmt_string, NULL, TRUE);
CC_set_no_trans(conn);
if (!res)
......@@ -721,7 +721,7 @@ PGAPI_ParamData(
/* commit transaction if needed */
if (!ci->drivers.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
{
if (!CC_commit(stmt->hdbc))
if (CC_commit(stmt->hdbc))
{
stmt->errormsg = "Could not commit (in-line) a transaction";
stmt->errornumber = STMT_EXEC_ERROR;
......@@ -902,6 +902,14 @@ PGAPI_PutData(
}
else
{
Int2 ctype = current_param->CType;
if (ctype == SQL_C_DEFAULT)
ctype = sqltype_to_default_ctype(current_param->SQLType);
#ifdef UNICODE_SUPPORT
if (SQL_NTS == cbValue && SQL_C_WCHAR == ctype)
cbValue = 2 * ucs2strlen((SQLWCHAR *) rgbValue);
#endif /* UNICODE_SUPPORT */
/* for handling fields */
if (cbValue == SQL_NTS)
{
......@@ -916,11 +924,11 @@ PGAPI_PutData(
}
else
{
Int2 ctype = current_param->CType;
if (ctype == SQL_C_DEFAULT)
ctype = sqltype_to_default_ctype(current_param->SQLType);
#ifdef UNICODE_SUPPORT
if (ctype == SQL_C_CHAR || ctype == SQL_C_BINARY || ctype == SQL_C_WCHAR)
#else
if (ctype == SQL_C_CHAR || ctype == SQL_C_BINARY)
#endif /* UNICODE_SUPPORT */
{
current_param->EXEC_buffer = malloc(cbValue + 1);
if (!current_param->EXEC_buffer)
......@@ -965,31 +973,31 @@ PGAPI_PutData(
}
else
{
buffer = current_param->EXEC_buffer;
Int2 ctype = current_param->CType;
if (cbValue == SQL_NTS)
if (ctype == SQL_C_DEFAULT)
ctype = sqltype_to_default_ctype(current_param->SQLType);
buffer = current_param->EXEC_buffer;
if (old_pos = *current_param->EXEC_used, SQL_NTS == old_pos)
{
buffer = realloc(buffer, strlen(buffer) + strlen(rgbValue) + 1);
if (!buffer)
{
stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in PGAPI_PutData (3)";
SC_log_error(func, "", stmt);
return SQL_ERROR;
}
strcat(buffer, rgbValue);
mylog(" cbValue = SQL_NTS: strlen(buffer) = %d\n", strlen(buffer));
*current_param->EXEC_used = cbValue;
/* reassign buffer incase realloc moved it */
current_param->EXEC_buffer = buffer;
#ifdef UNICODE_SUPPORT
if (SQL_C_WCHAR == ctype)
old_pos = 2 * ucs2strlen((SQLWCHAR *) buffer);
else
#endif /* UNICODE_SUPPORT */
old_pos = strlen(buffer);
}
else if (cbValue > 0)
if (SQL_NTS == cbValue)
{
#ifdef UNICODE_SUPPORT
if (SQL_C_WCHAR == ctype)
cbValue = 2 * ucs2strlen((SQLWCHAR *) rgbValue);
else
#endif /* UNICODE_SUPPORT */
cbValue = strlen(rgbValue);
}
if (cbValue > 0)
{
old_pos = *current_param->EXEC_used;
*current_param->EXEC_used += cbValue;
mylog(" cbValue = %d, old_pos = %d, *used = %d\n", cbValue, old_pos, *current_param->EXEC_used);
......
This diff is collapsed.
......@@ -19,6 +19,7 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
{
static char *func = "PGAPI_GetInfo30";
ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci = &(conn->connInfo);
char *p = NULL;
int len = 0,
value = 0;
......@@ -50,35 +51,60 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
| SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
| SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
| SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
| SQL_CA1_POS_REFRESH
/* | SQL_CA1_BULK_ADD
| SQL_CA1_POS_REFRESH;
if (ci->drivers.lie)
value |=
( SQL_CA1_BULK_ADD
| SQL_CA1_BULK_UPDATE_BY_BOOKMARK
| SQL_CA1_BULK_DELETE_BY_BOOKMARK
| SQL_CA1_BULK_FETCH_BY_BOOKMARK */
;
| SQL_CA1_BULK_FETCH_BY_BOOKMARK
| SQL_CA1_LOCK_EXCLUSIVE
| SQL_CA1_LOCK_UNLOCK
| SQL_CA1_POSITIONED_UPDATE
| SQL_CA1_POSITIONED_DELETE
| SQL_CA1_SELECT_FOR_UPDATE
);
break;
case SQL_KEYSET_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY |
SQL_CA2_SENSITIVITY_ADDITIONS |
SQL_CA2_SENSITIVITY_DELETIONS |
SQL_CA2_SENSITIVITY_UPDATES;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY
| SQL_CA2_SENSITIVITY_ADDITIONS
| SQL_CA2_SENSITIVITY_DELETIONS
| SQL_CA2_SENSITIVITY_UPDATES;
if (ci->drivers.lie)
value |=
( SQL_CA2_READ_ONLY_CONCURRENCY
| SQL_CA2_LOCK_CONCURRENCY
| SQL_CA2_OPT_VALUES_CONCURRENCY
| SQL_CA2_MAX_ROWS_SELECT
| SQL_CA2_MAX_ROWS_INSERT
| SQL_CA2_MAX_ROWS_DELETE
| SQL_CA2_MAX_ROWS_UPDATE
| SQL_CA2_MAX_ROWS_CATALOG
| SQL_CA2_MAX_ROWS_AFFECTS_ALL
| SQL_CA2_CRC_EXACT
| SQL_CA2_CRC_APPROXIMATE
| SQL_CA2_SIMULATE_NON_UNIQUE
| SQL_CA2_SIMULATE_TRY_UNIQUE
| SQL_CA2_SIMULATE_UNIQUE
);
break;
case SQL_STATIC_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE |
SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK |
SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION |
SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE |
SQL_CA1_POS_REFRESH;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
| SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
| SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
| SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
| SQL_CA1_POS_REFRESH;
break;
case SQL_STATIC_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY |
SQL_CA2_SENSITIVITY_ADDITIONS |
SQL_CA2_SENSITIVITY_DELETIONS |
SQL_CA2_SENSITIVITY_UPDATES;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY
| SQL_CA2_SENSITIVITY_ADDITIONS
| SQL_CA2_SENSITIVITY_DELETIONS
| SQL_CA2_SENSITIVITY_UPDATES;
break;
case SQL_ODBC_INTERFACE_CONFORMANCE:
......@@ -103,11 +129,11 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
break;
case SQL_BATCH_ROW_COUNT:
len = 4;
value = SQL_BRC_ROLLED_UP | SQL_BRC_EXPLICIT;
value = SQL_BRC_EXPLICIT;
break;
case SQL_BATCH_SUPPORT:
len = 4;
value = SQL_BS_ROW_COUNT_EXPLICIT;
value = SQL_BS_SELECT_EXPLICIT | SQL_BS_ROW_COUNT_EXPLICIT;
break;
case SQL_CATALOG_NAME:
len = 0;
......@@ -194,7 +220,7 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
len = 4;
value = SQL_DT_DROP_TABLE;
if (PG_VERSION_GT(conn, 7.2)) /* hopefully */
value |= SQL_DT_RESTRICT | SQL_DT_CASCADE;
value |= (SQL_DT_RESTRICT | SQL_DT_CASCADE);
break;
case SQL_DROP_TRANSLATION:
len = 4;
......@@ -204,7 +230,7 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
len = 4;
value = SQL_DV_DROP_VIEW;
if (PG_VERSION_GT(conn, 7.2)) /* hopefully */
value |= SQL_DV_RESTRICT | SQL_DV_CASCADE;
value |= (SQL_DV_RESTRICT | SQL_DV_CASCADE);
break;
case SQL_INDEX_KEYWORDS:
len = 4;
......@@ -227,11 +253,11 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
break;
case SQL_PARAM_ARRAY_ROW_COUNTS:
len = 4;
value = SQL_PARC_NO_BATCH;
value = SQL_PARC_BATCH;
break;
case SQL_PARAM_ARRAY_SELECTS:
len = 4;
value = SQL_PAS_NO_SELECT;
value = SQL_PAS_BATCH;
break;
case SQL_SQL_CONFORMANCE:
len = 4;
......@@ -316,6 +342,7 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
return SQL_ERROR;
}
result = SQL_SUCCESS;
mylog("%s: p='%s', len=%d, value=%d, cbMax=%d\n", func, p ? p : "<NULL>", len, value, cbInfoValueMax);
if (p)
{
/* char/binary data */
......@@ -323,6 +350,14 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
if (rgbInfoValue)
{
#ifdef UNICODE_SUPPORT
if (conn->unicode)
{
len = utf8_to_ucs2(p, len, (SQLWCHAR *) rgbInfoValue, cbInfoValueMax / 2);
len *= 2;
}
else
#endif /* UNICODE_SUPPORT */
strncpy_null((char *) rgbInfoValue, p, (size_t) cbInfoValueMax);
if (len >= cbInfoValueMax)
......
......@@ -15,7 +15,6 @@
#include "psqlodbc.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
......
......@@ -38,6 +38,7 @@
#define MYLOGDIR "c:"
#endif
extern void mylog(char *fmt,...);
#define inolog mylog /* for really temporary debug */
#else
#ifndef WIN32
......
......@@ -16,13 +16,6 @@
#include <stdio.h>
#include <stdlib.h>
int PG_CCST; /* Client Charcter Status */
int PG_SCSC; /* Server Charcter Set (code) */
int PG_CCSC; /* Client Charcter Set (code) */
unsigned char *PG_SCSS; /* Server Charcter Set (string) */
unsigned char *PG_CCSS; /* Client Charcter Set (string) */
pg_CS CS_Table[] =
{
{ "SQL_ASCII", SQL_ASCII },
......@@ -78,19 +71,29 @@ pg_ismb(int characterset_code)
int
pg_CS_code(const unsigned char *characterset_string)
{
int i = 0, c;
int i = 0, c = -1;
unsigned len = 0;
for(i = 0; CS_Table[i].code != OTHER; i++)
{
if (strstr(characterset_string,CS_Table[i].name))
c = CS_Table[i].code;
{
if(strlen(CS_Table[i].name) >= len)
{
len = strlen(CS_Table[i].name);
c = CS_Table[i].code;
}
}
}
if (c < 0)
c = i;
return (c);
}
unsigned char *
pg_CS_name(const int characterset_code)
pg_CS_name(int characterset_code)
{
int i = 0;
int i;
for (i = 0; CS_Table[i].code != OTHER; i++)
{
if (CS_Table[i].code == characterset_code)
......@@ -242,7 +245,7 @@ pg_CS_stat(int stat,unsigned int character,int characterset_code)
unsigned char *
pg_mbschr(const unsigned char *string, unsigned int character)
pg_mbschr(int csc, const unsigned char *string, unsigned int character)
{
int mb_st = 0;
unsigned char *s;
......@@ -250,7 +253,7 @@ pg_mbschr(const unsigned char *string, unsigned int character)
for(;;)
{
mb_st = pg_CS_stat(mb_st, (unsigned char) *s,PG_CCSC);
mb_st = pg_CS_stat(mb_st, (unsigned char) *s, csc);
if (mb_st == 0 && (*s == character || *s == 0))
break;
else
......@@ -260,13 +263,13 @@ pg_mbschr(const unsigned char *string, unsigned int character)
}
int
pg_mbslen(const unsigned char *string)
pg_mbslen(int csc, const unsigned char *string)
{
unsigned char *s;
int len, cs_stat;
for (len = 0, cs_stat = 0, s = (unsigned char *) string; *s != 0; s++)
{
cs_stat = pg_CS_stat(cs_stat,(unsigned int) *s, PG_CCSC);
cs_stat = pg_CS_stat(cs_stat,(unsigned int) *s, csc);
if (cs_stat < 2)
len++;
}
......@@ -274,12 +277,12 @@ pg_mbslen(const unsigned char *string)
}
unsigned char *
pg_mbsinc(const unsigned char *current )
pg_mbsinc(int csc, const unsigned char *current )
{
int mb_stat = 0;
if (*current != 0)
{
mb_stat = (int) pg_CS_stat(mb_stat, *current, PG_CCSC);
mb_stat = (int) pg_CS_stat(mb_stat, *current, csc);
if (mb_stat == 0)
mb_stat = 1;
return ((unsigned char *) current + mb_stat);
......@@ -288,43 +291,100 @@ pg_mbsinc(const unsigned char *current )
return NULL;
}
void
CC_lookup_characterset(ConnectionClass *self)
static char *
CC_lookup_cs_new(ConnectionClass *self)
{
char *encstr = NULL;
QResultClass *res;
res = CC_send_query(self, "select pg_client_encoding()", NULL, TRUE);
if (res)
{
char *enc = QR_get_value_backend_row(res, 0, 0);
if (enc)
encstr = strdup(enc);
QR_Destructor(res);
}
return encstr;
}
static char *
CC_lookup_cs_old(ConnectionClass *self)
{
char *encstr = NULL;
HSTMT hstmt;
StatementClass *stmt;
RETCODE result;
static char *func = "CC_lookup_characterset";
mylog("%s: entering...\n", func);
PG_SCSS = malloc(MAX_CHARACTERSET_NAME);
PG_CCSS = malloc(MAX_CHARACTERSET_NAME);
result = PGAPI_AllocStmt(self, &hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return;
stmt = (StatementClass *) hstmt;
return encstr;
result = PGAPI_ExecDirect(hstmt, "Show Client_Encoding", SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
if (result == SQL_SUCCESS_WITH_INFO)
{
PGAPI_FreeStmt(hstmt, SQL_DROP);
return;
char sqlState[8], errormsg[128], enc[32];
if (PGAPI_Error(NULL, NULL, hstmt, sqlState, NULL, errormsg,
sizeof(errormsg), NULL) == SQL_SUCCESS &&
sscanf(errormsg, "%*s %*s %*s %*s %*s %s", enc) > 0)
encstr = strdup(enc);
}
result = PGAPI_AllocStmt(self, &hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return;
stmt = (StatementClass *) hstmt;
PGAPI_FreeStmt(hstmt, SQL_DROP);
return encstr;
}
result = PGAPI_ExecDirect(hstmt, "Show Server_Encoding", SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
void
CC_lookup_characterset(ConnectionClass *self)
{
char *encstr;
static char *func = "CC_lookup_characterset";
mylog("%s: entering...\n", func);
if (PG_VERSION_LT(self, 7.2))
encstr = CC_lookup_cs_old(self);
else
encstr = CC_lookup_cs_new(self);
if (self->client_encoding)
free(self->client_encoding);
if (encstr)
{
self->client_encoding = encstr;
self->ccsc = pg_CS_code(encstr);
qlog(" [ Client encoding = '%s' (code = %d) ]\n", self->client_encoding, self->ccsc);
if (stricmp(pg_CS_name(self->ccsc), encstr))
{
qlog(" Client encoding = '%s' and %s\n", self->client_encoding, pg_CS_name(self->ccsc));
self->errornumber = CONN_VALUE_OUT_OF_RANGE;
self->errormsg = "client encoding mismatch";
}
}
else
{
PGAPI_FreeStmt(hstmt, SQL_DROP);
return;
self->ccsc = SQL_ASCII;
self->client_encoding = NULL;
}
}
strcpy(PG_SCSS , pg_CS_name(PG_SCSC = pg_CS_code(PG_SCSS)));
strcpy(PG_CCSS , pg_CS_name(PG_CCSC = pg_CS_code(PG_CCSS)));
void encoded_str_constr(encoded_str *encstr, int ccsc, const char *str)
{
encstr->ccsc = ccsc;
encstr->encstr = str;
encstr->pos = -1;
encstr->ccst = 0;
}
int encoded_nextchar(encoded_str *encstr)
{
int chr;
chr = encstr->encstr[++encstr->pos];
encstr->ccst = pg_CS_stat(encstr->ccst, (unsigned int) chr, encstr->ccsc);
return chr;
}
int encoded_byte_check(encoded_str *encstr, int abspos)
{
int chr;
qlog(" [ Server encoding = '%s' (code = %d), Client encoding = '%s' (code = %d) ]\n", PG_SCSS, PG_SCSC, PG_CCSS, PG_CCSC);
chr = encstr->encstr[encstr->pos = abspos];
encstr->ccst = pg_CS_stat(encstr->ccst, (unsigned int) chr, encstr->ccsc);
return chr;
}
......@@ -4,13 +4,14 @@
*
*/
#include "psqlodbc.h"
#include "qresult.h"
/* PostgreSQL client encoding */
#define SQL_ASCII 0 /* SQL/ASCII */
#define EUC_JP 1 /* EUC for Japanese */
#define EUC_CN 2 /* EUC for Chinese */
#define EUC_KR 3 /* EUC for Korean */
#define EUC_TW 4 /* EUC for Taiwan */
#define EUC_TW 4 /* EUC for Taiwan */
#define JOHAB 5
#define UTF8 6 /* Unicode UTF-8 */
#define MULE_INTERNAL 7 /* Mule internal code */
......@@ -22,66 +23,67 @@
#define LATIN6 13 /* ISO-8859 Latin 6 */
#define LATIN7 14 /* ISO-8859 Latin 7 */
#define LATIN8 15 /* ISO-8859 Latin 8 */
#define LATIN9 16 /* ISO-8859 Latin 9 */
#define LATIN10 17 /* ISO-8859 Latin 10 */
#define WIN1256 18 /* Arabic Windows */
#define TCVN 19 /* Vietnamese Windows */
#define WIN874 20 /* Thai Windows */
#define KOI8R 21 /* KOI8-R/U */
#define LATIN9 16 /* ISO-8859 Latin 9 */
#define LATIN10 17 /* ISO-8859 Latin 10 */
#define WIN1256 18 /* Arabic Windows */
#define TCVN 19 /* Vietnamese Windows */
#define WIN874 20 /* Thai Windows */
#define KOI8R 21 /* KOI8-R/U */
#define WIN1251 22 /* windows-1251 */
#define ALT 23 /* Alternativny Variant (MS-DOS CP866) */
#define ISO_8859_5 24 /* ISO-8859-5 */
#define ISO_8859_6 25 /* ISO-8859-6 */
#define ISO_8859_7 26 /* ISO-8859-7 */
#define ISO_8859_8 27 /* ISO-8859-8 */
#define ISO_8859_5 24 /* ISO-8859-5 */
#define ISO_8859_6 25 /* ISO-8859-6 */
#define ISO_8859_7 26 /* ISO-8859-7 */
#define ISO_8859_8 27 /* ISO-8859-8 */
#define SJIS 28 /* Shift JIS */
#define BIG5 29 /* Big5 */
#define GBK 30 /* GBK */
#define UHC 31 /* UHC */
#define WIN1250 32 /* windows-1250 */
#define OTHER -1
#define MAX_CHARACTERSET_NAME 24
#define MAX_CHARACTER_LEN 6
#define BIG5 29 /* Big5 */
#define GBK 30 /* GBK */
#define UHC 31 /* UHC */
#define WIN1250 32 /* windows-1250 */
#define OTHER -1
#define MAX_CHARACTERSET_NAME 24
#define MAX_CHARACTER_LEN 6
/* OLD Type */
/* OLD Type */
// extern int multibyte_client_encoding; /* Multibyte client encoding. */
// extern int multibyte_status; /* Multibyte charcter status. */
//
// void multibyte_init(void);
// unsigned char *check_client_encoding(unsigned char *sql_string);
// int multibyte_char_check(unsigned char s);
// unsigned char *multibyte_strchr(const unsigned char *string, unsigned int c);
/* New Type */
extern int PG_CCST; /* Client Character StaTus */
extern int PG_SCSC; /* Server Character Set (Code) */
extern int PG_CCSC; /* Client Character Set (Code) */
extern unsigned char *PG_SCSS; /* Server Character Set (String) */
extern unsigned char *PG_CCSS; /* Client Character Set (String) */
extern void CC_lookup_characterset(ConnectionClass *self);
extern int pg_CS_stat(int stat,unsigned int charcter,int characterset_code);
extern int pg_CS_code(const unsigned char *stat_string);
extern unsigned char *pg_CS_name(const int code);
typedef struct pg_CS
{
unsigned char *name;
int code;
}pg_CS;
extern pg_CS CS_Table[];
extern int pg_mbslen(const unsigned char *string);
extern unsigned char *pg_mbschr(const unsigned char *string, unsigned int character);
extern unsigned char *pg_mbsinc( const unsigned char *current );
/* Old Type Compatible */
#define multibyte_init() (PG_CCST = 0)
#define multibyte_char_check(X) pg_CS_stat(PG_CCST, (unsigned int) X, PG_CCSC)
#define multibyte_strchr(X,Y) pg_mbschr(X,Y)
#define check_client_encoding(X) pg_CS_name(PG_CCSC = pg_CS_code(X))
// unsigned char *multibyte_strchr(const unsigned char *string, unsigned int c);
/* New Type */
extern void CC_lookup_characterset(ConnectionClass *self);
extern int pg_CS_stat(int stat,unsigned int charcter,int characterset_code);
extern int pg_CS_code(const unsigned char *stat_string);
extern unsigned char *pg_CS_name(int code);
typedef struct pg_CS
{
unsigned char *name;
int code;
}pg_CS;
extern int pg_mbslen(int ccsc, const unsigned char *string);
extern unsigned char *pg_mbschr(int ccsc, const unsigned char *string, unsigned int character);
extern unsigned char *pg_mbsinc(int ccsc, const unsigned char *current );
/* Old Type Compatible */
typedef struct
{
int ccsc;
const char *encstr;
int pos;
int ccst;
} encoded_str;
#define ENCODE_STATUS(enc) ((enc).ccst)
void encoded_str_constr(encoded_str *encstr, int ccsc, const char *str);
#define make_encoded_str(encstr, conn, str) encoded_str_constr(encstr, conn->ccsc, str)
extern int encoded_nextchar(encoded_str *encstr);
extern int encoded_byte_check(encoded_str *encstr, int abspos);
#define check_client_encoding(X) pg_CS_name(pg_CS_code(X))
......@@ -174,7 +174,8 @@ SQLError(HENV EnvironmentHandle,
{
mylog("[SQLError]");
return PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
Sqlstate, NativeError, MessageText, BufferLength, TextLength);
Sqlstate, NativeError, MessageText, BufferLength,
TextLength);
}
RETCODE SQL_API
......@@ -281,23 +282,31 @@ SQLGetInfo(HDBC ConnectionHandle,
SQLUSMALLINT InfoType, PTR InfoValue,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
{
#if (ODBCVER >= 0x0300)
RETCODE ret;
ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
CC_clear_error(conn);
#if (ODBCVER >= 0x0300)
mylog("[SQLGetInfo(30)]");
if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength)) == SQL_ERROR)
{
if (((ConnectionClass *) ConnectionHandle)->driver_version >= 0x0300)
return PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
{
CC_clear_error(conn);
ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
}
}
return ret;
if (SQL_ERROR == ret)
CC_log_error("SQLGetInfo30", "", conn);
#else
mylog("[SQLGetInfo]");
return PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
if (ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength), SQL_ERROR == ret)
CC_log_error("PGAPI_GetInfo", "", conn);
#endif
return ret;
}
RETCODE SQL_API
......@@ -638,7 +647,7 @@ SQLTablePrivileges(
{
mylog("[SQLTablePrivileges]");
return PGAPI_TablePrivileges(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szTableName, cbTableName);
szSchemaName, cbSchemaName, szTableName, cbTableName, 0);
}
RETCODE SQL_API
......
......@@ -25,22 +25,27 @@ RETCODE SQL_API SQLErrorW(HENV EnvironmentHandle,
SQLSMALLINT *TextLength)
{
RETCODE ret;
SWORD tlen;
SWORD tlen, buflen;
char *qst = NULL, *mtxt = NULL;
mylog("[SQLErrorW]");
if (Sqlstate)
qst = malloc(8);
if (MessageText)
mtxt = malloc(BufferLength);
buflen = 0;
if (MessageText && BufferLength > 0)
{
buflen = BufferLength * 3 + 1;
mtxt = malloc(buflen);
}
ret = PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
qst, NativeError, mtxt, BufferLength, &tlen);
qst, NativeError, mtxt, buflen, &tlen);
if (qst)
utf8_to_ucs2(qst, strlen(qst), Sqlstate, 5);
if (TextLength)
*TextLength = utf8_to_ucs2(mtxt, tlen, MessageText, BufferLength);
free(qst);
free(mtxt);
if (mtxt)
free(mtxt);
return ret;
}
......@@ -56,6 +61,7 @@ RETCODE SQL_API SQLSetConnectOptionW(HDBC ConnectionHandle,
SQLUSMALLINT Option, SQLUINTEGER Value)
{
mylog("[SQLSetConnectionOptionW]");
if (!ConnectionHandle) return SQL_ERROR;
((ConnectionClass *) ConnectionHandle)->unicode = 1;
return PGAPI_SetConnectOption(ConnectionHandle, Option, Value);
}
......
This diff is collapsed.
......@@ -85,22 +85,37 @@ RETCODE SQL_API SQLGetDiagRecW(SWORD fHandleType,
SQLSMALLINT *pcbErrorMsg)
{
RETCODE ret;
SWORD tlen;
char *qst = NULL, *mtxt = NULL;
SWORD buflen, tlen;
char *qstr = NULL, *mtxt = NULL;
mylog("[SQLGetDiagRecW]");
if (szSqlState)
qst = malloc(8);
if (szErrorMsg)
mtxt = malloc(cbErrorMsgMax);
ret = PGAPI_GetDiagRec(fHandleType, handle, iRecord, qst,
pfNativeError, mtxt, cbErrorMsgMax, &tlen);
if (qst)
utf8_to_ucs2(qst, strlen(qst), szSqlState, 5);
if (pcbErrorMsg)
*pcbErrorMsg = utf8_to_ucs2(mtxt, tlen, szErrorMsg, cbErrorMsgMax);
free(qst);
free(mtxt);
qstr = malloc(8);
buflen = 0;
if (szErrorMsg && cbErrorMsgMax > 0)
{
buflen = cbErrorMsgMax;
mtxt = malloc(buflen);
}
ret = PGAPI_GetDiagRec(fHandleType, handle, iRecord, qstr,
pfNativeError, mtxt, buflen, &tlen);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
{
if (qstr)
utf8_to_ucs2(qstr, strlen(qstr), szSqlState, 6);
if (mtxt && tlen <= cbErrorMsgMax)
{
tlen = utf8_to_ucs2(mtxt, tlen, szErrorMsg, cbErrorMsgMax);
if (tlen >= cbErrorMsgMax)
ret = SQL_SUCCESS_WITH_INFO;
}
if (pcbErrorMsg)
*pcbErrorMsg = tlen;
}
if (qstr);
free(qstr);
if (mtxt)
free(mtxt);
return ret;
}
......
......@@ -13,7 +13,7 @@
SQLPrepareW, SQLPrimaryKeysW, SQLProcedureColumnsW,
SQLProceduresW, SQLSetCursorNameW,
SQLSpecialColumnsW, SQLStatisticsW, SQLTablesW,
SQLTablePrivilegesW
SQLTablePrivilegesW, SQLGetTypeInfoW
*-------
*/
......@@ -102,7 +102,11 @@ RETCODE SQL_API SQLDriverConnectW(HDBC hdbc,
ret = PGAPI_DriverConnect(hdbc, hwnd, szIn, (SWORD) inlen,
szOut, cbConnStrOutMax, &olen, fDriverCompletion);
if (ret != SQL_ERROR)
*pcbConnStrOut = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
{
UInt4 outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
if (pcbConnStrOut)
*pcbConnStrOut = outlen;
}
free(szOut);
if (szIn);
free(szIn);
......@@ -129,7 +133,11 @@ RETCODE SQL_API SQLBrowseConnectW(
ret = PGAPI_BrowseConnect(hdbc, szIn, (SWORD) inlen,
szOut, cbConnStrOutMax, &olen);
if (ret != SQL_ERROR)
*pcbConnStrOut = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
{
UInt4 outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
if (pcbConnStrOut)
*pcbConnStrOut = outlen;
}
free(szOut);
if (szIn);
free(szIn);
......@@ -158,15 +166,28 @@ RETCODE SQL_API SQLDescribeColW(HSTMT StatementHandle,
SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
{
RETCODE ret;
SWORD nmlen;
SWORD buflen, nmlen;
char *clName;
mylog("[SQLDescribeColW]");
clName = malloc(BufferLength);
buflen = BufferLength * 3 + 1;
clName = malloc(buflen);
ret = PGAPI_DescribeCol(StatementHandle, ColumnNumber,
clName, BufferLength, &nmlen,
DataType, ColumnSize, DecimalDigits, Nullable);
*NameLength = utf8_to_ucs2(clName, nmlen, ColumnName, BufferLength);
clName, buflen, &nmlen, DataType, ColumnSize,
DecimalDigits, Nullable);
if (ret == SQL_SUCCESS)
{
UInt4 nmcount = utf8_to_ucs2(clName, nmlen, ColumnName, BufferLength);
if (nmcount > (UInt4) BufferLength)
{
StatementClass *stmt = (StatementClass *) StatementHandle;
ret = SQL_SUCCESS_WITH_INFO;
stmt->errornumber = STMT_TRUNCATED;
stmt->errormsg = "Column name too large";
}
if (NameLength)
*NameLength = nmcount;
}
free(clName);
return ret;
}
......@@ -192,13 +213,25 @@ RETCODE SQL_API SQLGetCursorNameW(HSTMT StatementHandle,
{
RETCODE ret;
char *crName;
SWORD clen;
SWORD clen, buflen;
mylog("[SQLGetCursorNameW]");
crName = malloc(BufferLength);
ret = PGAPI_GetCursorName(StatementHandle, crName, BufferLength,
&clen);
*NameLength = utf8_to_ucs2(crName, (Int4) clen, CursorName, BufferLength);
buflen = BufferLength * 3 + 1;
crName = malloc(buflen);
ret = PGAPI_GetCursorName(StatementHandle, crName, buflen, &clen);
if (ret == SQL_SUCCESS)
{
UInt4 nmcount = utf8_to_ucs2(crName, (Int4) clen, CursorName, BufferLength);
if (nmcount > (UInt4) BufferLength)
{
StatementClass *stmt = (StatementClass *) StatementHandle;
ret = SQL_SUCCESS_WITH_INFO;
stmt->errornumber = STMT_TRUNCATED;
stmt->errormsg = "Cursor name too large";
}
if (NameLength)
*NameLength = utf8_to_ucs2(crName, (Int4) clen, CursorName, BufferLength);
}
free(crName);
return ret;
}
......@@ -207,23 +240,33 @@ RETCODE SQL_API SQLGetInfoW(HDBC ConnectionHandle,
SQLUSMALLINT InfoType, PTR InfoValue,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
{
ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
RETCODE ret;
((ConnectionClass *) ConnectionHandle)->unicode = 1;
conn->unicode = 1;
CC_clear_error(conn);
#if (ODBCVER >= 0x0300)
mylog("[SQLGetInfoW(30)]");
if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength)) == SQL_ERROR)
{
if (((ConnectionClass *) ConnectionHandle)->driver_version >= 0x0300)
return PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
if (conn->driver_version >= 0x0300)
{
CC_clear_error(conn);
ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
}
}
return ret;
if (SQL_ERROR == ret)
CC_log_error("SQLGetInfoW(30)", "", conn);
#else
mylog("[SQLGetInfoW]");
return PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
if (SQL_ERROR == ret)
CC_log_error("SQLGetInfoW", "", conn);
#endif
return ret;
}
RETCODE SQL_API SQLPrepareW(HSTMT StatementHandle,
......@@ -428,17 +471,31 @@ RETCODE SQL_API SQLNativeSqlW(
RETCODE ret;
char *szIn, *szOut;
UInt4 slen;
SQLINTEGER olen;
SQLINTEGER buflen, olen;
mylog("[SQLNativeSqlW]");
((ConnectionClass *) hdbc)->unicode = 1;
szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen);
szOut = malloc(cbSqlStrMax);
buflen = 3 * cbSqlStrMax + 1;
szOut = malloc(buflen);
ret = PGAPI_NativeSql(hdbc, szIn, (SQLINTEGER) slen,
szOut, cbSqlStrMax, &olen);
szOut, buflen, &olen);
if (szIn);
free(szIn);
*pcbSqlStr = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
if (ret == SQL_SUCCESS)
{
UInt4 szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
if (szcount > (UInt4) cbSqlStrMax)
{
ConnectionClass *conn = (ConnectionClass *) hdbc;
ret = SQL_SUCCESS_WITH_INFO;
conn->errornumber = CONN_TRUNCATED;
conn->errormsg = "Sql string too large";
}
if (pcbSqlStr)
*pcbSqlStr = szcount;
}
free(szOut);
return ret;
}
......@@ -560,3 +617,10 @@ RETCODE SQL_API SQLTablePrivilegesW(
free(tbName);
return ret;
}
RETCODE SQL_API SQLGetTypeInfoW(
SQLHSTMT StatementHandle,
SQLSMALLINT DataType)
{
return PGAPI_GetTypeInfo(StatementHandle, DataType);
}
......@@ -342,12 +342,13 @@ PGAPI_SetConnectOption(
break;
case SQL_AUTOCOMMIT:
if (vParam == SQL_AUTOCOMMIT_ON && CC_is_in_autocommit(conn))
if (vParam == SQL_AUTOCOMMIT_ON && CC_is_in_trans(conn))
break;
else if (vParam == SQL_AUTOCOMMIT_OFF && !CC_is_in_autocommit(conn))
else if (vParam == SQL_AUTOCOMMIT_OFF && !CC_is_in_trans(conn))
break;
if (CC_is_in_trans(conn))
CC_commit(conn);
mylog("PGAPI_SetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
switch (vParam)
......@@ -401,8 +402,21 @@ PGAPI_SetConnectOption(
sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
if (fOption == 30002 && vParam)
{
if (strcmp((char *) vParam, "Microsoft Jet") == 0)
int cmp;
#ifdef UNICODE_SUPPORT
char *asPara;
if (conn->unicode)
{
asPara = ucs2_to_utf8((SQLWCHAR *) vParam, -1, NULL);
cmp = strcmp(asPara, "Microsoft Jet");
free(asPara);
}
else
#endif /* UNICODE_SUPPORT */
cmp = strncmp((char *) vParam, "Microsoft Jet", 13);
if (0 == cmp)
{
mylog("Microsoft Jet !!!!\n");
conn->errornumber = 0;
conn->ms_jet = 1;
return SQL_SUCCESS;
......@@ -456,7 +470,7 @@ PGAPI_GetConnectOption(
case SQL_CURRENT_QUALIFIER: /* don't use qualifiers */
if (pvParam)
strcpy(pvParam, "");
((char *) pvParam)[0] = ((char *) pvParam)[1] = '\0';
break;
......@@ -557,7 +571,7 @@ PGAPI_GetStmtOption(
case SQL_GET_BOOKMARK:
case SQL_ROW_NUMBER:
res = stmt->result;
res = SC_get_Curres(stmt);
if (stmt->manual_result || !ci->drivers.use_declarefetch)
{
......
......@@ -42,18 +42,29 @@
#define TAB_INCR 8
#define COL_INCR 16
#ifdef MULTIBYTE
char *getNextToken(int ccsc, char *s, char *token, int smax, char *delim, char *quote, char *dquote, char *numeric);
#else
char *getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dquote, char *numeric);
#endif /* MULTIBYTE */
void getColInfo(COL_INFO *col_info, FIELD_INFO *fi, int k);
char searchColInfo(COL_INFO *col_info, FIELD_INFO *fi);
char *
getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dquote, char *numeric)
getNextToken(
#ifdef MULTIBYTE
int ccsc, /* client encoding */
#endif /* MULTIBYTE */
char *s, char *token, int smax, char *delim, char *quote, char *dquote, char *numeric)
{
int i = 0;
int out = 0;
char qc,
in_escape = FALSE;
#ifdef MULTIBYTE
encoded_str encstr;
#endif
if (smax <= 1)
return NULL;
......@@ -80,17 +91,22 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
if (numeric)
*numeric = FALSE;
#ifdef MULTIBYTE
encoded_str_constr(&encstr, ccsc, &s[i]);
#endif
/* get the next token */
while (!isspace((unsigned char) s[i]) && s[i] != ',' &&
s[i] != '\0' && out != smax)
while (s[i] != '\0' && out < smax)
{
#ifdef MULTIBYTE
if (multibyte_char_check(s[i]) != 0)
encoded_nextchar(&encstr);
if (ENCODE_STATUS(encstr) != 0)
{
token[out++] = s[i++];
continue;
}
#endif
if (isspace((unsigned char) s[i]) || s[i] == ',')
break;
/* Handle quoted stuff */
if (out == 0 && (s[i] == '\"' || s[i] == '\''))
{
......@@ -110,7 +126,8 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
while (s[i] != '\0' && out != smax)
{
#ifdef MULTIBYTE
if (multibyte_char_check(s[i]) != 0)
encoded_nextchar(&encstr);
if (ENCODE_STATUS(encstr) != 0)
{
token[out++] = s[i++];
continue;
......@@ -197,22 +214,22 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
#if 0
QR_set_num_fields(stmt->result, 14);
QR_set_field_info(stmt->result, 0, "TABLE_QUALIFIER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 1, "TABLE_OWNER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 2, "TABLE_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 3, "COLUMN_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 4, "DATA_TYPE", PG_TYPE_INT2, 2);
QR_set_field_info(stmt->result, 5, "TYPE_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 6, "PRECISION", PG_TYPE_INT4, 4);
QR_set_field_info(stmt->result, 7, "LENGTH", PG_TYPE_INT4, 4);
QR_set_field_info(stmt->result, 8, "SCALE", PG_TYPE_INT2, 2);
QR_set_field_info(stmt->result, 9, "RADIX", PG_TYPE_INT2, 2);
QR_set_field_info(stmt->result, 10, "NULLABLE", PG_TYPE_INT2, 2);
QR_set_field_info(stmt->result, 11, "REMARKS", PG_TYPE_TEXT, 254);
QR_set_num_fields(SC_get_Curres(stmt), 14);
QR_set_field_info(SC_get_Curres(stmt), 0, "TABLE_QUALIFIER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(SC_get_Curres(stmt), 1, "TABLE_OWNER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(SC_get_Curres(stmt), 2, "TABLE_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(SC_get_Curres(stmt), 3, "COLUMN_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(SC_get_Curres(stmt), 4, "DATA_TYPE", PG_TYPE_INT2, 2);
QR_set_field_info(SC_get_Curres(stmt), 5, "TYPE_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(SC_get_Curres(stmt), 6, "PRECISION", PG_TYPE_INT4, 4);
QR_set_field_info(SC_get_Curres(stmt), 7, "LENGTH", PG_TYPE_INT4, 4);
QR_set_field_info(SC_get_Curres(stmt), 8, "SCALE", PG_TYPE_INT2, 2);
QR_set_field_info(SC_get_Curres(stmt), 9, "RADIX", PG_TYPE_INT2, 2);
QR_set_field_info(SC_get_Curres(stmt), 10, "NULLABLE", PG_TYPE_INT2, 2);
QR_set_field_info(SC_get_Curres(stmt), 11, "REMARKS", PG_TYPE_TEXT, 254);
/* User defined fields */
QR_set_field_info(stmt->result, 12, "DISPLAY_SIZE", PG_TYPE_INT4, 4);
QR_set_field_info(stmt->result, 13, "FIELD_TYPE", PG_TYPE_INT4, 4);
QR_set_field_info(SC_get_Curres(stmt), 12, "DISPLAY_SIZE", PG_TYPE_INT4, 4);
QR_set_field_info(SC_get_Curres(stmt), 13, "FIELD_TYPE", PG_TYPE_INT4, 4);
#endif
void
......@@ -312,9 +329,10 @@ parse_statement(StatementClass *stmt)
stmt->ntab = 0;
#ifdef MULTIBYTE
multibyte_init();
#endif
while (pptr = ptr, (ptr = getNextToken(conn->ccsc, pptr, token, sizeof(token), &delim, &quote, &dquote, &numeric)) != NULL)
#else
while (pptr = ptr, (ptr = getNextToken(pptr, token, sizeof(token), &delim, &quote, &dquote, &numeric)) != NULL)
#endif
{
unquoted = !(quote || dquote);
......@@ -607,12 +625,17 @@ parse_statement(StatementClass *stmt)
if (!dquote)
{
char *ptr;
#ifdef MULTIBYTE
encoded_str encstr;
make_encoded_str(&encstr, conn, ti[stmt->ntab]->name);
#endif /* MULTIBYTE */
/* lower case table name */
for (ptr = ti[stmt->ntab]->name; *ptr; ptr++)
{
#ifdef MULTIBYTE
if ((unsigned char) *ptr >= 0x80)
encoded_nextchar(&encstr);
if (ENCODE_STATUS(encstr) != 0)
ptr++;
else
#endif /* MULTIBYTE */
......@@ -773,13 +796,13 @@ parse_statement(StatementClass *stmt)
* structure
*/
strcpy(conn->col_info[conn->ntables]->name, ti[i]->name);
conn->col_info[conn->ntables]->result = col_stmt->result;
conn->col_info[conn->ntables]->result = SC_get_Curres(col_stmt);
/*
* The connection will now free the result structures, so
* make sure that the statement doesn't free it
*/
col_stmt->result = NULL;
SC_set_Result(col_stmt, NULL);
conn->ntables++;
......
......@@ -36,37 +36,92 @@ PGAPI_GetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,
RETCODE ret;
static const char *func = "PGAPI_GetDiagRec";
mylog("%s entering ", func);
mylog("%s entering rec=%d", func, RecNumber);
switch (HandleType)
{
case SQL_HANDLE_ENV:
ret = PGAPI_Error(Handle, NULL, NULL, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
ret = PGAPI_EnvError(Handle, RecNumber, Sqlstate,
NativeError, MessageText,
BufferLength, TextLength, 0);
break;
case SQL_HANDLE_DBC:
ret = PGAPI_Error(NULL, Handle, NULL, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
ret = PGAPI_ConnectError(Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength, 0);
break;
case SQL_HANDLE_STMT:
ret = PGAPI_Error(NULL, NULL, Handle, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
ret = PGAPI_StmtError(Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength, 0);
break;
default:
ret = SQL_ERROR;
}
if (ret == SQL_SUCCESS_WITH_INFO &&
BufferLength == 0 &&
*TextLength)
{
SQLSMALLINT BufferLength = *TextLength + 4;
SQLCHAR *MessageText = malloc(BufferLength);
mylog("%s exiting %d\n", func, ret);
return ret;
}
RETCODE SQL_API
PGAPI_GetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
PTR DiagInfoPtr, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
RETCODE ret = SQL_SUCCESS;
static const char *func = "PGAPI_GetDiagField";
ret = PGAPI_GetDiagRec(HandleType, Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength);
free(MessageText);
mylog("%s entering rec=%d", func, RecNumber);
switch (HandleType)
{
case SQL_HANDLE_ENV:
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
case SQL_DIAG_MESSAGE_TEXT:
case SQL_DIAG_NATIVE:
case SQL_DIAG_NUMBER:
case SQL_DIAG_RETURNCODE:
case SQL_DIAG_SERVER_NAME:
case SQL_DIAG_SQLSTATE:
break;
}
break;
case SQL_HANDLE_DBC:
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
case SQL_DIAG_MESSAGE_TEXT:
case SQL_DIAG_NATIVE:
case SQL_DIAG_NUMBER:
case SQL_DIAG_RETURNCODE:
case SQL_DIAG_SERVER_NAME:
case SQL_DIAG_SQLSTATE:
break;
}
break;
case SQL_HANDLE_STMT:
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
case SQL_DIAG_MESSAGE_TEXT:
case SQL_DIAG_NATIVE:
case SQL_DIAG_NUMBER:
case SQL_DIAG_RETURNCODE:
case SQL_DIAG_SERVER_NAME:
case SQL_DIAG_SQLSTATE:
break;
}
break;
default:
ret = SQL_ERROR;
}
mylog("%s exiting\n", func);
mylog("%s exiting %d\n", func, ret);
return ret;
}
......@@ -87,7 +142,7 @@ PGAPI_GetConnectAttr(HDBC ConnectionHandle,
case SQL_ATTR_CONNECTION_TIMEOUT:
case SQL_ATTR_METADATA_ID:
conn->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
conn->errormsg = "Unsupported connection option (Set)";
conn->errormsg = "Unsupported connect attribute (Get)";
return SQL_ERROR;
}
return PGAPI_GetConnectOption(ConnectionHandle, (UWORD) Attribute, Value);
......@@ -373,7 +428,7 @@ PGAPI_SetConnectAttr(HDBC ConnectionHandle,
case SQL_ATTR_CONNECTION_TIMEOUT:
case SQL_ATTR_METADATA_ID:
conn->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
conn->errormsg = "Unsupported connection option (Set)";
conn->errormsg = "Unsupported connect attribute (Set)";
return SQL_ERROR;
}
return PGAPI_SetConnectOption(ConnectionHandle, (UWORD) Attribute, (UDWORD) Value);
......
......@@ -11,6 +11,8 @@
#include <string.h>
#define PODBC_NOT_SEARCH_PATTERN 1L
#define PODBC_ALLOW_PARTIAL_EXTRACT 1L
#define PODBC_ERROR_CLEAR (1L << 1)
RETCODE SQL_API PGAPI_AllocConnect(HENV EnvironmentHandle,
HDBC FAR * ConnectionHandle);
......@@ -56,6 +58,20 @@ RETCODE SQL_API PGAPI_Error(HENV EnvironmentHandle,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength);
/* Helper functions for Error handling */
RETCODE SQL_API PGAPI_EnvError(HENV EnvironmentHandle, SWORD RecNumber,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength, UWORD flag);
RETCODE SQL_API PGAPI_ConnectError(HDBC ConnectionHandle, SWORD RecNumber,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength, UWORD flag);
RETCODE SQL_API PGAPI_StmtError(HSTMT StatementHandle, SWORD RecNumber,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength, UWORD flag);
RETCODE SQL_API PGAPI_ExecDirect(HSTMT StatementHandle,
SQLCHAR *StatementText, SQLINTEGER TextLength);
RETCODE SQL_API PGAPI_Execute(HSTMT StatementHandle);
......@@ -225,7 +241,8 @@ RETCODE SQL_API PGAPI_TablePrivileges(
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName);
SQLSMALLINT cbTableName,
UWORD flag);
RETCODE SQL_API PGAPI_BindParameter(
HSTMT hstmt,
SQLUSMALLINT ipar,
......@@ -243,4 +260,25 @@ RETCODE SQL_API PGAPI_SetScrollOptions(
SDWORD crowKeyset,
UWORD crowRowset);
#if (ODBCVER >= 0x0300)
RETCODE SQL_API PGAPI_GetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLCHAR *Sqlstate,
SQLINTEGER *NativeError, SQLCHAR *MessageText,
SQLSMALLINT BufferLength, SQLSMALLINT *TextLength);
RETCODE SQL_API PGAPI_GetConnectAttr(HDBC ConnectionHandle,
SQLINTEGER Attribute, PTR Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength);
RETCODE SQL_API PGAPI_GetStmtAttr(HSTMT StatementHandle,
SQLINTEGER Attribute, PTR Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength);
RETCODE SQL_API PGAPI_SetConnectAttr(HDBC ConnectionHandle,
SQLINTEGER Attribute, PTR Value,
SQLINTEGER StringLength);
RETCODE SQL_API PGAPI_SetStmtAttr(HSTMT StatementHandle,
SQLINTEGER Attribute, PTR Value,
SQLINTEGER StringLength);
RETCODE SQL_API PGAPI_SetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
PTR Value, SQLINTEGER BufferLength);
#endif /* ODBCVER */
#endif /* define_PG_API_FUNC_H__ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -45,6 +45,7 @@ struct QResultClass_
TupleListClass *manual_tuples; /* manual result tuple list */
ConnectionClass *conn; /* the connection this result is using
* (backend) */
QResultClass *next; /* the following result class */
/* Stuff for declare/fetch tuples */
int count_allocated; /* m(re)alloced count */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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