Commit 9abd0554 authored by Hiroshi Inoue's avatar Hiroshi Inoue

1) Fix SQLForeignKeys() in multibyte mode.

2) Fix a bug with NUMERIC scale in case of Parse
  statement option.
3) Remove a no longer needed loop in CC_send_query().

Hiroshi Inoue
parent 531126c8
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
*/ */
/* Multibyte support Eiji Tokuya 2001-03-15 */ /* Multibyte support Eiji Tokuya 2001-03-15 */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "connection.h" #include "connection.h"
#include "environ.h" #include "environ.h"
...@@ -27,9 +31,6 @@ ...@@ -27,9 +31,6 @@
#include "multibyte.h" #include "multibyte.h"
#endif #endif
#include <stdio.h>
#include <string.h>
#ifdef WIN32 #ifdef WIN32
#include <odbcinst.h> #include <odbcinst.h>
#endif #endif
...@@ -277,6 +278,10 @@ memcpy(&(rv->connInfo.drivers), &globals, sizeof(globals)); ...@@ -277,6 +278,10 @@ memcpy(&(rv->connInfo.drivers), &globals, sizeof(globals));
rv->pg_version_number = .0; rv->pg_version_number = .0;
rv->pg_version_major = 0; rv->pg_version_major = 0;
rv->pg_version_minor = 0; rv->pg_version_minor = 0;
#ifdef MULTIBYTE
rv->client_encoding = NULL;
rv->server_encoding = NULL;
#endif /* MULTIBYTE */
/* Initialize statement options to defaults */ /* Initialize statement options to defaults */
...@@ -302,6 +307,12 @@ CC_Destructor(ConnectionClass *self) ...@@ -302,6 +307,12 @@ CC_Destructor(ConnectionClass *self)
mylog("after CC_Cleanup\n"); mylog("after CC_Cleanup\n");
#ifdef MULTIBYTE
if (self->client_encoding)
free(self->client_encoding);
if (self->server_encoding)
free(self->server_encoding);
#endif /* MULTIBYTE */
/* Free up statement holders */ /* Free up statement holders */
if (self->stmts) if (self->stmts)
{ {
...@@ -510,6 +521,9 @@ CC_connect(ConnectionClass *self, char do_password) ...@@ -510,6 +521,9 @@ CC_connect(ConnectionClass *self, char do_password)
char msgbuffer[ERROR_MSG_LENGTH]; char msgbuffer[ERROR_MSG_LENGTH];
char salt[5]; char salt[5];
static char *func = "CC_connect"; static char *func = "CC_connect";
#ifdef MULTIBYTE
char *encoding;
#endif /* MULTIBYTE */
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -537,7 +551,9 @@ CC_connect(ConnectionClass *self, char do_password) ...@@ -537,7 +551,9 @@ CC_connect(ConnectionClass *self, char do_password)
ci->drivers.bools_as_char); ci->drivers.bools_as_char);
#ifdef MULTIBYTE #ifdef MULTIBYTE
check_client_encoding(ci->drivers.conn_settings); encoding = check_client_encoding(ci->drivers.conn_settings);
if (encoding && strcmp(encoding, "OTHER"))
self->client_encoding = strdup(encoding);
qlog(" extra_systable_prefixes='%s', conn_settings='%s' conn_encoding='%s'\n", qlog(" extra_systable_prefixes='%s', conn_settings='%s' conn_encoding='%s'\n",
ci->drivers.extra_systable_prefixes, ci->drivers.extra_systable_prefixes,
ci->drivers.conn_settings, ci->drivers.conn_settings,
...@@ -1041,7 +1057,6 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi) ...@@ -1041,7 +1057,6 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
CC_set_no_trans(self); CC_set_no_trans(self);
ReadyToReturn = TRUE; ReadyToReturn = TRUE;
retres = NULL; retres = NULL;
break;
} }
else else
{ {
...@@ -1059,6 +1074,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi) ...@@ -1059,6 +1074,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
QR_set_status(res, PGRES_COMMAND_OK); QR_set_status(res, PGRES_COMMAND_OK);
QR_set_command(res, cmdbuffer); QR_set_command(res, cmdbuffer);
query_completed = TRUE; query_completed = TRUE;
mylog("send_query: returning res = %u\n", res);
if (!before_64) if (!before_64)
break; break;
/* /*
...@@ -1069,71 +1085,14 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi) ...@@ -1069,71 +1085,14 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
* an 'I' is received * an 'I' is received
*/ */
if (empty_reqs == 0) if (empty_reqs == 0)
{ {
SOCK_put_string(sock, "Q "); SOCK_put_string(sock, "Q ");
SOCK_flush_output(sock); SOCK_flush_output(sock);
empty_reqs++; empty_reqs++;
} }
break;
while (!clear)
{
id = SOCK_get_char(sock);
mylog("got clear id = '%c'\n", id);
switch (id)
{
case 'I':
(void) SOCK_get_char(sock);
clear = TRUE;
break;
case 'Z':
break;
case 'C':
SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
qlog("Command response: '%s'\n", cmdbuffer);
break;
case 'N':
msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
if (QR_command_successful(res))
QR_set_status(res, PGRES_NONFATAL_ERROR);
QR_set_notice(res, cmdbuffer); /* will dup this string */
qlog("NOTICE from backend during clear: '%s'\n", cmdbuffer);
while (msg_truncated)
msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
break;
case 'E':
msg_truncated = SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
mylog("ERROR from backend during clear: '%s'\n", msgbuffer);
qlog("ERROR from backend during clear: '%s'\n", msgbuffer);
/*
* We must report this type of error as
* well (practically for reference
* integrity violation error reporting,
* from PostgreSQL 7.0). (Zoltan Kovacs,
* 04/26/2000)
*/
self->errormsg = msgbuffer;
if (!strncmp(self->errormsg, "FATAL", 5))
{
self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
CC_set_no_trans(self);
}
else
self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
QR_set_status(res, PGRES_FATAL_ERROR);
QR_set_aborted(res, TRUE);
while (msg_truncated)
msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
break;
}
}
mylog("send_query: returning res = %u\n", res);
break;
} }
break;
case 'Z': /* Backend is ready for new query (6.4) */ case 'Z': /* Backend is ready for new query (6.4) */
if (empty_reqs == 0) if (empty_reqs == 0)
{ {
......
...@@ -274,6 +274,10 @@ struct ConnectionClass_ ...@@ -274,6 +274,10 @@ struct ConnectionClass_
float pg_version_number; float pg_version_number;
Int2 pg_version_major; Int2 pg_version_major;
Int2 pg_version_minor; Int2 pg_version_minor;
#ifdef MULTIBYTE
char *client_encoding;
char *server_encoding;
#endif /* MULTIBYTE */
}; };
......
This diff is collapsed.
...@@ -227,12 +227,17 @@ QR_set_field_info(stmt->result, 13, "FIELD_TYPE", PG_TYPE_INT4, 4); ...@@ -227,12 +227,17 @@ QR_set_field_info(stmt->result, 13, "FIELD_TYPE", PG_TYPE_INT4, 4);
void void
getColInfo(COL_INFO *col_info, FIELD_INFO *fi, int k) getColInfo(COL_INFO *col_info, FIELD_INFO *fi, int k)
{ {
char *str;
if (fi->name[0] == '\0') if (fi->name[0] == '\0')
strcpy(fi->name, QR_get_value_manual(col_info->result, k, 3)); strcpy(fi->name, QR_get_value_manual(col_info->result, k, 3));
fi->type = atoi(QR_get_value_manual(col_info->result, k, 13)); fi->type = atoi(QR_get_value_manual(col_info->result, k, 13));
fi->precision = atoi(QR_get_value_manual(col_info->result, k, 6)); fi->precision = atoi(QR_get_value_manual(col_info->result, k, 6));
fi->length = atoi(QR_get_value_manual(col_info->result, k, 7)); fi->length = atoi(QR_get_value_manual(col_info->result, k, 7));
if (str = QR_get_value_manual(col_info->result, k, 8), str)
fi->scale = atoi(str);
else
fi->scale = -1;
fi->nullable = atoi(QR_get_value_manual(col_info->result, k, 10)); fi->nullable = atoi(QR_get_value_manual(col_info->result, k, 10));
fi->display_size = atoi(QR_get_value_manual(col_info->result, k, 12)); fi->display_size = atoi(QR_get_value_manual(col_info->result, k, 12));
} }
......
...@@ -199,7 +199,7 @@ PGAPI_DescribeCol( ...@@ -199,7 +199,7 @@ PGAPI_DescribeCol(
QResultClass *res; QResultClass *res;
char *col_name = NULL; char *col_name = NULL;
Int4 fieldtype = 0; Int4 fieldtype = 0;
int precision = 0; int precision = 0, scale = 0;
ConnInfo *ci; ConnInfo *ci;
char parse_ok; char parse_ok;
char buf[255]; char buf[255];
...@@ -250,6 +250,7 @@ PGAPI_DescribeCol( ...@@ -250,6 +250,7 @@ PGAPI_DescribeCol(
fieldtype = stmt->fi[icol]->type; fieldtype = stmt->fi[icol]->type;
col_name = stmt->fi[icol]->name; col_name = stmt->fi[icol]->name;
precision = stmt->fi[icol]->precision; precision = stmt->fi[icol]->precision;
scale = stmt->fi[icol]->scale;
mylog("PARSE: fieldtype=%d, col_name='%s', precision=%d\n", fieldtype, col_name, precision); mylog("PARSE: fieldtype=%d, col_name='%s', precision=%d\n", fieldtype, col_name, precision);
if (fieldtype > 0) if (fieldtype > 0)
...@@ -292,6 +293,7 @@ PGAPI_DescribeCol( ...@@ -292,6 +293,7 @@ PGAPI_DescribeCol(
/* atoi(ci->unknown_sizes) */ /* atoi(ci->unknown_sizes) */
precision = pgtype_precision(stmt, fieldtype, icol, ci->drivers.unknown_sizes); precision = pgtype_precision(stmt, fieldtype, icol, ci->drivers.unknown_sizes);
scale = pgtype_scale(stmt, fieldtype, icol);
} }
mylog("describeCol: col %d fieldname = '%s'\n", icol, col_name); mylog("describeCol: col %d fieldname = '%s'\n", icol, col_name);
...@@ -348,10 +350,7 @@ PGAPI_DescribeCol( ...@@ -348,10 +350,7 @@ PGAPI_DescribeCol(
*/ */
if (pibScale) if (pibScale)
{ {
Int2 scale; if (scale < 0)
scale = pgtype_scale(stmt, fieldtype, icol);
if (scale == -1)
scale = 0; scale = 0;
*pibScale = scale; *pibScale = scale;
......
...@@ -131,6 +131,7 @@ typedef struct ...@@ -131,6 +131,7 @@ typedef struct
{ {
TABLE_INFO *ti; /* resolve to explicit table names */ TABLE_INFO *ti; /* resolve to explicit table names */
int precision; int precision;
int scale;
int display_size; int display_size;
int length; int length;
int type; int type;
......
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