PostgreSQL added support for protocol version 3 in server version 7.4.
There's no need to support servers older than that. This simplifies the
code a lot, removing a lot of corner cases that haven't been properly
regression tested for a long time anyway.
Original patch by me, with some tweaks by Michael Paquier.
/* COLUMN_NAME_STORAGE_LEN may be sufficient but for safety */
char new_field_name[2 * COLUMN_NAME_STORAGE_LEN + 1];
SocketClass *sock;
- ConnInfo *ci;
sock = CC_get_socket(conn);
- ci = &conn->connInfo;
/* at first read in the number of fields that are in the query */
new_num_fields = (Int2) SOCK_get_int(sock, sizeof(Int2));
if (self)
{
/* according to that allocate memory */
- CI_set_num_fields(self, new_num_fields, PROTOCOL_74(ci));
+ CI_set_num_fields(self, new_num_fields);
if (NULL == self->coli_array)
return FALSE;
}
for (lf = 0; lf < new_num_fields; lf++)
{
SOCK_get_string(sock, new_field_name, 2 * COLUMN_NAME_STORAGE_LEN);
- if (PROTOCOL_74(ci)) /* tableid & columnid */
- {
- new_relid = SOCK_get_int(sock, sizeof(Int4));
- new_attid = SOCK_get_int(sock, sizeof(Int2));
- }
+ new_relid = SOCK_get_int(sock, sizeof(Int4));
+ new_attid = SOCK_get_int(sock, sizeof(Int2));
new_adtid = (OID) SOCK_get_int(sock, 4);
new_adtsize = (Int2) SOCK_get_int(sock, 2);
- /* If 6.4 protocol, then read the atttypmod field */
- if (PG_VERSION_GE(conn, 6.4))
- {
- mylog("READING ATTTYPMOD\n");
- new_atttypmod = (Int4) SOCK_get_int(sock, 4);
-
- /* Subtract the header length */
- 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)
- new_atttypmod = -1;
- if (PROTOCOL_74(ci)) /* format */
- SOCK_get_int(sock, sizeof(Int2));
+ mylog("READING ATTTYPMOD\n");
+ new_atttypmod = (Int4) SOCK_get_int(sock, 4);
+ /* Subtract the header length */
+ 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)
+ new_atttypmod = -1;
+ /* format */
+ SOCK_get_int(sock, sizeof(Int2));
mylog("%s: fieldname='%s', adtid=%d, adtsize=%d, atttypmod=%d (rel,att)=(%d,%d)\n", func, new_field_name, new_adtid, new_adtsize, new_atttypmod, new_relid, new_attid);
void
-CI_set_num_fields(ColumnInfoClass *self, int new_num_fields, BOOL allocrelatt)
+CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
{
CI_free_memory(self); /* always safe to call */
/* functions for setting up the fields from within the program, */
/* without reading from a socket */
-void CI_set_num_fields(ColumnInfoClass *self, int new_num_fields, BOOL);
+void CI_set_num_fields(ColumnInfoClass *self, int new_num_fields);
void CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
OID new_adtid, Int2 new_adtsize, Int4 atttypmod,
OID new_relid, OID new_attid);
#define PRN_NULLCHECK
-static void CC_lookup_pg_version(ConnectionClass *self);
static void CC_lookup_lo(ConnectionClass *self);
static char *CC_create_errormsg(ConnectionClass *self);
static int CC_close_eof_cursors(ConnectionClass *self);
CORR_STRCPY(database);
CORR_STRCPY(username);
NAME_TO_NAME(ci->password, sci->password);
- CORR_STRCPY(protocol);
CORR_STRCPY(port);
CORR_STRCPY(sslmode);
CORR_STRCPY(onlyread);
return 1;
}
free(pwd1);
- if (PROTOCOL_74(&(self->connInfo)))
- {
-inolog("putting p and %s\n", pwd2);
- SOCK_put_char(sock, 'p');
- }
+ inolog("putting p and %s\n", pwd2);
+ SOCK_put_char(sock, 'p');
+
md5len = strlen(pwd2);
SOCK_put_int(sock, (Int4) (4 + md5len + 1), 4);
SOCK_put_n_char(sock, pwd2, (md5len + 1));
EatReadyForQuery(ConnectionClass *conn)
{
int id = 0;
+ BOOL is_in_error_trans = CC_is_in_error_trans(conn);
- if (PROTOCOL_74(&(conn->connInfo)))
+ switch (id = SOCK_get_char(conn->sock))
{
- BOOL is_in_error_trans = CC_is_in_error_trans(conn);
- switch (id = SOCK_get_char(conn->sock))
- {
- case 'I':
- if (CC_is_in_trans(conn))
- {
- if (is_in_error_trans)
- CC_on_abort(conn, NO_TRANS);
- else
- CC_on_commit(conn);
- }
- break;
- case 'T':
- CC_set_in_trans(conn);
- CC_set_no_error_trans(conn);
+ case 'I':
+ if (CC_is_in_trans(conn))
+ {
if (is_in_error_trans)
- CC_on_abort_partial(conn);
- break;
- case 'E':
- CC_set_in_error_trans(conn);
- break;
- }
- conn->stmt_in_extquery = NULL;
+ CC_on_abort(conn, NO_TRANS);
+ else
+ CC_on_commit(conn);
+ }
+ break;
+ case 'T':
+ CC_set_in_trans(conn);
+ CC_set_no_error_trans(conn);
+ if (is_in_error_trans)
+ CC_on_abort_partial(conn);
+ break;
+ case 'E':
+ CC_set_in_error_trans(conn);
+ break;
}
+ conn->stmt_in_extquery = NULL;
+
return id;
}
int
-handle_error_message(ConnectionClass *self, char *msgbuf, size_t buflen, char *sqlstate, const char *comment, QResultClass *res)
+handle_error_message(ConnectionClass *self,
+ char *msgbuf,
+ size_t buflen,
+ char *sqlstate,
+ const char *comment,
+ QResultClass *res)
{
- BOOL new_format = FALSE, msg_truncated = FALSE, truncated, hasmsg = FALSE;
+ BOOL msg_truncated = FALSE;
+ BOOL hasmsg = FALSE;
+ BOOL truncated;
SocketClass *sock = self->sock;
- ConnInfo *ci = &(self->connInfo);
char msgbuffer[ERROR_MSG_LENGTH];
UDWORD abort_opt;
- inolog("handle_error_message protocol=%s\n", ci->protocol);
- if (PROTOCOL_74(ci))
- new_format = TRUE;
- else if (PROTOCOL_74REJECTED(ci))
- {
- if (!SOCK_get_next_byte(sock, TRUE)) /* peek the next byte */
- {
- uint32 leng;
+ inolog("handle_error_message");
+ truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
- mylog("peek the next byte = \\0\n");
- new_format = TRUE;
- strncpy_null(ci->protocol, PG74, sizeof(ci->protocol));
- leng = SOCK_get_response_length(sock);
- inolog("get the response length=%d\n", leng);
- }
- }
-
-inolog("new_format=%d\n", new_format);
- truncated = SOCK_get_string(sock,
- new_format ? msgbuffer : msgbuf,
- new_format ? sizeof(msgbuffer) : (Int4) buflen);
- if (new_format)
+ msgbuf[0] = '\0';
+ for (;msgbuffer[0];)
{
- msgbuf[0] = '\0';
- for (;msgbuffer[0];)
+ mylog("%s: 'E' - %s\n", comment, msgbuffer);
+ qlog("ERROR from backend during %s: '%s'\n", comment, msgbuffer);
+ switch (msgbuffer[0])
{
- mylog("%s: 'E' - %s\n", comment, msgbuffer);
- qlog("ERROR from backend during %s: '%s'\n", comment, msgbuffer);
- switch (msgbuffer[0])
- {
- case 'S':
- strlcat(msgbuf, msgbuffer + 1, buflen);
- strlcat(msgbuf, ": ", buflen);
- break;
- case 'M':
- case 'D':
- if (hasmsg)
- strlcat(msgbuf, "\n", buflen);
- strlcat(msgbuf, msgbuffer + 1, buflen);
- if (truncated)
- msg_truncated = truncated;
- hasmsg = TRUE;
- break;
- case 'C':
- if (sqlstate)
- strncpy_null(sqlstate, msgbuffer + 1, 8);
- break;
+ case 'S':
+ strlcat(msgbuf, msgbuffer + 1, buflen);
+ strlcat(msgbuf, ": ", buflen);
+ break;
+ case 'M':
+ case 'D':
+ if (hasmsg)
+ strlcat(msgbuf, "\n", buflen);
+ strlcat(msgbuf, msgbuffer + 1, buflen);
+ if (truncated)
+ msg_truncated = truncated;
+ hasmsg = TRUE;
+ break;
+ case 'C':
+ if (sqlstate)
+ strncpy_null(sqlstate, msgbuffer + 1, 8);
+ break;
}
- while (truncated)
- truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
- truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
- }
- }
- else
- {
- msg_truncated = truncated;
- /* Remove a newline */
- if (msgbuf[0] != '\0' && msgbuf[(int)strlen(msgbuf) - 1] == '\n')
- msgbuf[(int)strlen(msgbuf) - 1] = '\0';
-
- mylog("%s: 'E' - %s\n", comment, msgbuf);
- qlog("ERROR from backend during %s: '%s'\n", comment, msgbuf);
while (truncated)
truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
+ truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
}
+
abort_opt = 0;
if (!strncmp(msgbuf, "FATAL", 5))
{
int
handle_notice_message(ConnectionClass *self, char *msgbuf, size_t buflen, char *sqlstate, const char *comment, QResultClass *res)
{
- BOOL new_format = FALSE, msg_truncated = FALSE, truncated, hasmsg = FALSE;
+ BOOL msg_truncated = FALSE;
+ BOOL hasmsg = FALSE;
+ BOOL truncated;
SocketClass *sock = self->sock;
char msgbuffer[ERROR_MSG_LENGTH];
+ size_t dstlen = 0;
- if (PROTOCOL_74(&(self->connInfo)))
- new_format = TRUE;
-
- if (new_format)
+ msgbuf[0] = '\0';
+ for (;;)
{
- size_t dstlen = 0;
+ truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
+ if (!msgbuffer[0])
+ break;
- msgbuf[0] = '\0';
- for (;;)
+ mylog("%s: 'N' - %s\n", comment, msgbuffer);
+ qlog("NOTICE from backend during %s: '%s'\n", comment, msgbuffer);
+ switch (msgbuffer[0])
{
- truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
- if (!msgbuffer[0])
+ case 'S':
+ strlcat(msgbuf, msgbuffer + 1, buflen);
+ dstlen = strlcat(msgbuf, ": ", buflen);
+ break;
+ case 'M':
+ case 'D':
+ if (hasmsg)
+ strlcat(msgbuf, "\n", buflen);
+ dstlen = strlcat(msgbuf, msgbuffer + 1, buflen);
+ if (truncated)
+ msg_truncated = truncated;
+ hasmsg = TRUE;
+ break;
+ case 'C':
+ if (sqlstate && !sqlstate[0] && strcmp(msgbuffer + 1, "00000"))
+ strncpy_null(sqlstate, msgbuffer + 1, 8);
break;
-
- mylog("%s: 'N' - %s\n", comment, msgbuffer);
- qlog("NOTICE from backend during %s: '%s'\n", comment, msgbuffer);
- switch (msgbuffer[0])
- {
- case 'S':
- strlcat(msgbuf, msgbuffer + 1, buflen);
- dstlen = strlcat(msgbuf, ": ", buflen);
- break;
- case 'M':
- case 'D':
- if (hasmsg)
- strlcat(msgbuf, "\n", buflen);
- dstlen = strlcat(msgbuf, msgbuffer + 1, buflen);
- if (truncated)
- msg_truncated = truncated;
- hasmsg = TRUE;
- break;
- case 'C':
- if (sqlstate && !sqlstate[0] && strcmp(msgbuffer + 1, "00000"))
- strncpy_null(sqlstate, msgbuffer + 1, 8);
- break;
- }
- if (dstlen >= buflen)
- msg_truncated = TRUE;
- while (truncated)
- truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
}
-mylog("notice message len=%d\n", strlen(msgbuf));
- }
- else
- {
- msg_truncated = SOCK_get_string(sock, msgbuf, (Int4) buflen);
-
- /* Remove a newline */
- if (msgbuf[0] != '\0' && msgbuf[strlen(msgbuf) - 1] == '\n')
- msgbuf[strlen(msgbuf) - 1] = '\0';
-
- mylog("%s: 'N' - %s\n", comment, msgbuf);
- qlog("NOTICE from backend during %s: '%s'\n", comment, msgbuf);
- for (truncated = msg_truncated; truncated;)
+ if (dstlen >= buflen)
+ msg_truncated = TRUE;
+ while (truncated)
truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
}
+ mylog("notice message len=%d\n", strlen(msgbuf));
+
if (res)
{
if (QR_command_successful(res))
conn->pg_version_minor = minor;
}
conn->pg_version_number = (float) atof(szVersion);
- if (PG_VERSION_GE(conn, 7.3))
- conn->schema_support = 1;
mylog("Got the PostgreSQL version string: '%s'\n", conn->pg_version);
mylog("Extracted PostgreSQL version number: '%1.1f'\n", conn->pg_version_number);
ci->drivers.unknown_sizes,
ci->drivers.max_varchar_size,
ci->drivers.max_longvarchar_size);
- qlog(" disable_optimizer=%d, ksqo=%d, unique_index=%d, use_declarefetch=%d\n",
+ qlog(" disable_optimizer=%d, unique_index=%d, use_declarefetch=%d\n",
ci->drivers.disable_optimizer,
- ci->drivers.ksqo,
ci->drivers.unique_index,
ci->drivers.use_declarefetch);
qlog(" text_as_longvarchar=%d, unknowns_as_longvarchar=%d, bools_as_char=%d NAMEDATALEN=%d\n",
static char
original_CC_connect(ConnectionClass *self, char password_req, char *salt_para)
{
- StartupPacket sp;
- StartupPacket6_2 sp62;
- QResultClass *res;
SocketClass *sock = NULL;
ConnInfo *ci = &(self->connInfo);
int areq = -1;
if (anotherVersionRetry)
{
#ifdef USE_SSPI
- if (PROTOCOL_74(ci) || PROTOCOL_64(ci))
- {
- if (ssl_try_no < ssl_try_count)
- ssl_try_no++;
- }
- else
- ssl_try_no = ssl_try_count;
+ if (ssl_try_no < ssl_try_count)
+ ssl_try_no++;
+
if (ssl_try_no >= ssl_try_count)
{
#endif /* USE_SSPI */
- /* retry older version */
- if (PROTOCOL_62(ci))
- {
- CC_set_error(self, CONNECTION_SERVER_NOT_REACHED, "Could not construct a socket to the server", func);
- goto error_proc;
- }
- if (PROTOCOL_63(ci))
- strncpy_null(ci->protocol, PG62, sizeof(ci->protocol));
- else if (PROTOCOL_64(ci))
- strncpy_null(ci->protocol, PG63, sizeof(ci->protocol));
- else
- strncpy_null(ci->protocol, PG64, sizeof(ci->protocol));
+ CC_set_error(self, CONNECTION_SERVER_NOT_REACHED, "Could not construct a socket to the server", func);
+ goto error_proc;
#ifdef USE_SSPI
ssl_try_no = 0;
}
}
mylog("connection to the server socket succeeded.\n");
-inolog("protocol=%s version=%d,%d\n", ci->protocol, self->pg_version_major, self->pg_version_minor);
+ inolog("version=%d,%d\n", self->pg_version_major, self->pg_version_minor);
#ifdef USE_SSPI
if ('y' == ssl_call[ssl_try_no])
{
}
}
#endif /* USE_SSPI */
- if (PROTOCOL_62(ci))
- {
- sock->reverse = TRUE; /* make put_int and get_int work
- * for 6.2 */
-
- memset(&sp62, 0, sizeof(StartupPacket6_2));
- sock->pversion = PG_PROTOCOL_62;
- SOCK_put_int(sock, htonl(4 + sizeof(StartupPacket6_2)), 4);
- sp62.authtype = htonl(NO_AUTHENTICATION);
- strncpy_null(sp62.database, ci->database, PATH_SIZE);
- strncpy_null(sp62.user, ci->username, USRNAMEDATALEN);
- SOCK_put_n_char(sock, (char *) &sp62, sizeof(StartupPacket6_2));
- SOCK_flush_output(sock);
- }
- else if (PROTOCOL_74(ci))
- {
- if (!protocol3_packet_build(self))
- goto error_proc;
- }
- else
- {
- memset(&sp, 0, sizeof(StartupPacket));
-
- mylog("sizeof startup packet = %d\n", sizeof(StartupPacket));
-
- if (PROTOCOL_63(ci))
- sock->pversion = PG_PROTOCOL_63;
- else
- sock->pversion = PG_PROTOCOL_64;
- /* Send length of Authentication Block */
- SOCK_put_int(sock, 4 + sizeof(StartupPacket), 4);
-
- sp.protoVersion = (ProtocolVersion) htonl(sock->pversion);
-
- strncpy_null(sp.database, ci->database, SM_DATABASE);
- strncpy_null(sp.user, ci->username, SM_USER);
-
- SOCK_put_n_char(sock, (char *) &sp, sizeof(StartupPacket));
- SOCK_flush_output(sock);
- }
+ if (!protocol3_packet_build(self))
+ goto error_proc;
if (SOCK_get_errcode(sock) != 0)
{
/*
* Now get the authentication request from backend
*/
-
- if (!PROTOCOL_62(ci))
{
- BOOL beforeV2 = !(PROTOCOL_64(&self->connInfo) || PROTOCOL_74(&self->connInfo)),
- ReadyForQuery = FALSE, retry = FALSE;
+ BOOL ReadyForQuery = FALSE, retry = FALSE;
uint32 leng = 0;
#if defined(USE_GSS) || defined(USE_SSPI) || defined(USE_KRB5)
int authRet;
mylog("auth got '%c'\n", beresp);
if (0 != SOCK_get_errcode(sock))
goto sockerr_proc;
- if (PROTOCOL_74(ci))
+ if (beresp != 'E' || startPacketReceived)
{
- if (beresp != 'E' || startPacketReceived)
- {
- leng = SOCK_get_response_length(sock);
- inolog("leng=%d\n", leng);
- if (0 != SOCK_get_errcode(sock))
- goto sockerr_proc;
- }
- else
- strncpy_null(ci->protocol, PG74REJECTED, sizeof(ci->protocol));
+ leng = SOCK_get_response_length(sock);
+ inolog("leng=%d\n", leng);
+ if (0 != SOCK_get_errcode(sock))
+ goto sockerr_proc;
}
startPacketReceived = TRUE;
}
handle_error_message(self, msgbuffer, sizeof(msgbuffer), self->sqlstate, func, NULL);
CC_set_error(self, CONN_INVALID_AUTHENTICATION, msgbuffer, func);
qlog("ERROR from backend during authentication: '%s'\n", msgbuffer);
- if (PROTOCOL_74REJECTED(ci))
- retry = TRUE;
- else if (0 == strncmp(msgbuffer, "FATAL:", 6))
+ if (0 == strncmp(msgbuffer, "FATAL:", 6))
{
const char *emsg = msgbuffer + 8;
if (0 == strnicmp(emsg, "unsupported frontend protocol", 29))
mylog("past need password\n");
- if (PROTOCOL_74(&(self->connInfo)))
- SOCK_put_char(sock, 'p');
+ SOCK_put_char(sock, 'p');
SOCK_put_int(sock, (Int4) (4 + strlen(SAFE_NAME(ci->password)) + 1), 4);
SOCK_put_n_char(sock, SAFE_NAME(ci->password), strlen(SAFE_NAME(ci->password)) + 1);
sockerr = SOCK_flush_output(sock);
anotherVersionRetry = TRUE;
goto another_version_retry;
}
-
- /*
- * There were no ReadyForQuery responce before 6.4.
- */
- if (beforeV2 && areq == AUTH_REQ_OK)
- ReadyForQuery = TRUE;
} while (!ReadyForQuery);
}
CC_clear_error(self); /* clear any password error */
- /*
- * send an empty query in order to find out whether the specified
- * database really exists on the server machine
- */
- if (!PROTOCOL_74(ci))
- {
- mylog("sending an empty query...\n");
-
- res = CC_send_query(self, " ", NULL, 0, NULL);
- if (res == NULL ||
- (QR_get_rstatus(res) != PORES_EMPTY_QUERY &&
- QR_command_nonfatal(res)))
- {
- CC_set_error(self, CONNECTION_NO_SUCH_DATABASE, "The database does not exist on the server\nor user authentication failed.", func);
- QR_Destructor(res);
- return 0;
- }
- QR_Destructor(res);
-
- mylog("empty query seems to be OK.\n");
-
- /*
- * Get the version number first so we can check it before
- * sending options that are now obsolete. DJP 21/06/2002
- */
-inolog("CC_lookup_pg_version\n");
- CC_lookup_pg_version(self); /* Get PostgreSQL version for
- SQLGetInfo use */
- CC_setenv(self);
- }
-
return 1;
}
/*
CC_lookup_lo(self); /* a hack to get the oid of
our large object oid type */
- /*
- * Multibyte handling is available ?
- */
- if (PG_VERSION_GE(self, 6.4))
+ /* Multibyte handling */
+ CC_lookup_characterset(self);
+ if (CC_get_errornumber(self) > 0)
{
- CC_lookup_characterset(self);
- if (CC_get_errornumber(self) > 0)
- {
- ret = 0;
- goto cleanup;
- }
+ ret = 0;
+ goto cleanup;
+ }
#ifdef UNICODE_SUPPORT
- if (CC_is_in_unicode_driver(self))
+ if (CC_is_in_unicode_driver(self))
+ {
+ if (!self->original_client_encoding ||
+ UTF8 != self->ccsc)
{
- if (!self->original_client_encoding ||
- UTF8 != self->ccsc)
+ QResultClass *res;
+ if (self->original_client_encoding)
+ free(self->original_client_encoding);
+ self->original_client_encoding = NULL;
+ if (res = CC_send_query(self, "set client_encoding to 'UTF8'", NULL, 0, NULL), QR_command_maybe_successful(res))
{
- QResultClass *res;
- if (PG_VERSION_LT(self, 7.1))
- {
- CC_set_error(self, CONN_NOT_IMPLEMENTED_ERROR, "UTF-8 conversion isn't implemented before 7.1", func);
- ret = 0;
- goto cleanup;
- }
- if (self->original_client_encoding)
- free(self->original_client_encoding);
- self->original_client_encoding = NULL;
- if (res = CC_send_query(self, "set client_encoding to 'UTF8'", NULL, 0, NULL), QR_command_maybe_successful(res))
- {
- self->original_client_encoding = strdup("UNICODE");
- self->ccsc = pg_CS_code(self->original_client_encoding);
- }
- QR_Destructor(res);
+ self->original_client_encoding = strdup("UNICODE");
+ self->ccsc = pg_CS_code(self->original_client_encoding);
}
+ QR_Destructor(res);
}
-#else
- {
- }
-#endif /* UNICODE_SUPPORT */
}
-#ifdef UNICODE_SUPPORT
- else if (CC_is_in_unicode_driver(self))
+#else
{
- CC_set_error(self, CONN_NOT_IMPLEMENTED_ERROR, "Unicode isn't supported before 6.4", func);
- ret = 0;
- goto cleanup;
}
#endif /* UNICODE_SUPPORT */
+
ci->updatable_cursors = DISALLOW_UPDATABLE_CURSORS;
- if (ci->allow_keyset &&
- PG_VERSION_GE(self, 7.0)) /* Tid scan since 7.0 */
+ if (ci->allow_keyset)
{
if (ci->drivers.lie || !ci->drivers.use_declarefetch)
ci->updatable_cursors |= (ALLOW_STATIC_CURSORS | ALLOW_KEYSET_DRIVEN_CURSORS | ALLOW_BULK_OPERATIONS | SENSE_SELF_OPERATIONS);
else
- {
- if (PG_VERSION_GE(self, 7.4)) /* HOLDABLE CURSORS since 7.4 */
- ci->updatable_cursors |= (ALLOW_STATIC_CURSORS | SENSE_SELF_OPERATIONS);
- }
+ ci->updatable_cursors |= (ALLOW_STATIC_CURSORS | SENSE_SELF_OPERATIONS);
}
if (CC_get_errornumber(self) > 0)
lenrlscmd = 0, lenperqsvp = 0;
size_t qrylen;
int id;
- int maxlen,
- empty_reqs;
+ SocketClass *sock = self->sock;
+ int empty_reqs;
BOOL ReadyToReturn = FALSE,
query_completed = FALSE,
- beforeV2 = !(PROTOCOL_64(&self->connInfo) || PROTOCOL_74(&self->connInfo)),
aborted = FALSE,
used_passed_result_object = FALSE,
discard_next_begin = FALSE,
consider_rollback;
Int4 response_length;
UInt4 leng;
- ConnInfo *ci = &(self->connInfo);
int func_cs_count = 0;
/* ERROR_MSG_LENGTH is suffcient */
}
}
/* Indicate that we are sending a query to the backend */
- maxlen = CC_get_max_query_len(self);
qrylen = strlen(query);
- if (maxlen > 0 && maxlen < (int) qrylen + 1)
- {
- CC_set_error(self, CONNECTION_MSG_TOO_LONG, "Query string is too long", func);
- CLEANUP_FUNC_CONN_CS(func_cs_count, self);
- return NULL;
- }
if ((NULL == query) || (query[0] == '\0'))
{
lenrlscmd = strlen(rlscmd);
lenperqsvp = strlen(per_query_svp);
}
- if (PROTOCOL_74(ci))
+
+ leng = (UInt4) qrylen;
+ if (appendq)
+ leng += (UInt4) (strlen(appendq) + 1);
+ if (issue_begin)
+ leng += (UInt4) (lenbgncmd + 1);
+ if (query_rollback)
{
- leng = (UInt4) qrylen;
- if (appendq)
- leng += (UInt4) (strlen(appendq) + 1);
- if (issue_begin)
- leng += (UInt4) (lenbgncmd + 1);
- if (query_rollback)
- {
- leng += (UInt4) (lensvpcmd + 1 + lenperqsvp + 1);
- leng += (UInt4) (1 + lenrlscmd + 1 + lenperqsvp);
- }
- leng++;
- SOCK_put_int(self->sock, leng + 4, 4);
-inolog("leng=%d\n", leng);
+ leng += (UInt4) (lensvpcmd + 1 + lenperqsvp + 1);
+ leng += (UInt4) (1 + lenrlscmd + 1 + lenperqsvp);
}
+ leng++;
+ SOCK_put_int(sock, leng + 4, 4);
+inolog("leng=%d\n", leng);
+
if (issue_begin)
{
SOCK_put_n_char(self->sock, bgncmd, lenbgncmd);
else if (strnicmp(cmdbuffer, rbkcmd, lenrbkcmd) == 0)
{
CC_mark_cursors_doubtful(self);
- if (PROTOCOL_74(&(self->connInfo)))
- CC_set_in_error_trans(self); /* mark the transaction error in case of manual rollback */
- else
- CC_on_abort(self, NO_TRANS);
+ CC_set_in_error_trans(self); /* mark the transaction error in case of manual rollback */
}
/*
* DROP TABLE or ALTER TABLE may change
res->recent_processed_row_count = atoi(ptr + 1);
else
res->recent_processed_row_count = -1;
- if (PROTOCOL_74(&(self->connInfo)))
+ if (NULL != self->current_schema &&
+ strnicmp(cmdbuffer, "SET", 3) == 0)
{
- if (NULL != self->current_schema &&
- strnicmp(cmdbuffer, "SET", 3) == 0)
- {
- if (is_setting_search_path(query))
- reset_current_schema(self);
- }
- }
- else
- {
- if (strnicmp(cmdbuffer, cmtcmd, 6) == 0)
- CC_on_commit(self);
- else if (strnicmp(cmdbuffer, "END", 3) == 0)
- CC_on_commit(self);
- else if (strnicmp(cmdbuffer, "ABORT", 5) == 0)
- CC_on_abort(self, NO_TRANS);
+ if (is_setting_search_path(query))
+ reset_current_schema(self);
}
}
QR_set_command(res, cmdbuffer);
query_completed = TRUE;
mylog("send_query: returning res = %p\n", res);
- if (!beforeV2)
- break;
-
- /*
- * (Quotation from the original comments) since
- * backend may produce more than one result for some
- * commands we need to poll until clear so we send an
- * empty query, and keep reading out of the pipe until
- * an 'I' is received
- */
- if (empty_reqs == 0)
- {
- SOCK_put_string(self->sock, "Q ");
- SOCK_flush_output(self->sock);
- empty_reqs++;
- }
}
break;
case 'Z': /* Backend is ready for new query (6.4) */
case 'I': /* The server sends an empty query */
/* There is a closing '\0' following the 'I', so we eat it */
- if (PROTOCOL_74(ci) && 0 == response_length)
+ if (0 == response_length)
swallow = '\0';
else
swallow = SOCK_get_char(self->sock);
if (--empty_reqs == 0)
query_completed = TRUE;
}
- else if (!beforeV2)
+ else
query_completed = TRUE;
break;
case 'E':
break;
if (CONN_DOWN == self->status)
break;
- /*
- * There was no ReadyForQuery response before 6.4.
- */
- if (beforeV2)
- {
- if (empty_reqs == 0 && query_completed)
- break;
- }
}
cleanup:
int ret = TRUE;
UInt4 leng;
Int4 response_length;
- ConnInfo *ci;
int func_cs_count = 0;
- BOOL sinceV3, beforeV3, beforeV2, resultResponse;
+ BOOL resultResponse;
mylog("send_function(): conn=%p, fnid=%d, result_is_int=%d, nargs=%d\n", self, fnid, result_is_int, nargs);
}
#define return DONT_CALL_RETURN_FROM_HERE???
ENTER_INNER_CONN_CS(self, func_cs_count);
- ci = &(self->connInfo);
- sinceV3 = PROTOCOL_74(ci);
- beforeV3 = (!sinceV3);
- beforeV2 = (beforeV3 && !PROTOCOL_64(ci));
- if (sinceV3)
- {
- leng = 4 + sizeof(uint32) + 2 + 2
- + sizeof(uint16);
- for (i = 0; i < nargs; i++)
+ leng = 4 + sizeof(uint32) + 2 + 2
+ + sizeof(uint16);
+
+ for (i = 0; i < nargs; i++)
+ {
+ leng += 4;
+ if (args[i].len >= 0)
{
- leng += 4;
- if (args[i].len >= 0)
- {
- if (args[i].isint)
- leng += 4;
- else
- leng += args[i].len;
- }
+ if (args[i].isint)
+ leng += 4;
+ else
+ leng += args[i].len;
}
- leng += 2;
- SOCK_put_char(sock, 'F');
- SOCK_put_int(sock, leng, 4);
}
- else
- SOCK_put_string(sock, "F ");
+ leng += 2;
+ SOCK_put_char(sock, 'F');
+ SOCK_put_int(sock, leng, 4);
if (SOCK_get_errcode(sock) != 0)
{
CC_set_error(self, CONNECTION_COULD_NOT_SEND, "Could not send function to backend", func);
}
SOCK_put_int(sock, fnid, 4);
- if (sinceV3)
- {
- SOCK_put_int(sock, 1, 2); /* # of formats */
- SOCK_put_int(sock, 1, 2); /* the format is binary */
- SOCK_put_int(sock, nargs, 2);
- }
- else
- SOCK_put_int(sock, nargs, 4);
+ SOCK_put_int(sock, 1, 2); /* # of formats */
+ SOCK_put_int(sock, 1, 2); /* the format is binary */
+ SOCK_put_int(sock, nargs, 2);
mylog("send_function: done sending function\n");
}
- if (sinceV3)
- SOCK_put_int(sock, 1, 2); /* result format is binary */
+ SOCK_put_int(sock, 1, 2); /* result format is binary */
mylog(" done sending args\n");
SOCK_flush_output(sock);
break;
} /* fall through */
case 'V':
- if ('V' == id)
- {
- if (beforeV3) /* FunctionResultResponse */
- {
- resultResponse = TRUE;
- break;
- }
- }
*actual_result_len = SOCK_get_int(sock, 4);
if (-1 != *actual_result_len)
{
mylog(" after get result\n");
}
- if (beforeV3)
- {
- SOCK_get_char(sock); /* get the last '0' */
- if (beforeV2)
- done = TRUE;
- resultResponse = FALSE;
- mylog(" after get 0\n");
- }
break; /* ok */
case 'N':
mylog("send_function(V): 'E' - %s\n", CC_get_errormsg(self));
qlog("ERROR from backend during send_function: '%s'\n", CC_get_errormsg(self));
- if (beforeV2)
- done = TRUE;
ret = FALSE;
break;
case '0': /* empty result */
if (resultResponse)
{
- if (beforeV2)
- done = TRUE;
resultResponse = FALSE;
break;
} /* fall through */
}
- /* KSQO (not applicable to 7.1+ - DJP 21/06/2002) */
- if (ci->drivers.ksqo && PG_VERSION_LT(self, 7.1))
- {
- result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "set ksqo to 'ON'", SQL_NTS, 0);
- if (!SQL_SUCCEEDED(result))
- status = FALSE;
-
- mylog("%s: result %d, status %d from set ksqo\n", func, result, status);
-
- }
-
- /* extra_float_digits (applicable since 7.4) */
- if (PG_VERSION_GT(self, 7.3))
- {
- result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "set extra_float_digits to 2", SQL_NTS, 0);
- if (!SQL_SUCCEEDED(result))
- status = FALSE;
-
- mylog("%s: result %d, status %d from set extra_float_digits\n", func, result, status);
+ result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "set extra_float_digits to 2", SQL_NTS, 0);
+ if (!SQL_SUCCEEDED(result))
+ status = FALSE;
- }
+ mylog("%s: result %d, status %d from set extra_float_digits\n", func, result, status);
PGAPI_FreeStmt(hstmt, SQL_DROP);
mylog("%s: entering...\n", func);
- if (PG_VERSION_GE(self, 7.4))
- res = CC_send_query(self, "select oid, typbasetype from pg_type where typname = '" PG_TYPE_LO_NAME "'",
- NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
- else
- res = CC_send_query(self, "select oid, 0 from pg_type where typname='" PG_TYPE_LO_NAME "'",
- NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
+ res = CC_send_query(self, "select oid, typbasetype from pg_type where typname = '" PG_TYPE_LO_NAME "'",
+ NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
if (QR_command_maybe_successful(res) && QR_get_num_cached_tuples(res) > 0)
{
OID basetype;
void
CC_initialize_pg_version(ConnectionClass *self)
{
- strncpy_null(self->pg_version, self->connInfo.protocol, sizeof(self->pg_version));
- if (PROTOCOL_62(&self->connInfo))
- {
- self->pg_version_number = (float) 6.2;
- self->pg_version_major = 6;
- self->pg_version_minor = 2;
- }
- else if (PROTOCOL_63(&self->connInfo))
- {
- self->pg_version_number = (float) 6.3;
- self->pg_version_major = 6;
- self->pg_version_minor = 3;
- }
- else if (PROTOCOL_64(&self->connInfo))
- {
- self->pg_version_number = (float) 6.4;
- self->pg_version_major = 6;
- self->pg_version_minor = 4;
- }
- else
- {
- self->pg_version_number = (float) 7.4;
- self->pg_version_major = 7;
- self->pg_version_minor = 4;
- }
-}
-
-
-/*
- * This function gets the version of PostgreSQL that we're connected to.
- * This is used to return the correct info in SQLGetInfo
- * DJP - 25-1-2001
- */
-static void
-CC_lookup_pg_version(ConnectionClass *self)
-{
- HSTMT hstmt;
- RETCODE result;
- char szVersion[32];
- int major,
- minor;
- CSTR func = "CC_lookup_pg_version";
-
- mylog("%s: entering...\n", func);
-
-/*
- * This function must use the local odbc API functions since the odbc state
- * has not transitioned to "connected" yet.
- */
- result = PGAPI_AllocStmt(self, &hstmt, 0);
- if (!SQL_SUCCEEDED(result))
- return;
-
- /* get the server's version if possible */
- result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "select version()", SQL_NTS, 0);
- if (!SQL_SUCCEEDED(result))
- {
- PGAPI_FreeStmt(hstmt, SQL_DROP);
- return;
- }
-
- result = PGAPI_Fetch(hstmt);
- if (!SQL_SUCCEEDED(result))
- {
- PGAPI_FreeStmt(hstmt, SQL_DROP);
- return;
- }
-
- result = PGAPI_GetData(hstmt, 1, SQL_C_CHAR, self->pg_version, MAX_INFO_STRING, NULL);
- if (!SQL_SUCCEEDED(result))
- {
- PGAPI_FreeStmt(hstmt, SQL_DROP);
- return;
- }
-
- /*
- * Extract the Major and Minor numbers from the string. This assumes
- * the string starts 'Postgresql X.X'
- */
- strcpy(szVersion, "0.0");
- if (sscanf(self->pg_version, "%*s %d.%d", &major, &minor) >= 2)
- {
- snprintf(szVersion, sizeof(szVersion), "%d.%d", major, minor);
- self->pg_version_major = major;
- self->pg_version_minor = minor;
- }
- self->pg_version_number = (float) atof(szVersion);
- if (PG_VERSION_GE(self, 7.3))
- self->schema_support = 1;
-
- mylog("Got the PostgreSQL version string: '%s'\n", self->pg_version);
- mylog("Extracted PostgreSQL version number: '%1.1f'\n", self->pg_version_number);
- qlog(" [ PostgreSQL version string = '%s' ]\n", self->pg_version);
- qlog(" [ PostgreSQL version number = '%1.1f' ]\n", self->pg_version_number);
-
- PGAPI_FreeStmt(hstmt, SQL_DROP);
+ strcpy(self->pg_version, "7.4");
+ self->pg_version_number = (float) 7.4;
+ self->pg_version_major = 7;
+ self->pg_version_minor = 4;
}
{
SocketClass *sock = self->sock;
- qlog(" socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n", sock->socket, sock->reverse, sock->errornumber, nullcheck(SOCK_get_errmsg(sock)));
+ qlog(" socket=%d, errornumber=%d, errormsg='%s'\n", sock->socket, sock->errornumber, nullcheck(SOCK_get_errmsg(sock)));
qlog(" buffer_in=%u, buffer_out=%u\n", sock->buffer_in, sock->buffer_out);
qlog(" buffer_filled_in=%d, buffer_filled_out=%d, buffer_read_in=%d\n", sock->buffer_filled_in, sock->buffer_filled_out, sock->buffer_read_in);
}
#undef PRN_NULLCHECK
}
-int
-CC_get_max_query_len(const ConnectionClass *conn)
-{
- int value;
-
- /* Long Queries in 7.0+ */
- if (PG_VERSION_GE(conn, 7.0))
- value = 0 /* MAX_STATEMENT_LEN */ ;
- /* Prior to 7.0 we used 2*BLCKSZ */
- else if (PG_VERSION_GE(conn, 6.5))
- value = (2 * BLCKSZ);
- else
- /* Prior to 6.5 we used BLCKSZ */
- value = BLCKSZ;
- return value;
-}
-
/*
* This doesn't really return the CURRENT SCHEMA
* but there's no alternative.
const char *
CC_get_current_schema(ConnectionClass *conn)
{
- if (!conn->current_schema && conn->schema_support)
+ if (!conn->current_schema)
{
QResultClass *res;
if (TRUE)
{
int pversion;
- ConnInfo *ci = &self->connInfo;
- sock->pversion = PG_PROTOCOL_74;
- strncpy_null(ci->protocol, PG74, sizeof(ci->protocol));
+ sock->pversion = PG_PROTOCOL_LATEST;
pversion = PQprotocolVersion(pqconn);
- switch (pversion)
+ if (pversion < 3)
{
- case 2:
- sock->pversion = PG_PROTOCOL_64;
- strncpy_null(ci->protocol, PG64, sizeof(ci->protocol));
- break;
+ mylog("Protocol version %d is not supported\n", pversion);
+ goto cleanup1;
}
+ mylog("protocol=%d\n", pversion);
}
- mylog("protocol=%s\n", self->connInfo.protocol);
{
int pversion;
const char *conforming_strings;
self->pg_version_minor = (pversion % 10000) / 100;
sprintf(self->pg_version, "%d.%d.%d", self->pg_version_major, self->pg_version_minor, pversion % 100);
self->pg_version_number = (float) atof(self->pg_version);
- if (PG_VERSION_GE(self, 7.3))
- self->schema_support = 1;
if (conforming_strings = PQparameterStatus(pqconn, std_cnf_strs), NULL != conforming_strings)
{
if (stricmp(conforming_strings, "on") == 0)
*/
if (isMsQuery()) /* MS Query */
return NULL;
- else if (conn->schema_support)
- return conn->connInfo.database;
- else
- return NULL;
+ return conn->connInfo.database;
}
const char *CurrCatString(const ConnectionClass *conn)
if (0 >= ci->xa_opt) return;
switch (ci->xa_opt)
{
- case DTC_CHECK_LINK_ONLY:
+ case DTC_CHECK_LINK_ONLY:
case DTC_CHECK_BEFORE_LINK:
sprintf(xaOptStr, KEYWORD_DTC_CHECK "=0;");
break;
#endif /* USE_LIBPQ */
,
- drivername, xaOptStr
+ drivername, xaOptStr
, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode
#ifdef USE_LIBPQ
, (CC_get_socket(conn))->via_libpq
}
#endif /* USE_LIBPQ */
- ret = 1;
+ ret = 1;
if (outReason)
*reason = '\0';
delim = "";
- if (doubtRootCert)
+ if (doubtRootCert)
{
if (outReason)
snprintf(reason, rsize, "%s%ssslmode verify-[ca|full]", reason, delim);
delim = ", ";
ret = -1;
}
- if (doubtCert)
+ if (doubtCert)
{
if (outReason)
snprintf(reason, rsize, "%s%scertificate", reason, delim);
delim = ", ";
ret = -1;
}
- if (doubtCert)
+ if (doubtCert)
{
if (outReason)
snprintf(reason, rsize, "%s%ssspi", reason, delim);
#define SM_UNUSED 64
#define SM_TTY 64
-/* Old 6.2 protocol defines */
-#define NO_AUTHENTICATION 7
-#define PATH_SIZE 64
-#define ARGV_SIZE 64
-#define USRNAMEDATALEN 16
-
typedef unsigned int ProtocolVersion;
#define PG_PROTOCOL(major, minor) (((major) << 16) | (minor))
#define PG_PROTOCOL_LATEST PG_PROTOCOL(3, 0)
-#define PG_PROTOCOL_74 PG_PROTOCOL(3, 0)
-#define PG_PROTOCOL_64 PG_PROTOCOL(2, 0)
-#define PG_PROTOCOL_63 PG_PROTOCOL(1, 0)
-#define PG_PROTOCOL_62 PG_PROTOCOL(0, 0)
#define PG_NEGOTIATE_SSLMODE PG_PROTOCOL(1234, 5679)
-/* This startup packet is to support latest Postgres protocol (6.4, 6.3) */
-typedef struct _StartupPacket
-{
- ProtocolVersion protoVersion;
- char database[SM_DATABASE];
- char user[SM_USER];
- char options[SM_OPTIONS];
- char unused[SM_UNUSED];
- char tty[SM_TTY];
-} StartupPacket;
-
-
-/* This startup packet is to support pre-Postgres 6.3 protocol */
-typedef struct _StartupPacket6_2
-{
- unsigned int authtype;
- char database[PATH_SIZE];
- char user[USRNAMEDATALEN];
- char options[ARGV_SIZE];
- char execfile[ARGV_SIZE];
- char tty[PATH_SIZE];
-} StartupPacket6_2;
-
/* Transferred from pqcomm.h: */
-
typedef ProtocolVersion MsgType;
#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
char database[MEDIUM_REGISTRY_LEN];
char username[MEDIUM_REGISTRY_LEN];
pgNAME password;
- char protocol[SMALL_REGISTRY_LEN];
char port[SMALL_REGISTRY_LEN];
char sslmode[16];
char onlyread[SMALL_REGISTRY_LEN];
GLOBAL_VALUES drivers; /* moved from driver's option */
} ConnInfo;
-/* Macro to determine is the connection using 6.2 protocol? */
-#define PROTOCOL_62(conninfo_) (strncmp((conninfo_)->protocol, PG62, strlen(PG62)) == 0)
-
-/* Macro to determine is the connection using 6.3 protocol? */
-#define PROTOCOL_63(conninfo_) (strncmp((conninfo_)->protocol, PG63, strlen(PG63)) == 0)
-
-/* Macro to determine is the connection using 6.4 protocol? */
-#define PROTOCOL_64(conninfo_) (strncmp((conninfo_)->protocol, PG64, strlen(PG64)) == 0)
-
-/* Macro to determine is the connection using 7.4 protocol? */
-#define PROTOCOL_74(conninfo_) (strncmp((conninfo_)->protocol, PG74, strlen(PG74)) == 0)
-
/* Macro to determine is the connection using 7.4 rejected? */
#define PROTOCOL_74REJECTED(conninfo_) (strncmp((conninfo_)->protocol, PG74REJECTED, strlen(PG74REJECTED)) == 0)
-#define SUPPORT_DESCRIBE_PARAM(conninfo_) (PROTOCOL_74(conninfo_) && conninfo_->use_server_side_prepare)
+#define SUPPORT_DESCRIBE_PARAM(conninfo_) (conninfo_->use_server_side_prepare)
+
/*
* Macros to compare the server's version with a specified version
* 1st parameter: pointer to a ConnectionClass object
((conn)->pg_version_major == major && (conn)->pg_version_minor >= minor))
#define SERVER_VERSION_EQ(conn, major, minor) \
((conn)->pg_version_major == major && (conn)->pg_version_minor == minor)
-#define SERVER_VERSION_LE(conn, major, minor) (! SERVER_VERSION_GT(conn, major, minor))
-#define SERVER_VERSION_LT(conn, major, minor) (! SERVER_VERSION_GE(conn, major, minor))
-/*#if ! defined(HAVE_CONFIG_H) || defined(HAVE_STRINGIZE)*/
#define STRING_AFTER_DOT(string) (strchr(#string, '.') + 1)
-/*#else
-#define STRING_AFTER_DOT(str) (strchr("str", '.') + 1)
-#endif*/
+
/*
* Simplified macros to compare the server's version with a
* specified version
/* This is used to store cached table information in the connection */
struct col_info
{
- Int2 num_reserved_cols;
Int2 refcnt;
QResultClass *result;
pgNAME schema_name;
char ms_jet;
char unicode;
char result_uncommitted;
- char schema_support;
char lo_is_domain;
char escape_in_literal;
char *original_client_encoding;
#define CC_is_onlyread(x) (x->connInfo.onlyread[0] == '1')
#define CC_get_escape(x) (x->escape_in_literal)
#define CC_fake_mss(x) (/* 0 != (x)->ms_jet && */ 0 < (x)->connInfo.fake_mss)
-#define CC_accessible_only(x) (0 < (x)->connInfo.accessible_only && PG_VERSION_GE((x), 7.2))
+#define CC_accessible_only(x) (0 < (x)->connInfo.accessible_only)
#define CC_default_is_c(x) (CC_is_in_ansi_app(x) || x->ms_jet /* not only */ || TRUE /* but for any other ? */)
/* for CC_DSN_info */
#define CONN_DONT_OVERWRITE 0
*/
void CC_initialize_pg_version(ConnectionClass *conn);
void CC_log_error(const char *func, const char *desc, const ConnectionClass *self);
-int CC_get_max_query_len(const ConnectionClass *self);
-int CC_send_cancel_request(const ConnectionClass *conn);
+int CC_send_cancel_request(const ConnectionClass *conn);
void CC_on_commit(ConnectionClass *conn);
void CC_on_abort(ConnectionClass *conn, UDWORD opt);
void CC_on_abort_partial(ConnectionClass *conn);
}
if (strnicmp(value, "invalid", 7) != 0)
{
- BOOL bZone = (field_type != PG_TYPE_TIMESTAMP_NO_TMZONE && PG_VERSION_GE(conn, 7.2));
+ BOOL bZone = field_type != PG_TYPE_TIMESTAMP_NO_TMZONE;
int zone;
/*
if (sscanf(vp, "%hi", &shortv) != 1)
break;
mylog(" %hi", shortv);
- if (0 == shortv && PG_VERSION_LT(conn, 7.2))
- break;
nval++;
if (nval < maxc)
short_array[i + 1] = shortv;
/* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */
len = stime2timestamp(&std_time, rgbValueBindRow, cbValueMax, FALSE,
- PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0);
+ (int) cbValueMax - len - 2 );
if (len + 1 > cbValueMax)
result = COPY_RESULT_TRUNCATED;
break;
static void
QP_initialize(QueryParse *q, const StatementClass *stmt)
{
- q->statement = stmt->execute_statement ? stmt->execute_statement : stmt->statement;
+ q->statement = stmt->statement;
q->statement_type = stmt->statement_type;
q->opos = 0;
q->from_pos = -1;
#define FLGB_PRE_EXECUTING 1L
#define FLGB_BUILDING_PREPARE_STATEMENT (1L << 1)
#define FLGB_BUILDING_BIND_REQUEST (1L << 2)
-#define FLGB_EXECUTE_PREPARED (1L << 3)
#define FLGB_INACCURATE_RESULT (1L << 4)
#define FLGB_CREATE_KEYSET (1L << 5)
#define FLGB_HEX_BIN_FORMAT (1L << 11)
typedef struct _QueryBuild {
char *query_statement;
- size_t str_size_limit;
size_t str_alsize;
size_t npos;
SQLLEN current_row;
if (PG_VERSION_GE(qb->conn, 9.0))
qb->flags |= FLGB_HEX_BIN_FORMAT;
- if (stmt)
- qb->str_size_limit = stmt->stmt_size_limit;
- else
- qb->str_size_limit = -1;
- if (qb->str_size_limit > 0)
- {
- if (size > qb->str_size_limit)
- return -1;
- newsize = qb->str_size_limit;
- }
- else
- {
- newsize = INIT_MIN_ALLOC;
- while (newsize <= size)
- newsize *= 2;
- }
+ newsize = INIT_MIN_ALLOC;
+ while (newsize <= size)
+ newsize *= 2;
+
if ((qb->query_statement = malloc(newsize)) == NULL)
{
qb->str_alsize = 0;
{
memcpy(qb_to, qb_from, sizeof(QueryBuild));
- if (qb_to->str_size_limit > 0)
- {
- if (size > qb_to->str_size_limit)
- return -1;
- }
if ((qb_to->query_statement = malloc(size)) == NULL)
{
qb_to->str_alsize = 0;
size_t newalsize = INIT_MIN_ALLOC;
CSTR func = "enlarge_statement";
- if (qb->str_size_limit > 0 && qb->str_size_limit < (int) newsize)
- {
- free(qb->query_statement);
- qb->query_statement = NULL;
- qb->str_alsize = 0;
- if (qb->stmt)
- {
- SC_set_error(qb->stmt, STMT_EXEC_ERROR, "Query buffer overflow in copy_statement_with_parameters", func);
- }
- else
- {
- qb->errormsg = "Query buffer overflow in copy_statement_with_parameters";
- qb->errornumber = STMT_EXEC_ERROR;
- }
- return -1;
- }
while (newalsize <= newsize)
newalsize *= 2;
if (!(qb->query_statement = realloc(qb->query_statement, newalsize)))
static int
Prepare_and_convert(StatementClass *stmt, QueryParse *qp, QueryBuild *qb)
{
- CSTR func = "Prepare_and_convert";
- char *exe_statement = NULL;
- RETCODE retval;
- ConnectionClass *conn = SC_get_conn(stmt);
- ConnInfo *ci = &(conn->connInfo);
- BOOL discardOutput, outpara;
-
- if (PROTOCOL_74(ci))
+ switch (stmt->prepared)
{
- switch (stmt->prepared)
- {
- case NOT_YET_PREPARED:
- case ONCE_DESCRIBED:
- break;
- default:
- return SQL_SUCCESS;
- }
+ case NOT_YET_PREPARED:
+ case ONCE_DESCRIBED:
+ break;
+ default:
+ return SQL_SUCCESS;
}
if (QB_initialize(qb, qp->stmt_len, stmt, NULL) < 0)
return SQL_ERROR;
- if (PROTOCOL_74(ci))
- return prep_params(stmt, qp, qb, FALSE);
- discardOutput = (0 != (qb->flags & FLGB_DISCARD_OUTPUT));
- if (NOT_YET_PREPARED == stmt->prepared) /* not yet prepared */
- {
- ssize_t elen;
- int i, oc;
- SQLSMALLINT marker_count;
- const IPDFields *ipdopts = qb->ipdopts;
- char plan_name[32];
-
- qb->flags |= FLGB_BUILDING_PREPARE_STATEMENT;
- sprintf(plan_name, "_PLAN%p", stmt);
-#ifdef NOT_USED
- new_statement = qb->query_statement;
- sprintf(new_statement, "PREPARE \"%s\"", plan_name);
- qb->npos = strlen(new_statement);
-#endif /* NOT_USED */
- CVT_APPEND_STR(qb, "PREPARE \"");
- CVT_APPEND_STR(qb, plan_name);
- CVT_APPEND_CHAR(qb, IDENTIFIER_QUOTE);
- marker_count = stmt->num_params - qb->num_discard_params;
- if (!ipdopts || ipdopts->allocated < marker_count)
- {
- SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT,
- "The # of binded parameters < the # of parameter markers", func);
- retval = SQL_ERROR;
- goto cleanup;
- }
- if (marker_count > 0)
- {
- CVT_APPEND_CHAR(qb, '(');
- for (i = qb->proc_return, oc = 0; i < stmt->num_params; i++)
- {
- outpara = FALSE;
- if (i < ipdopts->allocated &&
- SQL_PARAM_OUTPUT == ipdopts->parameters[i].paramType)
- {
- outpara = TRUE;
- if (discardOutput)
- continue;
- }
- if (oc > 0)
- CVT_APPEND_STR(qb, ", ");
- if (outpara)
- CVT_APPEND_STR(qb, "void");
- else
- CVT_APPEND_STR(qb, pgtype_to_name(stmt, PIC_dsp_pgtype(conn, ipdopts->parameters[i]), -1, FALSE));
- oc++;
- }
- CVT_APPEND_CHAR(qb, ')');
- }
- CVT_APPEND_STR(qb, " as ");
- for (qp->opos = 0; qp->opos < qp->stmt_len; qp->opos++)
- {
- retval = inner_process_tokens(qp, qb);
- if (SQL_ERROR == retval)
- goto cleanup;
- }
- CVT_APPEND_CHAR(qb, ';');
- /* build the execute statement */
- exe_statement = malloc(30 + 2 * marker_count);
- sprintf(exe_statement, "EXECUTE \"%s\"", plan_name);
- if (marker_count > 0)
- {
- elen = strlen(exe_statement);
- exe_statement[elen++] = '(';
- for (i = 0; i < marker_count; i++)
- {
- if (i > 0)
- exe_statement[elen++] = ',';
- exe_statement[elen++] = '?';
- }
- exe_statement[elen++] = ')';
- exe_statement[elen] = '\0';
- }
-inolog("exe_statement=%s\n", exe_statement);
- stmt->execute_statement = exe_statement;
- QP_initialize(qp, stmt);
- SC_set_planname(stmt, plan_name);
- }
- qb->flags &= FLGB_DISCARD_OUTPUT;
- qb->flags |= FLGB_EXECUTE_PREPARED;
- qb->param_number = -1;
- for (qp->opos = 0; qp->opos < qp->stmt_len; qp->opos++)
- {
- retval = inner_process_tokens(qp, qb);
- if (SQL_ERROR == retval)
- goto cleanup;
- }
- /* make sure new_statement is always null-terminated */
- CVT_TERMINATE(qb);
- retval = SQL_SUCCESS;
-
-cleanup:
- if (SQL_SUCCEEDED(retval))
- {
- if (exe_statement)
- SC_set_concat_prepare_exec(stmt);
- stmt->stmt_with_params = qb->query_statement;
- qb->query_statement = NULL;
- }
- else
- {
- QB_replace_SC_error(stmt, qb, func);
- if (exe_statement)
- {
- free(exe_statement);
- stmt->execute_statement = NULL;
- }
- QB_Destructor(qb);
- }
- return retval;
+ return prep_params(stmt, qp, qb, FALSE);
}
#define my_strchr(conn, s1,c1) pg_mbschr(conn->ccsc, s1,c1)
if (prepare_dummy_cursor)
{
SC_set_fetchcursor(stmt);
- if (PG_VERSION_GE(conn, 7.4))
- opt_scroll = " scroll";
- if (!CC_is_in_trans(conn) && PG_VERSION_GE(conn, 7.1))
+ opt_scroll = " scroll";
+ if (!CC_is_in_trans(conn))
{
strcpy(new_statement, "BEGIN;");
begin_first = TRUE;
SC_set_fetchcursor(stmt);
if (SC_is_with_hold(stmt))
opt_hold = " with hold";
- if (PG_VERSION_GE(conn, 7.4))
- {
- if (SQL_CURSOR_FORWARD_ONLY != stmt->options.cursor_type)
- opt_scroll = " scroll";
- }
+ if (SQL_CURSOR_FORWARD_ONLY != stmt->options.cursor_type)
+ opt_scroll = " scroll";
}
if (SC_is_fetchcursor(stmt))
{
CVT_TERMINATE(qb); /* just in case */
return SQL_ERROR;
}
- if (0 != (qb->flags & FLGB_EXECUTE_PREPARED)
- && (outputDiscard || param_number < qb->proc_return)
- )
- {
- while (ipara && SQL_PARAM_OUTPUT == ipara->paramType)
- {
- apara = NULL;
- ipara = NULL;
- param_number = ++qb->param_number;
- if (param_number < apdopts->allocated)
- apara = apdopts->parameters + param_number;
- if (param_number < ipdopts->allocated)
- ipara = ipdopts->parameters + param_number;
- }
- }
inolog("ipara=%p paramType=%d %d proc_return=%d\n", ipara, ipara ? ipara->paramType : -1, PG_VERSION_LT(conn, 8.1), qb->proc_return);
if (param_number < qb->proc_return)
* st.m, st.d, st.hh, st.mm, st.ss);
*/
/* Time zone stuff is unreliable */
- stime2timestamp(&st, tmp, sizeof(tmp), USE_ZONE, PG_VERSION_GE(conn, 7.2) ? 6 : 0);
+ stime2timestamp(&st, tmp, sizeof(tmp), USE_ZONE, 6);
lastadd = "::timestamp";
CVT_APPEND_STR(qb, tmp);
convert_escape(QueryParse *qp, QueryBuild *qb)
{
CSTR func = "convert_escape";
- ConnectionClass *conn = qb->conn;
RETCODE retval = SQL_SUCCESS;
char buf[1024], buf_small[128], key[65];
UCHAR ucv;
}
while (isspace((UCHAR) qp->statement[++qp->opos]));
}
- /**
- if (qp->statement_type == STMT_TYPE_PROCCALL)
- {
- int lit_call_len = 4;
-
- // '?=' to accept return values exists ?
- if (F_OldChar(qp) == '?')
- {
- qb->param_number++;
- qb->proc_return = 1;
- if (qb->stmt)
- qb->stmt->proc_return = 1;
- while (isspace((UCHAR) qp->statement[++qp->opos]));
- if (F_OldChar(qp) != '=')
- {
- F_OldPrior(qp);
- return SQL_SUCCESS;
- }
- while (isspace((UCHAR) qp->statement[++qp->opos]));
- }
- if (strnicmp(F_OldPtr(qp), "call", lit_call_len) ||
- !isspace((UCHAR) F_OldPtr(qp)[lit_call_len]))
- {
- F_OldPrior(qp);
- return SQL_SUCCESS;
- }
- qp->opos += lit_call_len;
- if (qb->num_io_params > 1 ||
- (0 == qb->proc_return &&
- PG_VERSION_GE(conn, 7.3)))
- CVT_APPEND_STR(qb, "SELECT * FROM");
- else
- CVT_APPEND_STR(qb, "SELECT");
- if (my_strchr(conn, F_OldPtr(qp), '('))
- qp->proc_no_param = FALSE;
- return SQL_SUCCESS;
- }
- **/
sscanf(F_OldPtr(qp), "%32s", key);
while ((ucv = F_OldChar(qp)) != '\0' && (!isspace(ucv)))
goto cleanup;
}
if (qb->num_io_params > 1 ||
- (0 == qb->proc_return &&
- PG_VERSION_GE(conn, 7.3)))
+ (0 == qb->proc_return))
CVT_APPEND_STR(qb, "SELECT * FROM ");
else
CVT_APPEND_STR(qb, "SELECT ");
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- if (PG_VERSION_LT(conn, 7.3))
- prtlen = snprintf(buf, sizeof(buf), "%s", buf_small);
- else
- prtlen = snprintf(buf, sizeof(buf), "%s::date", buf_small);
+ prtlen = snprintf(buf, sizeof(buf), "%s::date", buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- if (PG_VERSION_LT(conn, 7.1))
- prtlen = snprintf(buf, sizeof(buf), "%s::datetime", buf_small);
- else
- prtlen = snprintf(buf, sizeof(buf), "%s::timestamp", buf_small);
+ prtlen = snprintf(buf, sizeof(buf), "%s::timestamp", buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
{
memset(self, 0, sizeof(TABLE_INFO));
TI_set_updatable(self);
- if (PG_VERSION_LT(conn, 7.2))
- {
- char qual[32];
-
- STR_TO_NAME(self->bestitem, OID_NAME);
- sprintf(qual, "\"%s\" = %%u", OID_NAME);
- STRX_TO_NAME(self->bestqual, qual);
- TI_set_hasoids(self);
- TI_set_hasoids_checked(self);
- }
}
void TI_Destructor(TABLE_INFO **ti, int count)
{
char protocol_and[16];
if (ci->rollback_on_error >= 0)
- snprintf(protocol_and, sizeof(protocol_and), "%s-%d", ci->protocol, ci->rollback_on_error);
+ snprintf(protocol_and, sizeof(protocol_and), "7.4-%d", ci->rollback_on_error);
else
- strncpy_null(protocol_and, ci->protocol, sizeof(protocol_and));
+ strcpy(protocol_and, "7.4");
olen = snprintf(&connect_string[hlen], nlen, ";"
INI_SSLMODE "=%s;"
INI_READONLY "=%s;"
INI_DEBUG "=%d;"
INI_COMMLOG "=%d;"
INI_OPTIMIZER "=%d;"
- INI_KSQO "=%d;"
INI_USEDECLAREFETCH "=%d;"
INI_TEXTASLONGVARCHAR "=%d;"
INI_UNKNOWNSASLONGVARCHAR "=%d;"
,ci->drivers.debug
,ci->drivers.commlog
,ci->drivers.disable_optimizer
- ,ci->drivers.ksqo
,ci->drivers.use_declarefetch
,ci->drivers.text_as_longvarchar
,ci->drivers.unknowns_as_longvarchar
flag |= BIT_LFCONVERSION;
if (ci->drivers.unique_index)
flag |= BIT_UNIQUEINDEX;
- if (PROTOCOL_74(ci))
- flag |= (BIT_PROTOCOL_64 | BIT_PROTOCOL_63);
- else if (PROTOCOL_64(ci))
- flag |= BIT_PROTOCOL_64;
- else if (PROTOCOL_63(ci))
- flag |= BIT_PROTOCOL_63;
switch (ci->drivers.unknown_sizes)
{
case UNKNOWNS_AS_DONTKNOW:
}
if (ci->drivers.disable_optimizer)
flag |= BIT_OPTIMIZER;
- if (ci->drivers.ksqo)
- flag |= BIT_KSQO;
if (ci->drivers.commlog)
flag |= BIT_COMMLOG;
if (ci->drivers.debug)
makeXaOptConnectString(xaOptStr, ci, TRUE),
#endif /* _HANDLE_ENLIST_IN_DTC_ */
EFFECTIVE_BIT_COUNT, flag);
- if (olen < nlen && (PROTOCOL_74(ci) || ci->rollback_on_error >= 0))
+ if (olen < nlen || ci->rollback_on_error >= 0)
{
hlen = strlen(connect_string);
nlen = MAX_CONNECT_STRING - hlen;
*/
if (ci->rollback_on_error >= 0)
olen = snprintf(&connect_string[hlen], nlen, ";"
- ABBR_PROTOCOL "=%s-%d",
- ci->protocol, ci->rollback_on_error);
+ ABBR_PROTOCOL "=7.4-%d",
+ ci->rollback_on_error);
else
olen = snprintf(&connect_string[hlen], nlen, ";"
- ABBR_PROTOCOL "=%s",
- ci->protocol);
+ ABBR_PROTOCOL "=7.4");
}
}
if (olen < nlen)
if (count < 4)
return;
ci->drivers.unique_index = (char)((flag & BIT_UNIQUEINDEX) != 0);
- if ((flag & BIT_PROTOCOL_64) != 0)
- {
- if ((flag & BIT_PROTOCOL_63) != 0)
- strcpy(ci->protocol, PG74);
- else
- strcpy(ci->protocol, PG64);
- }
- else if ((flag & BIT_PROTOCOL_63) != 0)
- strcpy(ci->protocol, PG63);
- else
- strcpy(ci->protocol, PG62);
if ((flag & BIT_UNKNOWN_DONTKNOW) != 0)
ci->drivers.unknown_sizes = UNKNOWNS_AS_DONTKNOW;
else if ((flag & BIT_UNKNOWN_ASMAX) != 0)
else
ci->drivers.unknown_sizes = UNKNOWNS_AS_LONGEST;
ci->drivers.disable_optimizer = (char)((flag & BIT_OPTIMIZER) != 0);
- ci->drivers.ksqo = (char)((flag & BIT_KSQO) != 0);
ci->drivers.commlog = (char)((flag & BIT_COMMLOG) != 0);
ci->drivers.debug = (char)((flag & BIT_DEBUG) != 0);
ci->drivers.parse = (char)((flag & BIT_PARSE) != 0);
else if (stricmp(attribute, INI_PROTOCOL) == 0 || stricmp(attribute, ABBR_PROTOCOL) == 0)
{
char *ptr;
-
+ /*
+ * The first part of the Protocol used to be "6.2", "6.3" or
+ * "7.4" to denote which protocol version to use. Nowadays we
+ * only support the 7.4 protocol, also known as the protocol
+ * version 3. So just ignore the first part of the string,
+ * parsing only the rollback_on_error value.
+ */
ptr = strchr(value, '-');
if (ptr)
{
if ('-' != *value)
{
*ptr = '\0';
- strcpy(ci->protocol, value);
+ /* ignore first part */
}
ci->rollback_on_error = atoi(ptr + 1);
mylog("rollback_on_error=%d\n", ci->rollback_on_error);
}
- else
- strcpy(ci->protocol, value);
}
else if (stricmp(attribute, INI_SHOWOIDCOLUMN) == 0 || stricmp(attribute, ABBR_SHOWOIDCOLUMN) == 0)
else
found = FALSE;
- mylog("%s: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s',conn_settings='%s',disallow_premature=%d)\n", func, ci->dsn, ci->server, ci->database, ci->username, NAME_IS_VALID(ci->password) ? "xxxxx" : "", ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature);
+ mylog("%s: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',conn_settings='%s',disallow_premature=%d)\n", func, ci->dsn, ci->server, ci->database, ci->username, NAME_IS_VALID(ci->password) ? "xxxxx" : "", ci->port, ci->onlyread, ci->conn_settings, ci->disallow_premature);
return found;
}
ci->drivers.commlog = atoi(value);
else if (stricmp(attribute, INI_OPTIMIZER) == 0 || stricmp(attribute, ABBR_OPTIMIZER) == 0)
ci->drivers.disable_optimizer = atoi(value);
- else if (stricmp(attribute, INI_KSQO) == 0 || stricmp(attribute, ABBR_KSQO) == 0)
- ci->drivers.ksqo = atoi(value);
/*
* else if (stricmp(attribute, INI_UNIQUEINDEX) == 0 ||
else
found = FALSE;
- mylog("%s: A7=%d;A8=%d;A9=%d;B0=%d;B1=%d;B2=%d;B3=%d;B4=%d;B5=%d;B6=%d;B7=%d;B8=%d;B9=%d;C0=%d;C1=%d;C2=%s", func,
+ mylog("%s: A7=%d;A8=%d;A9=%d;B0=%d;B1=%d;B2=%d;B3=%d;B4=%d;B6=%d;B7=%d;B8=%d;B9=%d;C0=%d;C1=%d;C2=%s", func,
ci->drivers.fetch_max,
ci->drivers.socket_buffersize,
ci->drivers.unknown_sizes,
ci->drivers.debug,
ci->drivers.commlog,
ci->drivers.disable_optimizer,
- ci->drivers.ksqo,
ci->drivers.use_declarefetch,
ci->drivers.text_as_longvarchar,
ci->drivers.unknowns_as_longvarchar,
if (ci->onlyread[0] == '\0')
sprintf(ci->onlyread, "%d", globals.onlyread);
- if (ci->protocol[0] == '\0')
- strcpy(ci->protocol, globals.protocol);
-
if (ci->fake_oid_index[0] == '\0')
sprintf(ci->fake_oid_index, "%d", DEFAULT_FAKEOIDINDEX);
if (ci->show_system_tables[0] == '\0' || overwrite)
SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);
- if (ci->protocol[0] == '\0' || overwrite)
+ if (ci->rollback_on_error == -1 || overwrite)
{
+ char protocol[SMALL_REGISTRY_LEN];
char *ptr;
- SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
- if (ptr = strchr(ci->protocol, '-'), NULL != ptr)
+ SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", protocol, sizeof(protocol), ODBC_INI);
+ if (ptr = strchr(protocol, '-'), NULL != ptr)
{
*ptr = '\0';
if (overwrite || ci->rollback_on_error < 0)
ci->database,
ci->username,
NAME_IS_VALID(ci->password) ? "xxxxx" : "");
- qlog(" onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
+ qlog(" onlyread='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
ci->onlyread,
- ci->protocol,
ci->show_oid_column,
ci->fake_oid_index,
ci->show_system_tables);
if (!SQLWritePrivateProfileString(sectionName, INI_OPTIMIZER, tmp, fileName))
errc--;
- sprintf(tmp, "%d", comval->ksqo);
- if (!SQLWritePrivateProfileString(sectionName, INI_KSQO, tmp, fileName))
- errc--;
-
sprintf(tmp, "%d", comval->unique_index);
if (!SQLWritePrivateProfileString(sectionName, INI_UNIQUEINDEX, tmp, fileName))
errc--;
ODBC_INI);
if (ci->rollback_on_error >= 0)
- sprintf(temp, "%s-%d", ci->protocol, ci->rollback_on_error);
+ sprintf(temp, "7.4-%d", ci->rollback_on_error);
else
- strncpy_null(temp, ci->protocol, sizeof(temp));
+ strncpy_null(temp, "", sizeof(temp));
SQLWritePrivateProfileString(DSN,
INI_PROTOCOL,
temp,
else if (inst_position)
comval->disable_optimizer = DEFAULT_OPTIMIZER;
- /* KSQO is stored in the driver section only */
- SQLGetPrivateProfileString(section, INI_KSQO, "",
- temp, sizeof(temp), filename);
- if (temp[0])
- comval->ksqo = atoi(temp);
- else if (inst_position)
- comval->ksqo = DEFAULT_KSQO;
-
/* Recognize Unique Index is stored in the driver section only */
SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "",
temp, sizeof(temp), filename);
else if (inst_position)
comval->unique_index = DEFAULT_UNIQUEINDEX;
-
/* Unknown Sizes is stored in the driver section only */
SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "",
temp, sizeof(temp), filename);
#define INI_OPTIMIZER "Optimizer" /* Use backend genetic
* optimizer */
#define ABBR_OPTIMIZER "B4"
-#define INI_KSQO "Ksqo" /* Keyset query
- * optimization */
-#define ABBR_KSQO "B5"
+/* "Ksqo", abbreviated to B5 was used with pre-7.1 server versions for
+ * "keyset query optimization". No longer used.
+#define INI_KSQO "Ksqo"
+#define ABBR_KSQO "B5"
+*/
#define INI_CONNSETTINGS "ConnSettings" /* Anything to send to
* backend on successful
* connection */
#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 DEFAULT_UNKNOWNSASLONGVARCHAR 0
#define DEFAULT_BOOLSASCHAR 1
#define DEFAULT_OPTIMIZER 0 /* enable */
-#define DEFAULT_KSQO 1 /* on */
#define DEFAULT_UNIQUEINDEX 1 /* dont recognize */
#define DEFAULT_COMMLOG 0 /* dont log */
#define DEFAULT_DEBUG 0
{
defval.commlog = DEFAULT_COMMLOG;
defval.disable_optimizer = DEFAULT_OPTIMIZER;
- defval.ksqo = DEFAULT_KSQO;
defval.unique_index = DEFAULT_UNIQUEINDEX;
defval.onlyread = DEFAULT_READONLY;
defval.use_declarefetch = DEFAULT_USEDECLAREFETCH;
EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE);
#endif /* Q_LOG */
CheckDlgButton(hdlg, DRV_OPTIMIZER, comval->disable_optimizer);
- CheckDlgButton(hdlg, DRV_KSQO, comval->ksqo);
CheckDlgButton(hdlg, DRV_UNIQUEINDEX, comval->unique_index);
/* EnableWindow(GetDlgItem(hdlg, DRV_UNIQUEINDEX), enable); */
CheckDlgButton(hdlg, DRV_READONLY, comval->onlyread);
comval = &globals;
comval->commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
comval->disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
- comval->ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
comval->unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
if (!ci)
{
/* Readonly */
sprintf(ci->onlyread, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
- /* Protocol */
- if (IsDlgButtonChecked(hdlg, DS_PG62))
- strcpy(ci->protocol, PG62);
- else if (IsDlgButtonChecked(hdlg, DS_PG63))
- strcpy(ci->protocol, PG63);
- else if (IsDlgButtonChecked(hdlg, DS_PG64))
- strcpy(ci->protocol, PG64);
- else
- /* latest */
- strcpy(ci->protocol, PG74);
-
/* Issue rollback command on error */
if (IsDlgButtonChecked(hdlg, DS_NO_ROLLBACK))
ci->rollback_on_error = 0;
/* Protocol */
enable = (ci->sslmode[0] == SSLLBYTE_DISABLE || ci->username[0] == '\0');
- EnableWindow(GetDlgItem(hdlg, DS_PG62), enable);
- EnableWindow(GetDlgItem(hdlg, DS_PG63), enable);
- EnableWindow(GetDlgItem(hdlg, DS_PG64), enable);
- EnableWindow(GetDlgItem(hdlg, DS_PG74), enable);
- if (PROTOCOL_62(ci))
- CheckDlgButton(hdlg, DS_PG62, 1);
- else if (PROTOCOL_63(ci))
- CheckDlgButton(hdlg, DS_PG63, 1);
- else if (PROTOCOL_64(ci))
- CheckDlgButton(hdlg, DS_PG64, 1);
- else
- /* latest */
- CheckDlgButton(hdlg, DS_PG74, 1);
/* How to issue Rollback */
switch (ci->rollback_on_error)
conn = SC_get_conn(stmt);
ci = &(conn->connInfo);
- if (!ci->use_server_side_prepare ||
- PG_VERSION_LT(conn, 7.3))
+ if (!ci->use_server_side_prepare)
{
/* Do prepare operations by the driver itself */
return PREPARE_BY_THE_DRIVER;
}
if (stmt->multi_statement < 0)
PGAPI_NumParams((StatementClass *) stmt, &num_params);
- if (stmt->multi_statement > 0) /* would divide the query into multiple commands and apply V3 parse requests for each of them */
- ret = PROTOCOL_74(ci) ? PARSE_REQ_FOR_INFO : PREPARE_BY_THE_DRIVER;
- else if (PROTOCOL_74(ci))
+ if (stmt->multi_statement > 0)
+ {
+ /*
+ * divide the query into multiple commands and apply V3 parse
+ * requests for each of them
+ */
+ ret = PARSE_REQ_FOR_INFO;
+ }
+ else
{
if (SC_may_use_cursor(stmt))
{
else
ret = PARSE_TO_EXEC_ONCE;
}
- else
- {
- if (SC_may_use_cursor(stmt) &&
- (SQL_CURSOR_FORWARD_ONLY != stmt->options.cursor_type ||
- ci->drivers.use_declarefetch))
- ret = PREPARE_BY_THE_DRIVER;
- else if (SC_is_prepare_statement(stmt))
- ret = USING_PREPARE_COMMAND;
- else
- ret = PREPARE_BY_THE_DRIVER;
- }
}
if (SC_is_prepare_statement(stmt) && (PARSE_TO_EXEC_ONCE == ret))
ret = NAMED_PARSE_REQUEST;
{
switch (how_to_prepare)
{
- case USING_PREPARE_COMMAND:
- return checkOnly ? doNothing : usingCommand;
case NAMED_PARSE_REQUEST:
return shouldParse;
case PARSE_TO_EXEC_ONCE:
return doNothing;
}
}
- if (PG_VERSION_LE(conn, 7.3) ||
- !PROTOCOL_74(ci))
- return nCallParse;
if (num_params > 0)
{
res = kres;
}
}
-#ifdef NOT_USED
- else if (SC_is_concat_prepare_exec(stmt))
- {
- if (res && QR_command_maybe_successful(res))
- {
- QResultClass *kres;
-
- kres = res->next;
-inolog("res->next=%p\n", kres);
- res->next = NULL;
- SC_set_Result(stmt, kres);
- res = kres;
- SC_set_prepared(stmt, PREPARED_PERMANENTLY);
- }
- else
- {
- retval = SQL_ERROR;
- if (stmt->execute_statement)
- free(stmt->execute_statement);
- stmt->execute_statement = NULL;
- }
- }
-#endif /* NOT_USED */
#if (ODBCVER >= 0x0300)
ipdopts = SC_get_IPDF(stmt);
if (ipdopts->param_status_ptr)
case SQL_ALTER_TABLE: /* ODBC 2.0 */
len = 4;
value = SQL_AT_ADD_COLUMN;
- if (PG_VERSION_GE(conn, 7.3))
- value |= SQL_AT_DROP_COLUMN;
+ value |= SQL_AT_DROP_COLUMN;
#if (ODBCVER >= 0x0300)
- value |= SQL_AT_ADD_COLUMN_SINGLE;
- if (PG_VERSION_GE(conn, 7.1))
- value |= SQL_AT_ADD_CONSTRAINT
+ value |= SQL_AT_ADD_COLUMN_SINGLE
+ | SQL_AT_ADD_CONSTRAINT
| SQL_AT_ADD_TABLE_CONSTRAINT
| SQL_AT_CONSTRAINT_INITIALLY_DEFERRED
| SQL_AT_CONSTRAINT_INITIALLY_IMMEDIATE
- | SQL_AT_CONSTRAINT_DEFERRABLE;
- if (PG_VERSION_GE(conn, 7.3))
- value |= SQL_AT_DROP_TABLE_CONSTRAINT_RESTRICT
+ | SQL_AT_CONSTRAINT_DEFERRABLE
+ | SQL_AT_DROP_TABLE_CONSTRAINT_RESTRICT
| SQL_AT_DROP_TABLE_CONSTRAINT_CASCADE
| SQL_AT_DROP_COLUMN_RESTRICT
| SQL_AT_DROP_COLUMN_CASCADE;
case SQL_BOOKMARK_PERSISTENCE: /* ODBC 2.0 */
/* very simple bookmark support */
len = 4;
- value = ci->drivers.use_declarefetch && PG_VERSION_LT(conn, 7.4) ? 0 : (SQL_BP_SCROLL | SQL_BP_DELETE | SQL_BP_UPDATE | SQL_BP_TRANSACTION);
+ value = SQL_BP_SCROLL | SQL_BP_DELETE | SQL_BP_UPDATE | SQL_BP_TRANSACTION;
break;
case SQL_COLUMN_ALIAS: /* ODBC 2.0 */
case SQL_CURSOR_COMMIT_BEHAVIOR: /* ODBC 1.0 */
len = 2;
- value = SQL_CB_CLOSE;
- if (!ci->drivers.use_declarefetch || PG_VERSION_GE(conn, 7.4))
- value = SQL_CB_PRESERVE;
+ value = SQL_CB_PRESERVE;
break;
case SQL_CURSOR_ROLLBACK_BEHAVIOR: /* ODBC 1.0 */
len = 2;
- value = SQL_CB_CLOSE;
if (!ci->drivers.use_declarefetch)
value = SQL_CB_PRESERVE;
+ else
+ value = SQL_CB_CLOSE;
break;
case SQL_DATA_SOURCE_NAME: /* ODBC 1.0 */
case SQL_DEFAULT_TXN_ISOLATION: /* ODBC 1.0 */
len = 4;
- if (PG_VERSION_LT(conn, 6.5))
- value = SQL_TXN_SERIALIZABLE;
- else
- value = SQL_TXN_READ_COMMITTED;
+ value = SQL_TXN_READ_COMMITTED;
break;
case SQL_DRIVER_NAME: /* ODBC 1.0 */
break;
case SQL_EXPRESSIONS_IN_ORDERBY: /* ODBC 1.0 */
- p = PG_VERSION_GE(conn, 6.5) ? "Y" : "N";
+ p = "Y";
break;
case SQL_FETCH_DIRECTION: /* ODBC 1.0 */
case SQL_IDENTIFIER_QUOTE_CHAR: /* ODBC 1.0 */
/* the character used to quote "identifiers" */
- p = PG_VERSION_LE(conn, 6.2) ? " " : "\"";
+ p = "\"";
break;
case SQL_KEYWORDS: /* ODBC 2.0 */
case SQL_MAX_COLUMN_NAME_LEN: /* ODBC 1.0 */
len = 2;
- if (PG_VERSION_GT(conn, 7.4))
- value = CC_get_max_idlen(conn);
-#ifdef MAX_COLUMN_LEN
- else
- value = MAX_COLUMN_LEN;
-#endif /* MAX_COLUMN_LEN */
+ value = CC_get_max_idlen(conn);
if (0 == value)
- {
- if (PG_VERSION_GE(conn, 7.3))
- value = NAMEDATALEN_V73;
- else
- value = NAMEDATALEN_V72;
- }
+ value = NAMEDATALEN_V73;
break;
case SQL_MAX_COLUMNS_IN_GROUP_BY: /* ODBC 2.0 */
if (PG_VERSION_GT(conn, 7.4))
value = CC_get_max_idlen(conn);
#ifdef MAX_SCHEMA_LEN
- else if (conn->schema_support)
+ else
value = MAX_SCHEMA_LEN;
#endif /* MAX_SCHEMA_LEN */
if (0 == value)
- {
- if (PG_VERSION_GE(conn, 7.3))
- value = NAMEDATALEN_V73;
- }
+ value = NAMEDATALEN_V73;
break;
case SQL_MAX_PROCEDURE_NAME_LEN: /* ODBC 1.0 */
case SQL_MAX_ROW_SIZE: /* ODBC 2.0 */
len = 4;
- if (PG_VERSION_GE(conn, 7.1))
- {
- /* No limit with tuptoaster in 7.1+ */
- value = 0;
- }
- else
- {
- /* Without the Toaster we're limited to the blocksize */
- value = BLCKSZ;
- }
+ /* No limit with tuptoaster in 7.1+ */
+ value = 0;
break;
case SQL_MAX_ROW_SIZE_INCLUDES_LONG: /* ODBC 2.0 */
break;
case SQL_MAX_STATEMENT_LEN: /* ODBC 2.0 */
- /* maybe this should be 0? */
len = 4;
- value = CC_get_max_query_len(conn);
+ value = 0;
break;
case SQL_MAX_TABLE_NAME_LEN: /* ODBC 1.0 */
value = MAX_TABLE_LEN;
#endif /* MAX_TABLE_LEN */
if (0 == value)
- {
- if (PG_VERSION_GE(conn, 7.3))
- value = NAMEDATALEN_V73;
- else
- value = NAMEDATALEN_V72;
- }
+ value = NAMEDATALEN_V73;
break;
case SQL_MAX_TABLES_IN_SELECT: /* ODBC 2.0 */
case SQL_NULL_COLLATION: /* ODBC 2.0 */
/* where are nulls sorted? */
len = 2;
- if (PG_VERSION_GE(conn, 7.2))
- value = SQL_NC_HIGH;
- else
- value = SQL_NC_END;
+ value = SQL_NC_HIGH;
break;
case SQL_NUMERIC_FUNCTIONS: /* ODBC 1.0 */
case SQL_OJ_CAPABILITIES: /* ODBC 2.01 */
len = 4;
- if (PG_VERSION_GE(conn, 7.1))
- {
- /* OJs in 7.1+ */
- value = (SQL_OJ_LEFT |
- SQL_OJ_RIGHT |
- SQL_OJ_FULL |
- SQL_OJ_NESTED |
- SQL_OJ_NOT_ORDERED |
- SQL_OJ_INNER |
- SQL_OJ_ALL_COMPARISON_OPS);
- }
- else
- /* OJs not in <7.1 */
- value = 0;
+ value = (SQL_OJ_LEFT |
+ SQL_OJ_RIGHT |
+ SQL_OJ_FULL |
+ SQL_OJ_NESTED |
+ SQL_OJ_NOT_ORDERED |
+ SQL_OJ_INNER |
+ SQL_OJ_ALL_COMPARISON_OPS);
break;
case SQL_ORDER_BY_COLUMNS_IN_SELECT: /* ODBC 2.0 */
- p = (PG_VERSION_LE(conn, 6.3)) ? "Y" : "N";
+ p = "Y";
break;
case SQL_OUTER_JOINS: /* ODBC 1.0 */
- if (PG_VERSION_GE(conn, 7.1))
- /* OJs in 7.1+ */
- p = "Y";
- else
- /* OJs not in <7.1 */
- p = "N";
+ p = "Y";
break;
case SQL_OWNER_TERM: /* ODBC 1.0 */
- if (conn->schema_support)
- p = "schema";
- else
- p = "owner";
+ p = "schema";
break;
case SQL_OWNER_USAGE: /* ODBC 2.0 */
len = 4;
- value = 0;
- if (conn->schema_support)
- value = SQL_OU_DML_STATEMENTS
+ value = SQL_OU_DML_STATEMENTS
| SQL_OU_TABLE_DEFINITION
| SQL_OU_INDEX_DEFINITION
- | SQL_OU_PRIVILEGE_DEFINITION
- ;
+ | SQL_OU_PRIVILEGE_DEFINITION;
break;
case SQL_POS_OPERATIONS: /* ODBC 2.0 */
break;
case SQL_SEARCH_PATTERN_ESCAPE: /* ODBC 1.0 */
- if (PG_VERSION_GE(conn, 6.5))
- p = "\\";
- else
- p = NULL_STRING;
+ p = "\\";
break;
case SQL_SERVER_NAME: /* ODBC 1.0 */
case SQL_TXN_ISOLATION_OPTION: /* ODBC 1.0 */
len = 4;
- if (PG_VERSION_LT(conn, 6.5))
- value = SQL_TXN_SERIALIZABLE;
- else if (PG_VERSION_GE(conn, 7.1))
- value = SQL_TXN_READ_COMMITTED | SQL_TXN_SERIALIZABLE;
- else
- value = SQL_TXN_READ_COMMITTED;
+ value = SQL_TXN_READ_COMMITTED | SQL_TXN_SERIALIZABLE;
break;
case SQL_UNION: /* ODBC 2.0 */
if (SQL_INTEGER == sqlType)
{
mylog("sqlType=%d ms_jet=%d\n", sqlType, conn->ms_jet);
- if (conn->ms_jet && PG_VERSION_GE(conn, 6.4))
+ if (conn->ms_jet)
{
aunq_match = 1;
pgtcount = 2;
/* ODBC level 2 functions */
pfExists[SQL_API_SQLBROWSECONNECT] = FALSE;
- if (PG_VERSION_GE(conn, 7.4))
- pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE;
- else
- pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE;
+ pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE;
pfExists[SQL_API_SQLDATASOURCES] = FALSE; /* only implemented by
* DM */
if (SUPPORT_DESCRIBE_PARAM(ci))
pfExists[SQL_API_SQLNUMPARAMS] = TRUE;
pfExists[SQL_API_SQLPARAMOPTIONS] = TRUE;
pfExists[SQL_API_SQLPRIMARYKEYS] = TRUE;
- if (PG_VERSION_LT(conn, 6.5))
- pfExists[SQL_API_SQLPROCEDURECOLUMNS] = FALSE;
- else
- pfExists[SQL_API_SQLPROCEDURECOLUMNS] = TRUE;
- if (PG_VERSION_LT(conn, 6.5))
- pfExists[SQL_API_SQLPROCEDURES] = FALSE;
- else
- pfExists[SQL_API_SQLPROCEDURES] = TRUE;
+ pfExists[SQL_API_SQLPROCEDURECOLUMNS] = TRUE;
+ pfExists[SQL_API_SQLPROCEDURES] = TRUE;
pfExists[SQL_API_SQLSETPOS] = TRUE;
pfExists[SQL_API_SQLSETSCROLLOPTIONS] = TRUE; /* odbc 1.0 */
pfExists[SQL_API_SQLTABLEPRIVILEGES] = TRUE;
*pfExists = TRUE;
break;
case SQL_API_SQLPROCEDURECOLUMNS:
- if (PG_VERSION_LT(conn, 6.5))
- *pfExists = FALSE;
- else
- *pfExists = TRUE;
+ *pfExists = TRUE;
break;
case SQL_API_SQLPROCEDURES:
- if (PG_VERSION_LT(conn, 6.5))
- *pfExists = FALSE;
- else
- *pfExists = TRUE;
+ *pfExists = TRUE;
break;
case SQL_API_SQLSETPOS:
*pfExists = TRUE;
strncpy_null(tables_query, "select NULL, NULL, relkind from (select 'r' as relkind union select 'v') as a", sizeof(tables_query));
else if (list_schemas)
{
- if (conn->schema_support)
- strncpy_null(tables_query, "select NULL, nspname, NULL"
+ strncpy_null(tables_query, "select NULL, nspname, NULL"
" from pg_catalog.pg_namespace n where true", sizeof(tables_query));
- else
- strncpy_null(tables_query, "select NULL, NULL as nspname, NULL", sizeof(tables_query));
}
- else if (conn->schema_support)
+ else
{
/* view is represented by its relkind since 7.1 */
strcpy(tables_query, "select relname, nspname, relkind"
" from pg_catalog.pg_class c, pg_catalog.pg_namespace n");
strcat(tables_query, " where relkind in ('r', 'v')");
}
- else if (PG_VERSION_GE(conn, 7.1))
- {
- /* view is represented by its relkind since 7.1 */
- strcpy(tables_query, "select relname, usename, relkind"
- " from pg_class c, pg_user u");
- strcat(tables_query, " where relkind in ('r', 'v')");
- }
- else
- {
- strcpy(tables_query, "select relname, usename, relhasrules from pg_class c, pg_user u");
- strcat(tables_query, " where relkind = 'r'");
- }
op_string = gen_opestr(like_or_eq, conn);
if (!list_some)
{
- if (conn->schema_support)
- {
- schema_strcat1(tables_query, " and nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
- /* strcat(tables_query, " and pg_catalog.pg_table_is_visible(c.oid)"); */
- }
- else
- {
- if (IS_VALID_NAME(escSchemaName))
- snprintf_add(tables_query, sizeof(tables_query),
- " and usename %s'%s'", op_string, escSchemaName);
- }
+ schema_strcat1(tables_query, " and nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
if (IS_VALID_NAME(escTableName))
snprintf_add(tables_query, sizeof(tables_query),
" and relname %s'%s'", op_string, escTableName);
* tables, then dont filter either.
*/
if ((list_schemas || !list_some) && !atoi(ci->show_system_tables) && !show_system_tables)
- {
- if (conn->schema_support)
- strcat(tables_query, " and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')");
- else if (!list_schemas)
- {
- strcat(tables_query, " and relname !~ '^" POSTGRES_SYS_PREFIX);
-
- /* Also filter out user-defined system table types */
- for (i = 0; i < nprefixes; i++)
- {
- strcat(tables_query, "|^");
- strcat(tables_query, prefix[i]);
- }
- strcat(tables_query, "'");
- }
- }
+ strcat(tables_query, " and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')");
if (!list_some)
{
strcat(tables_query, " order by nspname");
else if (list_some)
;
- else if (conn->schema_support)
- strcat(tables_query, " and n.oid = relnamespace order by nspname, relname");
else
- {
- /* match users */
- if (PG_VERSION_LT(conn, 7.1))
- /* filter out large objects in older versions */
- strcat(tables_query, " and relname !~ '^xinv[0-9]+'");
- strcat(tables_query, " and usesysid = relowner order by relname");
- }
+ strcat(tables_query, " and n.oid = relnamespace order by nspname, relname");
result = PGAPI_ExecDirect(htbl_stmt, (SQLCHAR *) tables_query, SQL_NTS, 0);
if (!SQL_SUCCEEDED(result))
}
/* If not found */
- if (conn->schema_support &&
- (res = SC_get_Result(tbl_stmt)) &&
+ if ((res = SC_get_Result(tbl_stmt)) &&
0 == QR_get_num_total_tuples(res))
{
if (allow_public_schema(conn, szSchemaName, cbSchemaName))
systable = FALSE;
if (!atoi(ci->show_system_tables))
{
- if (conn->schema_support)
- {
- if (stricmp(table_owner, "pg_catalog") == 0 ||
- stricmp(table_owner, "pg_toast") == 0 ||
- strnicmp(table_owner, "pg_temp_", 8) == 0 ||
- stricmp(table_owner, "information_schema") == 0)
- systable = TRUE;
- }
- else if (strncmp(table_name, POSTGRES_SYS_PREFIX, strlen(POSTGRES_SYS_PREFIX)) == 0)
+ if (stricmp(table_owner, "pg_catalog") == 0 ||
+ stricmp(table_owner, "pg_toast") == 0 ||
+ strnicmp(table_owner, "pg_temp_", 8) == 0 ||
+ stricmp(table_owner, "information_schema") == 0)
systable = TRUE;
-
else
{
/* Check extra system table prefixes */
}
/* Determine if the table name is a view */
- if (PG_VERSION_GE(conn, 7.1))
- /* view is represented by its relkind since 7.1 */
- view = (relkind_or_hasrules[0] == 'v');
- else
- view = (relkind_or_hasrules[0] == '1');
+ view = (relkind_or_hasrules[0] == 'v');
/* It must be a regular table */
regular_table = (!systable && !view);
-
/* Include the row in the result set if meets all criteria */
/*
mylog("%s: table_name = '%s'\n", func, table_name);
- if (list_schemas || (conn->schema_support && !list_some))
+ if (list_schemas || !list_some)
set_tuplefield_string(&tuple[TABLES_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
else
set_tuplefield_null(&tuple[TABLES_SCHEMA_NAME]);
* have the atttypmod field)
*/
op_string = gen_opestr(like_or_eq, conn);
- if (conn->schema_support)
- {
- snprintf(columns_query, sizeof(columns_query),
- "select n.nspname, c.relname, a.attname, a.atttypid"
- ", t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull"
- ", c.relhasrules, c.relkind, c.oid, %s, %s, %s"
- " from (((pg_catalog.pg_class c"
- " inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace",
- PG_VERSION_GE(conn, 7.4) ?
- "pg_get_expr(d.adbin, d.adrelid)" : "d.adsrc",
- PG_VERSION_GE(conn, 7.4) ?
- "case t.typtype when 'd' then t.typbasetype else 0 end, t.typtypmod"
- : "0, -1",
- PG_VERSION_GE(conn, 7.2) ? "c.relhasoids" : "1"
- );
- if (search_by_ids)
- snprintf_add(columns_query, sizeof(columns_query), " and c.oid = %u", reloid);
- else
- {
- if (escTableName)
- snprintf_add(columns_query, sizeof(columns_query), " and c.relname %s'%s'", op_string, escTableName);
- schema_strcat1(columns_query, " and n.nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
- }
- strcat(columns_query, ") inner join pg_catalog.pg_attribute a"
- " on (not a.attisdropped)");
- if (0 == attnum && (NULL == escColumnName || like_or_eq != eqop))
- strcat(columns_query, " and a.attnum > 0");
- if (search_by_ids)
- {
- if (attnum != 0)
- snprintf_add(columns_query, sizeof(columns_query), " and a.attnum = %d", attnum);
- }
- else if (escColumnName)
- snprintf_add(columns_query, sizeof(columns_query), " and a.attname %s'%s'", op_string, escColumnName);
- strcat(columns_query,
- " and a.attrelid = c.oid) inner join pg_catalog.pg_type t"
- " on t.oid = a.atttypid) left outer join pg_attrdef d"
- " on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum");
- strcat(columns_query, " order by n.nspname, c.relname, attnum");
- }
+ snprintf(columns_query, sizeof(columns_query),
+ "select n.nspname, c.relname, a.attname, a.atttypid, "
+ "t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, "
+ "c.relhasrules, c.relkind, c.oid, pg_get_expr(d.adbin, d.adrelid), "
+ "case t.typtype when 'd' then t.typbasetype else 0 end, t.typtypmod, "
+ "c.relhasoids "
+ "from (((pg_catalog.pg_class c "
+ "inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace");
+ if (search_by_ids)
+ snprintf_add(columns_query, sizeof(columns_query), " and c.oid = %u", reloid);
else
{
- snprintf(columns_query, sizeof(columns_query),
- "select u.usename, c.relname, a.attname, a.atttypid"
- ", t.typname, a.attnum, a.attlen, %s, a.attnotnull"
- ", c.relhasrules, c.relkind, c.oid, NULL, 0, -1 from"
- " pg_user u, pg_class c, pg_attribute a, pg_type t where"
- " u.usesysid = c.relowner and c.oid= a.attrelid"
- " and a.atttypid = t.oid and (a.attnum > 0)",
- PG_VERSION_LE(conn, 6.2) ? "a.attlen" : "a.atttypmod");
if (escTableName)
- snprintf_add(columns_query, sizeof(columns_query),
- " and c.relname %s'%s'", op_string, escTableName);
- if (IS_VALID_NAME(escSchemaName))
- snprintf_add(columns_query, sizeof(columns_query),
- " and u.usename %s'%s'", op_string, escSchemaName);
- if (escColumnName)
- snprintf_add(columns_query, sizeof(columns_query),
- " and a.attname %s'%s'", op_string, escColumnName);
- strcat(columns_query, " order by c.relname, attnum");
+ snprintf_add(columns_query, sizeof(columns_query), " and c.relname %s'%s'", op_string, escTableName);
+ schema_strcat1(columns_query, " and n.nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
}
+ strcat(columns_query, ") inner join pg_catalog.pg_attribute a"
+ " on (not a.attisdropped)");
+ if (0 == attnum && (NULL == escColumnName || like_or_eq != eqop))
+ strcat(columns_query, " and a.attnum > 0");
+ if (search_by_ids)
+ {
+ if (attnum != 0)
+ snprintf_add(columns_query, sizeof(columns_query), " and a.attnum = %d", attnum);
+ }
+ else if (escColumnName)
+ snprintf_add(columns_query, sizeof(columns_query), " and a.attname %s'%s'", op_string, escColumnName);
+ strcat(columns_query,
+ " and a.attrelid = c.oid) inner join pg_catalog.pg_type t"
+ " on t.oid = a.atttypid) left outer join pg_attrdef d"
+ " on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum");
+ strcat(columns_query, " order by n.nspname, c.relname, attnum");
result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
if (!SQL_SUCCEEDED(result))
}
/* If not found */
- if (conn->schema_support &&
- (flag & PODBC_SEARCH_PUBLIC_SCHEMA) != 0 &&
+ if ((flag & PODBC_SEARCH_PUBLIC_SCHEMA) != 0 &&
(res = SC_get_Result(col_stmt)) &&
0 == QR_get_num_total_tuples(res))
{
* being called by SQLStatistics . Always show OID if it's a system
* table
*/
+ relisaview = (relkind[0] == 'v');
- if (PG_VERSION_GE(conn, 7.1))
- relisaview = (relkind[0] == 'v');
- else
- relisaview = (relhasrules[0] == '1');
if (result != SQL_ERROR && !stmt->internal)
{
if (!relisaview &&
tuple = QR_AddNew(res);
set_tuplefield_string(&tuple[COLUMNS_CATALOG_NAME], CurrCat(conn));
/* see note in SQLTables() */
- if (conn->schema_support)
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
- else
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], NULL_STRING);
+ set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
set_tuplefield_string(&tuple[COLUMNS_TABLE_NAME], table_name);
set_tuplefield_string(&tuple[COLUMNS_COLUMN_NAME], OID_NAME);
sqltype = pgtype_to_concise_type(stmt, the_type, PG_STATIC);
sqltype = SQL_TYPE_NULL; /* unspecified */
set_tuplefield_string(&tuple[COLUMNS_CATALOG_NAME], CurrCat(conn));
/* see note in SQLTables() */
- if (conn->schema_support)
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
- else
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], NULL_STRING);
+ set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
set_tuplefield_string(&tuple[COLUMNS_TABLE_NAME], table_name);
set_tuplefield_string(&tuple[COLUMNS_COLUMN_NAME], field_name);
auto_unique = SQL_FALSE;
else if ((field_type == PG_TYPE_DATETIME) ||
(field_type == PG_TYPE_TIMESTAMP_NO_TMZONE))
{
- if (PG_VERSION_GE(conn, 7.2))
- {
- useStaticScale = FALSE;
-
- set_nullfield_int2(&tuple[COLUMNS_SCALE], (Int2) mod_length);
- }
+ useStaticScale = FALSE;
+ set_nullfield_int2(&tuple[COLUMNS_SCALE], (Int2) mod_length);
}
if ((field_type == PG_TYPE_VARCHAR) ||
tuple = QR_AddNew(res);
set_tuplefield_string(&tuple[COLUMNS_CATALOG_NAME], CurrCat(conn));
- if (conn->schema_support)
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
- else
- set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], NULL_STRING);
+ set_tuplefield_string(&tuple[COLUMNS_SCHEMA_NAME], GET_SCHEMA_NAME(table_owner));
set_tuplefield_string(&tuple[COLUMNS_TABLE_NAME], table_name);
set_tuplefield_string(&tuple[COLUMNS_COLUMN_NAME], "xmin");
sqltype = pgtype_to_concise_type(stmt, the_type, PG_STATIC);
/*
* Create the query to find out if this is a view or not...
*/
- strcpy(columns_query, "select c.relhasrules, c.relkind");
- if (PG_VERSION_GE(conn, 7.2))
- strcat(columns_query, ", c.relhasoids");
- if (conn->schema_support)
- strcat(columns_query, " from pg_catalog.pg_namespace u,"
- " pg_catalog.pg_class c where "
- "u.oid = c.relnamespace");
- else
- strcat(columns_query, " from pg_user u, pg_class c where "
- "u.usesysid = c.relowner");
+ strcpy(columns_query, "select c.relhasrules, c.relkind, c.relhasoids");
+ strcat(columns_query, " from pg_catalog.pg_namespace u,"
+ " pg_catalog.pg_class c where "
+ "u.oid = c.relnamespace");
/* TableName cannot contain a string search pattern */
- /* my_strcat(columns_query, " and c.relname = '%.*s'", szTableName, cbTableName); */
if (escTableName)
snprintf_add(columns_query, sizeof(columns_query),
" and c.relname %s'%s'", eq_string, escTableName);
/* SchemaName cannot contain a string search pattern */
- if (conn->schema_support)
- schema_strcat1(columns_query, " and u.nspname %s'%.*s'", eq_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
- else
- {
- if (IS_VALID_NAME(escSchemaName))
- snprintf_add(columns_query, sizeof(columns_query),
- " and u.usename %s'%s'", eq_string, escSchemaName);
- }
-
+ schema_strcat1(columns_query, " and u.nspname %s'%.*s'", eq_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
if (!SQL_SUCCEEDED(result))
}
/* If not found */
- if (conn->schema_support &&
- (res = SC_get_Result(col_stmt)) &&
+ if ((res = SC_get_Result(col_stmt)) &&
0 == QR_get_num_total_tuples(res))
{
if (allow_public_schema(conn, szSchemaName, cbSchemaName))
goto cleanup;
}
relhasoids[0] = '1';
- if (PG_VERSION_GE(conn, 7.2))
+ result = PGAPI_BindCol(hcol_stmt, 3, internal_asis_type,
+ relhasoids, sizeof(relhasoids), NULL);
+ if (!SQL_SUCCEEDED(result))
{
- result = PGAPI_BindCol(hcol_stmt, 3, internal_asis_type,
- relhasoids, sizeof(relhasoids), NULL);
- if (!SQL_SUCCEEDED(result))
- {
- SC_error_copy(stmt, col_stmt, TRUE);
- result = SQL_ERROR;
- goto cleanup;
- }
+ SC_error_copy(stmt, col_stmt, TRUE);
+ result = SQL_ERROR;
+ goto cleanup;
}
result = PGAPI_Fetch(hcol_stmt);
- if (PG_VERSION_GE(conn, 7.1))
- relisaview = (relkind[0] == 'v');
- else
- relisaview = (relhasrules[0] == '1');
+ relisaview = (relkind[0] == 'v');
PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
hcol_stmt = NULL;
cbSchemaName = cbTableOwner;
table_schemaname[0] = '\0';
- if (conn->schema_support)
- schema_strcat(table_schemaname, "%.*s", szSchemaName, cbSchemaName, szTableName, cbTableName, conn);
+ schema_strcat(table_schemaname, "%.*s", szSchemaName, cbSchemaName, szTableName, cbTableName, conn);
/*
* we need to get a list of the field names first, so we can return
/* TableName cannot contain a string search pattern */
escTableName = simpleCatalogEscape((SQLCHAR *) table_name, SQL_NTS, NULL, conn);
eq_string = gen_opestr(eqop, conn);
- if (conn->schema_support)
- {
- escSchemaName = simpleCatalogEscape((SQLCHAR *) table_schemaname, SQL_NTS, NULL, conn);
- snprintf(index_query, sizeof(index_query), "select c.relname, i.indkey, i.indisunique"
- ", i.indisclustered, a.amname, c.relhasrules, n.nspname"
- ", c.oid, %s, %s"
- " from pg_catalog.pg_index i, pg_catalog.pg_class c,"
- " pg_catalog.pg_class d, pg_catalog.pg_am a,"
- " pg_catalog.pg_namespace n"
- " where d.relname %s'%s'"
- " and n.nspname %s'%s'"
- " and n.oid = d.relnamespace"
- " and d.oid = i.indrelid"
- " and i.indexrelid = c.oid"
- " and c.relam = a.oid order by"
- , PG_VERSION_GE(conn, 7.2) ? "d.relhasoids" : "1"
- , PG_VERSION_GE(conn, 8.3) ? "i.indoption" : "0"
- , eq_string, escTableName, eq_string, escSchemaName);
- }
- else
- snprintf(index_query, sizeof(index_query), "select c.relname, i.indkey, i.indisunique"
- ", i.indisclustered, a.amname, c.relhasrules, c.oid, %s, 0"
- " from pg_index i, pg_class c, pg_class d, pg_am a"
- " where d.relname %s'%s'"
- " and d.oid = i.indrelid"
- " and i.indexrelid = c.oid"
- " and c.relam = a.oid order by"
- , PG_VERSION_GE(conn, 7.2) ? "d.relhasoids" : "1"
- , eq_string, escTableName);
- if (PG_VERSION_GT(SC_get_conn(stmt), 6.4))
- strcat(index_query, " i.indisprimary desc,");
- if (conn->schema_support)
- strcat(index_query, " i.indisunique, n.nspname, c.relname");
- else
- strcat(index_query, " i.indisunique, c.relname");
+ escSchemaName = simpleCatalogEscape((SQLCHAR *) table_schemaname, SQL_NTS, NULL, conn);
+ snprintf(index_query, sizeof(index_query), "select c.relname, i.indkey, i.indisunique"
+ ", i.indisclustered, a.amname, c.relhasrules, n.nspname"
+ ", c.oid, d.relhasoids, %s"
+ " from pg_catalog.pg_index i, pg_catalog.pg_class c,"
+ " pg_catalog.pg_class d, pg_catalog.pg_am a,"
+ " pg_catalog.pg_namespace n"
+ " where d.relname %s'%s'"
+ " and n.nspname %s'%s'"
+ " and n.oid = d.relnamespace"
+ " and d.oid = i.indrelid"
+ " and i.indexrelid = c.oid"
+ " and c.relam = a.oid order by"
+ , PG_VERSION_GE(conn, 8.3) ? "i.indoption" : "0"
+ , eq_string, escTableName, eq_string, escSchemaName);
+ strcat(index_query, " i.indisprimary desc,");
+ strcat(index_query, " i.indisunique, n.nspname, c.relname");
result = PGAPI_ExecDirect(hindx_stmt, (SQLCHAR *) index_query, SQL_NTS, 0);
if (!SQL_SUCCEEDED(result))
if (result = SC_initialize_and_recycle(stmt), SQL_SUCCESS != result)
return result;
- if (PG_VERSION_LT(conn, 7.4))
- SC_set_error(stmt, STMT_NOT_IMPLEMENTED_ERROR, "Function not implementedyet", func);
escSchemaName = simpleCatalogEscape(szTableOwner, cbTableOwner, NULL, conn);
escTableName = simpleCatalogEscape(szTableName, cbTableName, NULL, conn);
search_pattern = (0 == (flag & PODBC_NOT_SEARCH_PATTERN));
if (escSchemaName)
free(escSchemaName);
escSchemaName = simpleCatalogEscape(szSchemaName, cbSchemaName, NULL, conn);
- if (conn->schema_support)
- schema_strcat(pkscm, "%.*s", (SQLCHAR *) escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
+ schema_strcat(pkscm, "%.*s", (SQLCHAR *) escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
}
result = PGAPI_BindCol(htbl_stmt, 1, internal_asis_type,
goto cleanup;
}
- if (PG_VERSION_LE(conn, 6.4))
- qstart = 2;
- else
- qstart = 1;
+ qstart = 1;
if (0 == reloid)
qend = 2;
else
* possible index columns. Courtesy of Tom Lane - thomas
* 2000-03-21
*/
- if (conn->schema_support)
- {
- strncpy_null(tables_query,
- "select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname"
- " from pg_catalog.pg_attribute ta,"
- " pg_catalog.pg_attribute ia, pg_catalog.pg_class tc,"
- " pg_catalog.pg_index i, pg_catalog.pg_namespace n"
- ", pg_catalog.pg_class ic"
- , sizeof(tables_query));
- qsize = strlen(tables_query);
- tsize = sizeof(tables_query) - qsize;
- tbqry = tables_query + qsize;
- if (0 == reloid)
- snprintf(tbqry, tsize,
- " where tc.relname %s'%s'"
- " AND n.nspname %s'%s'"
- , eq_string, escTableName, eq_string, pkscm);
- else
- snprintf(tbqry, tsize,
- " where tc.oid = " FORMAT_UINT4
- , reloid);
-
- strlcat(tables_query,
- " AND tc.oid = i.indrelid"
- " AND n.oid = tc.relnamespace"
- " AND i.indisprimary = 't'"
- " AND ia.attrelid = i.indexrelid"
- " AND ta.attrelid = i.indrelid"
- " AND ta.attnum = i.indkey[ia.attnum-1]"
- " AND (NOT ta.attisdropped)"
- " AND (NOT ia.attisdropped)"
- " AND ic.oid = i.indexrelid"
- " order by ia.attnum"
- , sizeof(tables_query));
- }
+ strncpy_null(tables_query,
+ "select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname"
+ " from pg_catalog.pg_attribute ta,"
+ " pg_catalog.pg_attribute ia, pg_catalog.pg_class tc,"
+ " pg_catalog.pg_index i, pg_catalog.pg_namespace n"
+ ", pg_catalog.pg_class ic"
+ , sizeof(tables_query));
+ qsize = strlen(tables_query);
+ tsize = sizeof(tables_query) - qsize;
+ tbqry = tables_query + qsize;
+ if (0 == reloid)
+ snprintf(tbqry, tsize,
+ " where tc.relname %s'%s'"
+ " AND n.nspname %s'%s'"
+ , eq_string, escTableName, eq_string, pkscm);
else
- {
- strncpy_null(tables_query,
- "select ta.attname, ia.attnum, ic.relname, NULL, tc.relname"
- " from pg_attribute ta, pg_attribute ia, pg_class tc, pg_index i, pg_class ic"
- , sizeof(tables_query));
- qsize = strlen(tables_query);
- tsize = sizeof(tables_query) - qsize;
- tbqry = tables_query + qsize;
- if (0 == reloid)
- snprintf(tbqry, tsize,
- " where tc.relname %s'%s'"
- , eq_string, escTableName);
- else
- snprintf(tbqry, tsize,
- " where tc.oid = " FORMAT_UINT4, reloid);
-
- strlcat(tables_query,
- " AND tc.oid = i.indrelid"
- " AND i.indisprimary = 't'"
- " AND ia.attrelid = i.indexrelid"
- " AND ta.attrelid = i.indrelid"
- " AND ta.attnum = i.indkey[ia.attnum-1]"
- " AND ic.oid = i.indexrelid"
- " order by ia.attnum"
- , sizeof(tables_query));
- }
+ snprintf(tbqry, tsize,
+ " where tc.oid = " FORMAT_UINT4
+ , reloid);
+
+ strlcat(tables_query,
+ " AND tc.oid = i.indrelid"
+ " AND n.oid = tc.relnamespace"
+ " AND i.indisprimary = 't'"
+ " AND ia.attrelid = i.indexrelid"
+ " AND ta.attrelid = i.indrelid"
+ " AND ta.attnum = i.indkey[ia.attnum-1]"
+ " AND (NOT ta.attisdropped)"
+ " AND (NOT ia.attisdropped)"
+ " AND ic.oid = i.indexrelid"
+ " order by ia.attnum"
+ , sizeof(tables_query));
break;
case 2:
/*
* Simplified query to search old fashoned primary key
*/
- if (conn->schema_support)
- snprintf(tables_query, sizeof(tables_query), "select ta.attname, ia.attnum, ic.relname, n.nspname, NULL"
- " from pg_catalog.pg_attribute ta,"
- " pg_catalog.pg_attribute ia, pg_catalog.pg_class ic,"
- " pg_catalog.pg_index i, pg_catalog.pg_namespace n"
- " where ic.relname %s'%s_pkey'"
- " AND n.nspname %s'%s'"
- " AND ic.oid = i.indexrelid"
- " AND n.oid = ic.relnamespace"
- " AND ia.attrelid = i.indexrelid"
- " AND ta.attrelid = i.indrelid"
- " AND ta.attnum = i.indkey[ia.attnum-1]"
- " AND (NOT ta.attisdropped)"
- " AND (NOT ia.attisdropped)"
- " order by ia.attnum", eq_string, escTableName, eq_string, pkscm);
- else
- snprintf(tables_query, sizeof(tables_query), "select ta.attname, ia.attnum, ic.relname, NULL, NULL"
- " from pg_attribute ta, pg_attribute ia, pg_class ic, pg_index i"
- " where ic.relname %s'%s_pkey'"
- " AND ic.oid = i.indexrelid"
- " AND ia.attrelid = i.indexrelid"
- " AND ta.attrelid = i.indrelid"
- " AND ta.attnum = i.indkey[ia.attnum-1]"
- " order by ia.attnum", eq_string, escTableName);
+ snprintf(tables_query, sizeof(tables_query), "select ta.attname, ia.attnum, ic.relname, n.nspname, NULL"
+ " from pg_catalog.pg_attribute ta,"
+ " pg_catalog.pg_attribute ia, pg_catalog.pg_class ic,"
+ " pg_catalog.pg_index i, pg_catalog.pg_namespace n"
+ " where ic.relname %s'%s_pkey'"
+ " AND n.nspname %s'%s'"
+ " AND ic.oid = i.indexrelid"
+ " AND n.oid = ic.relnamespace"
+ " AND ia.attrelid = i.indexrelid"
+ " AND ta.attrelid = i.indrelid"
+ " AND ta.attnum = i.indkey[ia.attnum-1]"
+ " AND (NOT ta.attisdropped)"
+ " AND (NOT ia.attisdropped)"
+ " order by ia.attnum", eq_string, escTableName, eq_string, pkscm);
break;
}
mylog("%s: tables_query='%s'\n", func, tables_query);
}
/* If not found */
- if (conn->schema_support &&
- SQL_NO_DATA_FOUND == result)
+ if (SQL_NO_DATA_FOUND == result)
{
if (0 == reloid &&
allow_public_schema(conn, szSchemaName, cbSchemaName))
*/
if (fk_table_needed && fk_table_needed[0] != '\0')
{
+ char *escSchemaName;
+
mylog("%s: entering Foreign Key Case #2", func);
escFkTableName = simpleCatalogEscape((SQLCHAR *) fk_table_needed, SQL_NTS, NULL, conn);
- if (conn->schema_support)
- {
- char *escSchemaName;
-
- schema_strcat(schema_needed, "%.*s", szFkTableOwner, cbFkTableOwner, szFkTableName, cbFkTableName, conn);
- escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
- " pt.tgnargs, "
- " pt.tgdeferrable, "
- " pt.tginitdeferred, "
- " pp1.proname, "
- " pp2.proname, "
- " pc.oid, "
- " pc1.oid, "
- " pc1.relname, "
- " pt.tgconstrname, pn.nspname "
- "FROM pg_catalog.pg_class pc, "
- " pg_catalog.pg_proc pp1, "
- " pg_catalog.pg_proc pp2, "
- " pg_catalog.pg_trigger pt1, "
- " pg_catalog.pg_trigger pt2, "
- " pg_catalog.pg_proc pp, "
- " pg_catalog.pg_trigger pt, "
- " pg_catalog.pg_class pc1, "
- " pg_catalog.pg_namespace pn, "
- " pg_catalog.pg_namespace pn1 "
- "WHERE pt.tgrelid = pc.oid "
- "AND pp.oid = pt.tgfoid "
- "AND pt1.tgconstrrelid = pc.oid "
- "AND pp1.oid = pt1.tgfoid "
- "AND pt2.tgfoid = pp2.oid "
- "AND pt2.tgconstrrelid = pc.oid "
- "AND ((pc.relname %s'%s') "
- "AND (pn1.oid = pc.relnamespace) "
- "AND (pn1.nspname %s'%s') "
- "AND (pp.proname LIKE '%%ins') "
- "AND (pp1.proname LIKE '%%upd') "
- "AND (pp1.proname not LIKE '%%check%%') "
- "AND (pp2.proname LIKE '%%del') "
- "AND (pt1.tgrelid=pt.tgconstrrelid) "
- "AND (pt1.tgconstrname=pt.tgconstrname) "
- "AND (pt2.tgrelid=pt.tgconstrrelid) "
- "AND (pt2.tgconstrname=pt.tgconstrname) "
- "AND (pt.tgconstrrelid=pc1.oid) "
- "AND (pc1.relnamespace=pn.oid))"
- " order by pt.tgconstrname",
- eq_string, escFkTableName, eq_string, escSchemaName);
- free(escSchemaName);
- }
- else
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
- " pt.tgnargs, "
- " pt.tgdeferrable, "
- " pt.tginitdeferred, "
- " pp1.proname, "
- " pp2.proname, "
- " pc.oid, "
- " pc1.oid, "
- " pc1.relname, pt.tgconstrname "
- "FROM pg_class pc, "
- " pg_proc pp1, "
- " pg_proc pp2, "
- " pg_trigger pt1, "
- " pg_trigger pt2, "
- " pg_proc pp, "
- " pg_trigger pt, "
- " pg_class pc1 "
- "WHERE pt.tgrelid = pc.oid "
- "AND pp.oid = pt.tgfoid "
- "AND pt1.tgconstrrelid = pc.oid "
- "AND pp1.oid = pt1.tgfoid "
- "AND pt2.tgfoid = pp2.oid "
- "AND pt2.tgconstrrelid = pc.oid "
- "AND ((pc.relname %s'%s') "
- "AND (pp.proname LIKE '%%ins') "
- "AND (pp1.proname LIKE '%%upd') "
- "AND (pp1.proname not LIKE '%%check%%') "
- "AND (pp2.proname LIKE '%%del') "
- "AND (pt1.tgrelid=pt.tgconstrrelid) "
- "AND (pt1.tgconstrname=pt.tgconstrname) "
- "AND (pt2.tgrelid=pt.tgconstrrelid) "
- "AND (pt2.tgconstrname=pt.tgconstrname) "
- "AND (pt.tgconstrrelid=pc1.oid)) "
- "order by pt.tgconstrname",
- eq_string, escFkTableName);
+ schema_strcat(schema_needed, "%.*s", szFkTableOwner, cbFkTableOwner, szFkTableName, cbFkTableName, conn);
+ escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
+ snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
+ " pt.tgnargs, "
+ " pt.tgdeferrable, "
+ " pt.tginitdeferred, "
+ " pp1.proname, "
+ " pp2.proname, "
+ " pc.oid, "
+ " pc1.oid, "
+ " pc1.relname, "
+ " pt.tgconstrname, pn.nspname "
+ "FROM pg_catalog.pg_class pc, "
+ " pg_catalog.pg_proc pp1, "
+ " pg_catalog.pg_proc pp2, "
+ " pg_catalog.pg_trigger pt1, "
+ " pg_catalog.pg_trigger pt2, "
+ " pg_catalog.pg_proc pp, "
+ " pg_catalog.pg_trigger pt, "
+ " pg_catalog.pg_class pc1, "
+ " pg_catalog.pg_namespace pn, "
+ " pg_catalog.pg_namespace pn1 "
+ "WHERE pt.tgrelid = pc.oid "
+ "AND pp.oid = pt.tgfoid "
+ "AND pt1.tgconstrrelid = pc.oid "
+ "AND pp1.oid = pt1.tgfoid "
+ "AND pt2.tgfoid = pp2.oid "
+ "AND pt2.tgconstrrelid = pc.oid "
+ "AND ((pc.relname %s'%s') "
+ "AND (pn1.oid = pc.relnamespace) "
+ "AND (pn1.nspname %s'%s') "
+ "AND (pp.proname LIKE '%%ins') "
+ "AND (pp1.proname LIKE '%%upd') "
+ "AND (pp1.proname not LIKE '%%check%%') "
+ "AND (pp2.proname LIKE '%%del') "
+ "AND (pt1.tgrelid=pt.tgconstrrelid) "
+ "AND (pt1.tgconstrname=pt.tgconstrname) "
+ "AND (pt2.tgrelid=pt.tgconstrrelid) "
+ "AND (pt2.tgconstrname=pt.tgconstrname) "
+ "AND (pt.tgconstrrelid=pc1.oid) "
+ "AND (pc1.relnamespace=pn.oid))"
+ " order by pt.tgconstrname",
+ eq_string, escFkTableName, eq_string, escSchemaName);
+ free(escSchemaName);
result = PGAPI_ExecDirect(htbl_stmt, (SQLCHAR *) tables_query, SQL_NTS, 0);
goto cleanup;
}
- if (conn->schema_support)
+ result = PGAPI_BindCol(htbl_stmt, 11, internal_asis_type,
+ schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
+ if (!SQL_SUCCEEDED(result))
{
- result = PGAPI_BindCol(htbl_stmt, 11, internal_asis_type,
- schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
- if (!SQL_SUCCEEDED(result))
- {
- SC_error_copy(stmt, tbl_stmt, TRUE);
- goto cleanup;
- }
+ SC_error_copy(stmt, tbl_stmt, TRUE);
+ goto cleanup;
}
result = PGAPI_Fetch(htbl_stmt);
*/
else if (pk_table_needed[0] != '\0')
{
+ char *escSchemaName;
+
escPkTableName = simpleCatalogEscape((SQLCHAR *) pk_table_needed, SQL_NTS, NULL, conn);
- if (conn->schema_support)
- {
- char *escSchemaName;
-
- schema_strcat(schema_needed, "%.*s", szPkTableOwner, cbPkTableOwner, szPkTableName, cbPkTableName, conn);
- escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
- " pt.tgnargs, "
- " pt.tgdeferrable, "
- " pt.tginitdeferred, "
- " pp1.proname, "
- " pp2.proname, "
- " pc.oid, "
- " pc1.oid, "
- " pc1.relname, "
- " pt.tgconstrname, pn1.nspname "
- "FROM pg_catalog.pg_class pc, "
- " pg_catalog.pg_class pc1, "
- " pg_catalog.pg_proc pp, "
- " pg_catalog.pg_proc pp1, "
- " pg_catalog.pg_proc pp2, "
- " pg_catalog.pg_trigger pt, "
- " pg_catalog.pg_trigger pt1, "
- " pg_catalog.pg_trigger pt2, "
- " pg_catalog.pg_namespace pn, "
- " pg_catalog.pg_namespace pn1 "
- "WHERE pc.relname %s'%s' "
- " AND pn.nspname %s'%s' "
- " AND pc.relnamespace = pn.oid "
- " AND pt.tgconstrrelid = pc.oid "
- " AND pp.oid = pt.tgfoid "
- " AND pp.proname Like '%%ins' "
- " AND pt1.tgconstrname = pt.tgconstrname "
- " AND pt1.tgconstrrelid = pt.tgrelid "
- " AND pt1.tgrelid = pc.oid "
- " AND pc1.oid = pt.tgrelid "
- " AND pp1.oid = pt1.tgfoid "
- " AND pp1.proname like '%%upd' "
- " AND (pp1.proname not like '%%check%%') "
- " AND pt2.tgconstrname = pt.tgconstrname "
- " AND pt2.tgconstrrelid = pt.tgrelid "
- " AND pt2.tgrelid = pc.oid "
- " AND pp2.oid = pt2.tgfoid "
- " AND pp2.proname Like '%%del' "
- " AND pn1.oid = pc1.relnamespace "
- " order by pt.tgconstrname",
- eq_string, escPkTableName, eq_string, escSchemaName);
- free(escSchemaName);
- }
- else
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
- " pt.tgnargs, "
- " pt.tgdeferrable, "
- " pt.tginitdeferred, "
- " pp1.proname, "
- " pp2.proname, "
- " pc.oid, "
- " pc1.oid, "
- " pc1.relname, pt.tgconstrname "
- "FROM pg_class pc, "
- " pg_class pc1, "
- " pg_proc pp, "
- " pg_proc pp1, "
- " pg_proc pp2, "
- " pg_trigger pt, "
- " pg_trigger pt1, "
- " pg_trigger pt2 "
- "WHERE pc.relname %s'%s' "
- " AND pt.tgconstrrelid = pc.oid "
- " AND pp.oid = pt.tgfoid "
- " AND pp.proname Like '%%ins' "
- " AND pt1.tgconstrname = pt.tgconstrname "
- " AND pt1.tgconstrrelid = pt.tgrelid "
- " AND pt1.tgrelid = pc.oid "
- " AND pc1.oid = pt.tgrelid "
- " AND pp1.oid = pt1.tgfoid "
- " AND pp1.proname like '%%upd' "
- " AND pp1.(proname not like '%%check%%') "
- " AND pt2.tgconstrname = pt.tgconstrname "
- " AND pt2.tgconstrrelid = pt.tgrelid "
- " AND pt2.tgrelid = pc.oid "
- " AND pp2.oid = pt2.tgfoid "
- " AND pp2.proname Like '%%del'"
- " order by pt.tgconstrname",
- eq_string, escPkTableName);
+ schema_strcat(schema_needed, "%.*s", szPkTableOwner, cbPkTableOwner, szPkTableName, cbPkTableName, conn);
+ escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
+ snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
+ " pt.tgnargs, "
+ " pt.tgdeferrable, "
+ " pt.tginitdeferred, "
+ " pp1.proname, "
+ " pp2.proname, "
+ " pc.oid, "
+ " pc1.oid, "
+ " pc1.relname, "
+ " pt.tgconstrname, pn1.nspname "
+ "FROM pg_catalog.pg_class pc, "
+ " pg_catalog.pg_class pc1, "
+ " pg_catalog.pg_proc pp, "
+ " pg_catalog.pg_proc pp1, "
+ " pg_catalog.pg_proc pp2, "
+ " pg_catalog.pg_trigger pt, "
+ " pg_catalog.pg_trigger pt1, "
+ " pg_catalog.pg_trigger pt2, "
+ " pg_catalog.pg_namespace pn, "
+ " pg_catalog.pg_namespace pn1 "
+ "WHERE pc.relname %s'%s' "
+ " AND pn.nspname %s'%s' "
+ " AND pc.relnamespace = pn.oid "
+ " AND pt.tgconstrrelid = pc.oid "
+ " AND pp.oid = pt.tgfoid "
+ " AND pp.proname Like '%%ins' "
+ " AND pt1.tgconstrname = pt.tgconstrname "
+ " AND pt1.tgconstrrelid = pt.tgrelid "
+ " AND pt1.tgrelid = pc.oid "
+ " AND pc1.oid = pt.tgrelid "
+ " AND pp1.oid = pt1.tgfoid "
+ " AND pp1.proname like '%%upd' "
+ " AND (pp1.proname not like '%%check%%') "
+ " AND pt2.tgconstrname = pt.tgconstrname "
+ " AND pt2.tgconstrrelid = pt.tgrelid "
+ " AND pt2.tgrelid = pc.oid "
+ " AND pp2.oid = pt2.tgfoid "
+ " AND pp2.proname Like '%%del' "
+ " AND pn1.oid = pc1.relnamespace "
+ " order by pt.tgconstrname",
+ eq_string, escPkTableName, eq_string, escSchemaName);
+ free(escSchemaName);
result = PGAPI_ExecDirect(htbl_stmt, (SQLCHAR *) tables_query, SQL_NTS, 0);
if (!SQL_SUCCEEDED(result))
goto cleanup;
}
- if (conn->schema_support)
+ result = PGAPI_BindCol(htbl_stmt, 11, internal_asis_type,
+ schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
+ if (!SQL_SUCCEEDED(result))
{
- result = PGAPI_BindCol(htbl_stmt, 11, internal_asis_type,
- schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
- if (!SQL_SUCCEEDED(result))
- {
- SC_error_copy(stmt, tbl_stmt, TRUE);
- goto cleanup;
- }
+ SC_error_copy(stmt, tbl_stmt, TRUE);
+ goto cleanup;
}
result = PGAPI_Fetch(htbl_stmt);
mylog("%s: entering...\n", func);
- if (PG_VERSION_LT(conn, 6.5))
- {
- SC_set_error(stmt, STMT_NOT_IMPLEMENTED_ERROR, "Version is too old", func);
- return SQL_ERROR;
- }
if (result = SC_initialize_and_recycle(stmt), SQL_SUCCESS != result)
return result;
search_pattern = (0 == (flag & PODBC_NOT_SEARCH_PATTERN));
escProcName = simpleCatalogEscape(szProcName, cbProcName, NULL, conn);
}
op_string = gen_opestr(like_or_eq, conn);
- if (conn->schema_support)
- {
- strcpy(proc_query, "select proname, proretset, prorettype, "
- "pronargs, proargtypes, nspname, p.oid");
- ret_col = ext_pos = 7;
- poid_pos = 6;
+ strcpy(proc_query, "select proname, proretset, prorettype, "
+ "pronargs, proargtypes, nspname, p.oid");
+ ret_col = ext_pos = 7;
+ poid_pos = 6;
#ifdef PRORET_COUNT
- strcat(proc_query, ", atttypid, attname");
- attid_pos = ext_pos;
- attname_pos = ext_pos + 1;
- ret_col += 2;
- ext_pos = ret_col;
+ strcat(proc_query, ", atttypid, attname");
+ attid_pos = ext_pos;
+ attname_pos = ext_pos + 1;
+ ret_col += 2;
+ ext_pos = ret_col;
#endif /* PRORET_COUNT */
- if (PG_VERSION_GE(conn, 8.0))
- {
- strcat(proc_query, ", proargnames");
- ret_col++;
- }
- if (PG_VERSION_GE(conn, 8.1))
- {
- strcat(proc_query, ", proargmodes, proallargtypes");
- ret_col += 2;
- }
+ if (PG_VERSION_GE(conn, 8.0))
+ {
+ strcat(proc_query, ", proargnames");
+ ret_col++;
+ }
+ if (PG_VERSION_GE(conn, 8.1))
+ {
+ strcat(proc_query, ", proargmodes, proallargtypes");
+ ret_col += 2;
+ }
#ifdef PRORET_COUNT
- strcat(proc_query, " from ((pg_catalog.pg_namespace n inner join"
- " pg_catalog.pg_proc p on p.pronamespace = n.oid)"
- " inner join pg_type t on t.oid = p.prorettype)"
- " left outer join pg_attribute a on a.attrelid = t.typrelid "
- " and attnum > 0 and not attisdropped where");
+ strcat(proc_query, " from ((pg_catalog.pg_namespace n inner join"
+ " pg_catalog.pg_proc p on p.pronamespace = n.oid)"
+ " inner join pg_type t on t.oid = p.prorettype)"
+ " left outer join pg_attribute a on a.attrelid = t.typrelid "
+ " and attnum > 0 and not attisdropped where");
#else
- strcat(proc_query, " from pg_catalog.pg_namespace n,"
- " pg_catalog.pg_proc p where");
- " p.pronamespace = n.oid and"
- " (not proretset) and");
+ strcat(proc_query, " from pg_catalog.pg_namespace n,"
+ " pg_catalog.pg_proc p where");
+ " p.pronamespace = n.oid and"
+ " (not proretset) and");
#endif /* PRORET_COUNT */
+ snprintf_add(proc_query, sizeof(proc_query),
+ " has_function_privilege(p.oid, 'EXECUTE')");
+ if (IS_VALID_NAME(escSchemaName))
snprintf_add(proc_query, sizeof(proc_query),
- " has_function_privilege(p.oid, 'EXECUTE')");
- if (IS_VALID_NAME(escSchemaName))
- snprintf_add(proc_query, sizeof(proc_query),
- " and nspname %s'%s'",
- op_string, escSchemaName);
- if (escProcName)
- snprintf_add(proc_query, sizeof(proc_query),
- " and proname %s'%s'", op_string, escProcName);
- snprintf_add(proc_query, sizeof(proc_query),
- " order by nspname, proname, p.oid, attnum");
- }
- else
- {
- strcpy(proc_query, "select proname, proretset, prorettype, "
- "pronargs, proargtypes from pg_proc where "
- "(not proretset)");
- ret_col = 5;
- if (escProcName)
- snprintf_add(proc_query, sizeof(proc_query), " and proname %s'%s'", op_string, escProcName);
+ " and nspname %s'%s'",
+ op_string, escSchemaName);
+ if (escProcName)
snprintf_add(proc_query, sizeof(proc_query),
- " order by proname, proretset");
- }
+ " and proname %s'%s'", op_string, escProcName);
+ snprintf_add(proc_query, sizeof(proc_query),
+ " order by nspname, proname, p.oid, attnum");
if (tres = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(tres))
{
SC_set_error(stmt, STMT_EXEC_ERROR, "PGAPI_ProcedureColumns query error", func);
tcount = QR_get_num_total_tuples(tres);
for (i = 0, poid = 0; i < tcount; i++)
{
- if (conn->schema_support)
- schema_name = GET_SCHEMA_NAME(QR_get_value_backend_text(tres, i, 5));
- else
- schema_name = NULL;
+ schema_name = GET_SCHEMA_NAME(QR_get_value_backend_text(tres, i, 5));
procname = QR_get_value_backend_text(tres, i, 0);
retset = QR_get_value_backend_text(tres, i, 1);
pgtype = QR_get_value_backend_int(tres, i, 2, NULL);
mylog("%s: entering... scnm=%p len=%d\n", func, szProcOwner, cbProcOwner);
- if (PG_VERSION_LT(conn, 6.5))
- {
- SC_set_error(stmt, STMT_NOT_IMPLEMENTED_ERROR, "Version is too old", func);
- return SQL_ERROR;
- }
if (result = SC_initialize_and_recycle(stmt), SQL_SUCCESS != result)
return result;
* The following seems the simplest implementation
*/
op_string = gen_opestr(like_or_eq, conn);
- if (conn->schema_support)
- {
- strcpy(proc_query, "select '' as " "PROCEDURE_CAT" ", nspname as " "PROCEDURE_SCHEM" ","
- " proname as " "PROCEDURE_NAME" ", '' as " "NUM_INPUT_PARAMS" ","
- " '' as " "NUM_OUTPUT_PARAMS" ", '' as " "NUM_RESULT_SETS" ","
- " '' as " "REMARKS" ","
- " case when prorettype = 0 then 1::int2 else 2::int2 end"
- " as " "PROCEDURE_TYPE" " from pg_catalog.pg_namespace,"
- " pg_catalog.pg_proc"
- " where pg_proc.pronamespace = pg_namespace.oid");
- schema_strcat1(proc_query, " and nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szProcName, cbProcName, conn);
- if (IS_VALID_NAME(escProcName))
- snprintf_add(proc_query, sizeof(proc_query),
- " and proname %s'%s'", op_string, escProcName);
- }
- else
- {
- snprintf(proc_query, sizeof(proc_query),
- "select '' as " "PROCEDURE_CAT" ", '' as " "PROCEDURE_SCHEM" ","
- " proname as " "PROCEDURE_NAME" ", '' as " "NUM_INPUT_PARAMS" ","
- " '' as " "NUM_OUTPUT_PARAMS" ", '' as " "NUM_RESULT_SETS" ","
- " '' as " "REMARKS" ","
- " case when prorettype = 0 then 1::int2 else 2::int2 end as " "PROCEDURE_TYPE" " from pg_proc");
- if (IS_VALID_NAME(escSchemaName))
- snprintf_add(proc_query, sizeof(proc_query),
- " where proname %s'%s'",
- op_string, escSchemaName);
- }
+ strcpy(proc_query, "select '' as " "PROCEDURE_CAT" ", nspname as " "PROCEDURE_SCHEM" ","
+ " proname as " "PROCEDURE_NAME" ", '' as " "NUM_INPUT_PARAMS" ","
+ " '' as " "NUM_OUTPUT_PARAMS" ", '' as " "NUM_RESULT_SETS" ","
+ " '' as " "REMARKS" ","
+ " case when prorettype = 0 then 1::int2 else 2::int2 end"
+ " as " "PROCEDURE_TYPE" " from pg_catalog.pg_namespace,"
+ " pg_catalog.pg_proc"
+ " where pg_proc.pronamespace = pg_namespace.oid");
+ schema_strcat1(proc_query, " and nspname %s'%.*s'", op_string, escSchemaName, SQL_NTS, szProcName, cbProcName, conn);
+ if (IS_VALID_NAME(escProcName))
+ snprintf_add(proc_query, sizeof(proc_query),
+ " and proname %s'%s'", op_string, escProcName);
if (res = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(res))
{
escSchemaName = simpleCatalogEscape(szSchemaName, cbSchemaName, NULL, conn);
op_string = gen_opestr(like_or_eq, conn);
- if (conn->schema_support)
- strncpy_null(proc_query, "select relname, usename, relacl, nspname"
- " from pg_catalog.pg_namespace, pg_catalog.pg_class ,"
- " pg_catalog.pg_user where", sizeof(proc_query));
- else
- strncpy_null(proc_query, "select relname, usename, relacl"
- " from pg_class , pg_user where", sizeof(proc_query));
- if (conn->schema_support)
- {
- if (escSchemaName)
- schema_strcat1(proc_query, " nspname %s'%.*s' and", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
- }
+ strncpy_null(proc_query, "select relname, usename, relacl, nspname"
+ " from pg_catalog.pg_namespace, pg_catalog.pg_class ,"
+ " pg_catalog.pg_user where", sizeof(proc_query));
+ if (escSchemaName)
+ schema_strcat1(proc_query, " nspname %s'%.*s' and", op_string, escSchemaName, SQL_NTS, szTableName, cbTableName, conn);
+
if (escTableName)
snprintf_add(proc_query, sizeof(proc_query), " relname %s'%s' and", op_string, escTableName);
- if (conn->schema_support)
- {
- strcat(proc_query, " pg_namespace.oid = relnamespace and relkind in ('r', 'v') and");
- if ((!escTableName) && (!escSchemaName))
- strcat(proc_query, " nspname not in ('pg_catalog', 'information_schema') and");
- }
+ strcat(proc_query, " pg_namespace.oid = relnamespace and relkind in ('r', 'v') and");
+ if ((!escTableName) && (!escSchemaName))
+ strcat(proc_query, " nspname not in ('pg_catalog', 'information_schema') and");
+
strcat(proc_query, " pg_user.usesysid = relowner");
if (wres = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(wres))
{
}
tablecount = (Int4) QR_get_num_cached_tuples(wres);
/* If not found */
- if (conn->schema_support &&
- (flag & PODBC_SEARCH_PUBLIC_SCHEMA) != 0 &&
+ if ((flag & PODBC_SEARCH_PUBLIC_SCHEMA) != 0 &&
0 == tablecount)
{
if (allow_public_schema(conn, szSchemaName, cbSchemaName))
}
reln = QR_get_value_backend_text(wres, i, 0);
owner = QR_get_value_backend_text(wres, i, 1);
- if (conn->schema_support)
- schnm = QR_get_value_backend_text(wres, i, 3);
+ schnm = QR_get_value_backend_text(wres, i, 3);
/* The owner has all privileges */
useracl_upd(useracl, allures, owner, ALL_PRIVILIGES);
for (j = 0; j < usercount; j++)
}
tuple = QR_AddNew(res);
set_tuplefield_string(&tuple[0], CurrCat(conn));
- if (conn->schema_support)
- set_tuplefield_string(&tuple[1], GET_SCHEMA_NAME(schnm));
- else
- set_tuplefield_string(&tuple[1], NULL_STRING);
+ set_tuplefield_string(&tuple[1], GET_SCHEMA_NAME(schnm));
set_tuplefield_string(&tuple[2], reln);
if (su || sys)
set_tuplefield_string(&tuple[3], "_SYSTEM");
char *pk_table_needed = NULL, *escTableName = NULL;
char *fk_table_needed = NULL;
char schema_needed[SCHEMA_NAME_STORAGE_LEN + 1];
+ char *escSchemaName;
char catName[SCHEMA_NAME_STORAGE_LEN],
scmName1[SCHEMA_NAME_STORAGE_LEN],
scmName2[SCHEMA_NAME_STORAGE_LEN];
goto cleanup;
}
- if (conn->schema_support)
- {
- char *escSchemaName;
-
- if (NULL != CurrCat(conn))
- snprintf(catName, sizeof(catName), "'%s'::name", CurrCat(conn));
- else
- strcpy(catName, "NULL::name");
- strcpy(scmName1, "n2.nspname");
- strcpy(scmName2, "n1.nspname");
- escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
+ if (NULL != CurrCat(conn))
+ snprintf(catName, sizeof(catName), "'%s'::name", CurrCat(conn));
+ else
+ strcpy(catName, "NULL::name");
+ strcpy(scmName1, "n2.nspname");
+ strcpy(scmName2, "n1.nspname");
+ escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, NULL, conn);
- snprintf(tables_query, sizeof(tables_query),
+ snprintf(tables_query, sizeof(tables_query),
"select"
" %s as PKTABLE_CAT"
",\n %s as PKTABLE_SCHEM"
, eq_string, escTableName
, eq_string, escSchemaName);
- free(escSchemaName);
- if (NULL != pk_table_needed &&
- NULL != fk_table_needed)
- {
- free(escTableName);
- escTableName = simpleCatalogEscape((SQLCHAR *) pk_table_needed, SQL_NTS, NULL, conn);
- snprintf_add(tables_query, sizeof(tables_query),
- "\n where c2.relname %s'%s'",
- eq_string, escTableName);
- }
- strcat(tables_query, "\n order by ref.oid, ref.i");
- }
- else
+ free(escSchemaName);
+ if (NULL != pk_table_needed &&
+ NULL != fk_table_needed)
{
- strcpy(catName, "NULL::name");
- strcpy(scmName1, "NULL::name");
- strcpy(scmName2, "NULL::name");
-
- snprintf(tables_query, sizeof(tables_query),
- "select %s as PKTABLE_CAT"
- ",\n %s as PKTABLE_SCHEM"
- ",\n c2.relname as PKTABLE_NAME"
- ",\n a2.attname as PKCOLUMN_NAME"
- ",\n %s as FKTABLE_CAT"
- ",\n %s as FKTABLE_SCHEM"
- ",\n c1.relname as FKTABLE_NAME"
- ",\n a1.attname as FKCOLUMN_NAME"
- ",\n i::int2 as KEY_SEQ"
- ",\n case confupdtype"
- "\n when 'c' then %d::int2"
- "\n when 'n' then %d::int2"
- "\n when 'd' then %d::int2"
- "\n when 'r' then %d::int2"
- "\n else %d::int2"
- "\n end as UPDATE_RULE"
- ",\n case confdeltype"
- "\n when 'c' then %d::int2"
- "\n when 'n' then %d::int2"
- "\n when 'd' then %d::int2"
- "\n when 'r' then %d::int2"
- "\n else %d::int2"
- "\n end as DELETE_RULE"
- ",\n conname as FK_NAME"
- ",\n NULL::name as PK_NAME"
-#if (ODBCVER >= 0x0300)
- ",\n case"
- "\n when condeferrable then"
- "\n case"
- "\n when condeferred then %d::int2"
- "\n else %d::int2"
- "\n end"
- "\n else %d::int2"
- "\n end as DEFERRABLITY"
-#endif /* ODBCVER */
- "\n from"
- "\n (select conrelid, conkey, confrelid, confkey"
- ",\n generate_series(array_lower(conkey, 1), array_upper(conkey, 1)) as i"
- ",\n confupdtype, confdeltype, conname"
- ",\n condeferrable, condeferred"
- "\n from pg_catalog.pg_constraint cn"
- ",\n pg_catalog.pg_class c"
- "\n where contype = 'f' %s"
- "\n and relname %s'%s'"
- "\n ) ref"
- ",\n pg_catalog.pg_class c1"
- ",\n pg_catalog.pg_attribute a1"
- ",\n pg_catalog.pg_class c2"
- ",\n pg_catalog.pg_attribute a2"
- "\n where c1.oid = ref.conrelid"
- "\n and c2.oid = ref.confrelid"
- "\n and a1.attrelid = c1.oid"
- "\n and a1.attnum = conkey[i]"
- "\n and a2.attrelid = c2.oid"
- "\n and a2.attnum = confkey[i]"
- "\n order by ref.oid, ref.i"
- , catName
- , scmName1
- , catName
- , scmName2
- , SQL_CASCADE
- , SQL_SET_NULL
- , SQL_SET_DEFAULT
- , SQL_RESTRICT
- , SQL_NO_ACTION
- , SQL_CASCADE
- , SQL_SET_NULL
- , SQL_SET_DEFAULT
- , SQL_RESTRICT
- , SQL_NO_ACTION
-#if (ODBCVER >= 0x0300)
- , SQL_INITIALLY_DEFERRED
- , SQL_INITIALLY_IMMEDIATE
- , SQL_NOT_DEFERRABLE
-#endif /* ODBCVER */
- , relqual, eq_string, escTableName);
+ free(escTableName);
+ escTableName = simpleCatalogEscape((SQLCHAR *) pk_table_needed, SQL_NTS, NULL, conn);
+ snprintf_add(tables_query, sizeof(tables_query),
+ "\n where c2.relname %s'%s'",
+ eq_string, escTableName);
}
+ strcat(tables_query, "\n order by ref.oid, ref.i");
if (res = CC_send_query(conn, tables_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(res))
{
break;
case SQL_CREATE_SCHEMA:
len = 4;
- if (conn->schema_support)
- value = SQL_CS_CREATE_SCHEMA | SQL_CS_AUTHORIZATION;
- else
- value = 0;
+ value = SQL_CS_CREATE_SCHEMA | SQL_CS_AUTHORIZATION;
break;
case SQL_CREATE_TABLE:
len = 4;
- value = SQL_CT_CREATE_TABLE | SQL_CT_COLUMN_CONSTRAINT
- | SQL_CT_COLUMN_DEFAULT;
- if (PG_VERSION_GE(conn, 6.5))
- value |= SQL_CT_GLOBAL_TEMPORARY;
- if (PG_VERSION_GE(conn, 7.0))
- value |= SQL_CT_TABLE_CONSTRAINT
- | SQL_CT_CONSTRAINT_NAME_DEFINITION
- | SQL_CT_CONSTRAINT_INITIALLY_DEFERRED
- | SQL_CT_CONSTRAINT_INITIALLY_IMMEDIATE
- | SQL_CT_CONSTRAINT_DEFERRABLE;
+ value = SQL_CT_CREATE_TABLE
+ | SQL_CT_COLUMN_CONSTRAINT
+ | SQL_CT_COLUMN_DEFAULT
+ | SQL_CT_GLOBAL_TEMPORARY
+ | SQL_CT_TABLE_CONSTRAINT
+ | SQL_CT_CONSTRAINT_NAME_DEFINITION
+ | SQL_CT_CONSTRAINT_INITIALLY_DEFERRED
+ | SQL_CT_CONSTRAINT_INITIALLY_IMMEDIATE
+ | SQL_CT_CONSTRAINT_DEFERRABLE;
break;
case SQL_CREATE_TRANSLATION:
len = 4;
break;
case SQL_DROP_SCHEMA:
len = 4;
- if (conn->schema_support)
- value = SQL_DS_DROP_SCHEMA | SQL_DS_RESTRICT | SQL_DS_CASCADE;
- else
- value = 0;
+ value = SQL_DS_DROP_SCHEMA | SQL_DS_RESTRICT | SQL_DS_CASCADE;
break;
case SQL_DROP_TABLE:
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;
case SQL_DROP_VIEW:
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;
break;
case SQL_MAX_IDENTIFIER_LEN:
len = 2;
- value = 32;
- if (PG_VERSION_GT(conn, 7.2))
- value = 64;
+ /* FIXME: This is the default, but the server might be compiled
+ * with a different NAMEDATALEN value */
+ value = 64;
break;
case SQL_MAX_ROW_SIZE_INCLUDES_LONG:
len = 0;
break;
case SQL_SQL92_RELATIONAL_JOIN_OPERATORS:
len = 4;
- if (PG_VERSION_GE(conn, 7.1))
- value = SQL_SRJO_CROSS_JOIN | SQL_SRJO_EXCEPT_JOIN
- | SQL_SRJO_FULL_OUTER_JOIN | SQL_SRJO_INNER_JOIN
- | SQL_SRJO_INTERSECT_JOIN | SQL_SRJO_LEFT_OUTER_JOIN
- | SQL_SRJO_NATURAL_JOIN | SQL_SRJO_RIGHT_OUTER_JOIN
- | SQL_SRJO_UNION_JOIN;
+ value = SQL_SRJO_CROSS_JOIN | SQL_SRJO_EXCEPT_JOIN
+ | SQL_SRJO_FULL_OUTER_JOIN | SQL_SRJO_INNER_JOIN
+ | SQL_SRJO_INTERSECT_JOIN | SQL_SRJO_LEFT_OUTER_JOIN
+ | SQL_SRJO_NATURAL_JOIN | SQL_SRJO_RIGHT_OUTER_JOIN
+ | SQL_SRJO_UNION_JOIN;
break;
case SQL_SQL92_REVOKE:
len = 4;
* the CURRENT_SCHEMA() though it doesn't worth the
* naming.
*/
- if (conn->schema_support && tbname && (tbnmlen > 0 || tbnmlen == SQL_NTS))
+ if (tbname && (tbnmlen > 0 || tbnmlen == SQL_NTS))
return my_strcat(buf, fmt, CC_get_current_schema(conn), SQL_NTS);
return NULL;
}
{
if (!s || 0 == len)
{
- if (conn->schema_support && tbname && (tbnmlen > 0 || tbnmlen == SQL_NTS))
+ if (tbname && (tbnmlen > 0 || tbnmlen == SQL_NTS))
return my_strcat1(buf, fmt, s1, CC_get_current_schema(conn), SQL_NTS);
return NULL;
}
QR_Destructor(res);
return encstr;
}
-static char *
-CC_lookup_cs_old(ConnectionClass *self)
-{
- char *encstr = NULL;
- HSTMT hstmt;
- RETCODE result;
-
- result = PGAPI_AllocStmt(self, &hstmt, 0);
- if (!SQL_SUCCEEDED(result))
- return encstr;
-
- result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "Show Client_Encoding", SQL_NTS, 0);
- if (result == SQL_SUCCESS_WITH_INFO)
- {
- SQLCHAR sqlState[8];
- char errormsg[128], enc[32];
-
- if (PGAPI_Error(NULL, NULL, hstmt, sqlState, NULL, (SQLCHAR *) errormsg,
- sizeof(errormsg), NULL) == SQL_SUCCESS &&
- sscanf(errormsg, "%*s %*s %*s %*s %*s %s", enc) > 0)
- encstr = strdup(enc);
- }
- PGAPI_FreeStmt(hstmt, SQL_DROP);
- return encstr;
-}
/*
* This function works under Windows or Unicode case only.
wenc = "SJIS";
break;
case 936:
- if (!bStartup && PG_VERSION_GT(conn, 7.2))
+ if (!bStartup)
wenc = "GBK";
break;
case 949:
- if (!bStartup && PG_VERSION_GT(conn, 7.2))
+ if (!bStartup)
wenc = "UHC";
break;
case 950:
wenc = "WIN1251";
break;
case 1256:
- if (PG_VERSION_GE(conn, 7.3))
- wenc = "WIN1256";
+ wenc = "WIN1256";
break;
case 1252:
if (strnicmp(currenc, "LATIN", 5) == 0)
encspec = strdup(self->original_client_encoding);
if (self->current_client_encoding)
currenc = strdup(self->current_client_encoding);
- else if (PG_VERSION_LT(self, 7.2))
- currenc = CC_lookup_cs_old(self);
else
currenc = CC_lookup_cs_new(self);
tencstr = encspec ? encspec : currenc;
mylog("[%s]", func);
ENTER_STMT_CS(stmt);
SC_clear_error(stmt);
- if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
- flag |= PODBC_WITH_HOLD;
+ flag |= PODBC_WITH_HOLD;
if (SC_opencheck(stmt, func))
ret = SQL_ERROR;
else
mylog("[%s]", func);
ENTER_STMT_CS(stmt);
SC_clear_error(stmt);
- if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
- flag |= PODBC_WITH_HOLD;
+ flag |= PODBC_WITH_HOLD;
if (SC_opencheck(stmt, func))
ret = SQL_ERROR;
else
stxt = ucs2_to_utf8(StatementText, TextLength, &slen, FALSE);
ENTER_STMT_CS(stmt);
SC_clear_error(stmt);
- if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
- flag |= PODBC_WITH_HOLD;
+ flag |= PODBC_WITH_HOLD;
StartRollbackState(stmt);
if (SC_opencheck(stmt, func))
ret = SQL_ERROR;
switch (vParam)
{
case SQL_TXN_SERIALIZABLE:
- if (PG_VERSION_GE(conn, 6.5) &&
- PG_VERSION_LE(conn, 7.0))
- retval = SQL_ERROR;
break;
case SQL_TXN_REPEATABLE_READ:
if (PG_VERSION_LT(conn, 8.0))
retval = SQL_ERROR;
break;
case SQL_TXN_READ_COMMITTED:
- if (PG_VERSION_LT(conn, 6.5))
- retval = SQL_ERROR;
break;
case SQL_TXN_READ_UNCOMMITTED:
if (PG_VERSION_LT(conn, 8.0))
*coli = NULL;
if (NAME_IS_NULL(table_name))
return TRUE;
- if (conn->schema_support)
+ if (NAME_IS_NULL(*schema_name))
{
- if (NAME_IS_NULL(*schema_name))
+ const char *curschema = CC_get_current_schema(conn);
+ /*
+ * Though current_schema() doesn't have
+ * much sense in PostgreSQL, we first
+ * check the current_schema() when no
+ * explicit schema name is specified.
+ */
+ for (colidx = 0; colidx < conn->ntables; colidx++)
{
- const char *curschema = CC_get_current_schema(conn);
- /*
- * Though current_schema() doesn't have
- * much sense in PostgreSQL, we first
- * check the current_schema() when no
- * explicit schema name is specified.
- */
- for (colidx = 0; colidx < conn->ntables; colidx++)
+ if (!NAMEICMP(conn->col_info[colidx]->table_name, table_name) &&
+ !stricmp(SAFE_NAME(conn->col_info[colidx]->schema_name), curschema))
{
- if (!NAMEICMP(conn->col_info[colidx]->table_name, table_name) &&
- !stricmp(SAFE_NAME(conn->col_info[colidx]->schema_name), curschema))
- {
- mylog("FOUND col_info table='%s' current schema='%s'\n", PRINT_NAME(table_name), curschema);
- found = TRUE;
- STR_TO_NAME(*schema_name, curschema);
- break;
- }
- }
- if (!found)
- {
- QResultClass *res;
- char token[256];
- BOOL tblFound = FALSE;
-
- /*
- * We also have to check as follows.
- */
- snprintf(token, sizeof(token),
- "select nspname from pg_namespace n, pg_class c"
- " where c.relnamespace=n.oid and c.oid='\"%s\"'::regclass",
- SAFE_NAME(table_name));
- res = CC_send_query(conn, token, NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL);
- if (QR_command_maybe_successful(res))
- {
- if (QR_get_num_total_tuples(res) == 1)
- {
- tblFound = TRUE;
- STR_TO_NAME(*schema_name, QR_get_value_backend_text(res, 0, 0));
- }
- }
- QR_Destructor(res);
- if (!tblFound)
- return FALSE;
+ mylog("FOUND col_info table='%s' current schema='%s'\n", PRINT_NAME(table_name), curschema);
+ found = TRUE;
+ STR_TO_NAME(*schema_name, curschema);
+ break;
}
}
- if (!found && NAME_IS_VALID(*schema_name))
+ if (!found)
{
- for (colidx = 0; colidx < conn->ntables; colidx++)
+ QResultClass *res;
+ char token[256];
+ BOOL tblFound = FALSE;
+
+ /*
+ * We also have to check as follows.
+ */
+ snprintf(token, sizeof(token),
+ "select nspname from pg_namespace n, pg_class c"
+ " where c.relnamespace=n.oid and c.oid='\"%s\"'::regclass",
+ SAFE_NAME(table_name));
+ res = CC_send_query(conn, token, NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL);
+ if (QR_command_maybe_successful(res))
{
- if (!NAMEICMP(conn->col_info[colidx]->table_name, table_name) &&
- !NAMEICMP(conn->col_info[colidx]->schema_name, *schema_name))
+ if (QR_get_num_total_tuples(res) == 1)
{
- mylog("FOUND col_info table='%s' schema='%s'\n", PRINT_NAME(table_name), PRINT_NAME(*schema_name));
- found = TRUE;
- break;
+ tblFound = TRUE;
+ STR_TO_NAME(*schema_name, QR_get_value_backend_text(res, 0, 0));
}
}
+ QR_Destructor(res);
+ if (!tblFound)
+ return FALSE;
}
}
- else
+ if (!found && NAME_IS_VALID(*schema_name))
{
for (colidx = 0; colidx < conn->ntables; colidx++)
{
- if (!NAMEICMP(conn->col_info[colidx]->table_name, table_name))
+ if (!NAMEICMP(conn->col_info[colidx]->table_name, table_name) &&
+ !NAMEICMP(conn->col_info[colidx]->schema_name, *schema_name))
{
- mylog("FOUND col_info table='%s'\n", table_name);
+ mylog("FOUND col_info table='%s' schema='%s'\n", PRINT_NAME(table_name), PRINT_NAME(*schema_name));
found = TRUE;
break;
}
#endif /* UNICODE_SUPPORT */
if (maxsize == TEXT_FIELD_SIZE + 1) /* magic length for testing */
- {
- if (PG_VERSION_GE(conn, 7.1))
- maxsize = 0;
- else
- maxsize = TEXT_FIELD_SIZE;
- }
+ maxsize = 0;
+
/*
* Static ColumnSize (i.e., the Maximum ColumnSize of the datatype) This
* has nothing to do with a result set.
getTimestampDecimalDigitsX(const ConnectionClass *conn, OID type, int atttypmod)
{
mylog("%s: type=%d, atttypmod=%d\n", __FUNCTION__, type, atttypmod);
-
- if (PG_VERSION_LT(conn, 7.2))
- return 0;
-
return (atttypmod > -1 ? atttypmod : 6);
}
-
static SQLSMALLINT
getTimestampColumnSizeX(const ConnectionClass *conn, OID type, int atttypmod)
{
case PG_TYPE_ABSTIME:
return "abstime";
case PG_TYPE_DATETIME:
- if (PG_VERSION_GT(conn, 7.1))
- return "timestamptz";
- else if (PG_VERSION_LT(conn, 7.0))
- return "datetime";
- else
- return "timestamp";
+ return "timestamptz";
case PG_TYPE_TIMESTAMP_NO_TMZONE:
return "timestamp without time zone";
case PG_TYPE_TIMESTAMP:
value = NAME_FIELD_SIZE;
#endif /* NAME_FIELD_SIZE */
if (0 == value)
- {
- if (PG_VERSION_GE(conn, 7.3))
- value = NAMEDATALEN_V73;
- else
- value = NAMEDATALEN_V72;
- }
+ value = NAMEDATALEN_V73;
return value;
}
if (CC_is_in_unicode_driver(conn))
return prec * WCLEN;
#endif /* UNICODE_SUPPORT */
- /* after 7.2 */
- if (PG_VERSION_GE(conn, 7.2))
- coef = conn->mb_maxbyte_per_char;
+ coef = conn->mb_maxbyte_per_char;
if (coef < 2 && (conn->connInfo).lf_conversion)
/* CR -> CR/LF */
coef = 2;
if (CC_is_in_unicode_driver(conn))
return column_size * WCLEN;
#endif /* UNICODE_SUPPORT */
- /* after 7.2 */
- if (PG_VERSION_GE(conn, 7.2))
- coef = conn->mb_maxbyte_per_char;
+ coef = conn->mb_maxbyte_per_char;
if (coef < 2 && (conn->connInfo).lf_conversion)
/* CR -> CR/LF */
coef = 2;
#endif /* UNICODE_SUPPORT */
if (maxsize == TEXT_FIELD_SIZE + 1) /* magic length for testing */
- {
- if (PG_VERSION_GE(conn, 7.1))
- maxsize = 0;
- else
- maxsize = TEXT_FIELD_SIZE;
- }
+ maxsize = 0;
+
/*
* Static ColumnSize (i.e., the Maximum ColumnSize of the datatype) This
* has nothing to do with a result set.
if (col < 0)
return 0;
- if (PG_VERSION_LT(conn, 7.2))
- return 0;
result = SC_get_Curres(stmt);
if (CC_is_in_unicode_driver(conn))
return column_size * WCLEN;
#endif /* UNICODE_SUPPORT */
- /* after 7.2 */
- if (PG_VERSION_GE(conn, 7.2))
- coef = conn->mb_maxbyte_per_char;
+ coef = conn->mb_maxbyte_per_char;
if (coef < 2 && (conn->connInfo).lf_conversion)
/* CR -> CR/LF */
coef = 2;
CORR_VALCPY(debug);
CORR_VALCPY(commlog);
CORR_VALCPY(disable_optimizer);
- CORR_VALCPY(ksqo);
CORR_VALCPY(unique_index);
CORR_VALCPY(onlyread); /* readonly is reserved on Digital C++
* compiler */
#endif /* _MAX_PATH */
#endif /* PATH_MAX */
-#define PG62 "6.2" /* "Protocol" key setting
- * to force Postgres 6.2 */
-#define PG63 "6.3" /* "Protocol" key setting
- * to force postgres 6.3 */
-#define PG64 "6.4"
-#define PG74REJECTED "reject7.4"
-#define PG74 "7.4"
-
typedef struct ConnectionClass_ ConnectionClass;
typedef struct StatementClass_ StatementClass;
typedef struct QResultClass_ QResultClass;
char debug;
char commlog;
char disable_optimizer;
- char ksqo;
char unique_index;
char onlyread; /* readonly is reserved on Digital C++
* compiler */
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,26,140,10
CONTROL "\88ê\94Ê\83\8d\83O\8fo\97Í\82ð\82·\82é(&L) (C:\\psqlodbc.log)",DRV_COMMLOG,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,24,170,10
- CONTROL "&KSQO (¸´Ø°·°¾¯Ä\8dÅ\93K\89»\83I\83v\83V\83\87\83\93)",DRV_KSQO,"Button",
- BS_AUTOCHECKBOX | WS_TABSTOP,15,41,145,10
CONTROL "\83\86\83j\81|\83N\83C\83\93\83f\83b\83N\83X\82ð\8eg\82¤(&I)",DRV_UNIQUEINDEX,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,15,56,129,10
CONTROL "\83X\83e\81|\83g\83\81\83\93\83g\82Ì\8d\\95¶\89ð\90Í\82ð\8ds\82È\82¤(&a)",DRV_PARSE,"Button",
WS_TABSTOP,227,108,29,10
LTEXT "\93Á\95Ê\82È\83I\83v\83V\83\87\83\93",IDC_STATIC,227,158,66,8
EDITTEXT DS_EXTRA_OPTIONS,227,168,35,14,ES_AUTOHSCROLL
- GROUPBOX "\83v\83\8d\83g\83R\83\8b\83o\81|\83W\83\87\83\93",IDC_STATIC,5,128,150,25
- CONTROL "7.4+",DS_PG74,"Button",BS_AUTORADIOBUTTON | WS_GROUP,18,
- 139,30,10
- CONTROL "6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 52,139,30,10
- CONTROL "6.3",DS_PG63,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 90,140,26,10
- CONTROL "6.2",DS_PG62,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 118,140,26,10
GROUPBOX "\83G\83\89\81[\8e\9e\82Ì\83\8d\81[\83\8b\83o\83b\83N\94\8ds",IDC_STATIC,160,128,130,25
CONTROL "\96³\82µ",DS_NO_ROLLBACK,"Button",BS_AUTORADIOBUTTON |
WS_GROUP,165,139,30,10
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,26,116,10
CONTROL "Comm&Log (C:\\psqlodbc_xxxx.log)",DRV_COMMLOG,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,149,26,131,10
- CONTROL "&KSQO(Keyset Query Optimization)",DRV_KSQO,"Button",
- BS_AUTOCHECKBOX | WS_TABSTOP,15,41,132,10
CONTROL "Recognize Unique &Indexes",DRV_UNIQUEINDEX,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,15,56,110,10
CONTROL "P&arse Statements",DRV_PARSE,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,227,107,29,10
LTEXT "Extra Opts",IDC_STATIC,264,98,40,17
EDITTEXT DS_EXTRA_OPTIONS,264,105,40,12,ES_AUTOHSCROLL
- GROUPBOX "Protocol",IDC_STATIC,5,126,136,25
- CONTROL "7.4+",DS_PG74,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,
- 138,31,10
- CONTROL "6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 45,138,27,10
- CONTROL "6.3",DS_PG63,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 79,138,26,10
- CONTROL "6.2",DS_PG62,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,
- 110,138,26,10
GROUPBOX "OID Options",IDC_STATIC,5,157,296,25
CONTROL "Show &Column",DS_SHOWOIDCOLUMN,"Button",BS_AUTOCHECKBOX |
WS_GROUP | WS_TABSTOP,13,168,67,10
void
QR_set_num_fields(QResultClass *self, int new_num_fields)
{
- BOOL allocrelatt = FALSE;
-
if (!self) return;
mylog("in QR_set_num_fields\n");
- CI_set_num_fields(QR_get_fields(self), new_num_fields, allocrelatt);
+ CI_set_num_fields(QR_get_fields(self), new_num_fields);
mylog("exit QR_set_num_fields\n");
}
if (enlargeKeyCache(self, self->cache_size - num_backend_rows, "Out of memory while reading tuples") < 0)
RETURN(FALSE)
- if (PROTOCOL_74(ci)
- && !QR_is_permanent(self) /* Execute seems an invalid operation after COMMIT */
- )
+ if (!QR_is_permanent(self)) /* Execute seems an invalid operation after COMMIT */
{
ExecuteRequest = TRUE;
if (!SendExecuteRequest(stmt, QR_get_cursor(self),
/* We are done because we didn't even get CACHE_SIZE tuples */
mylog("%s: backend_rows < CACHE_SIZE: brows = %d, cache_size = %d\n", func, num_backend_rows, self->cache_size);
}
- if (!internally_invoked ||
- PG_VERSION_LE(conn, 6.3))
+ if (!internally_invoked)
loopend = rcvend = TRUE;
break;
mylog("ERROR from backend in next_tuple: '%s'\n", msgbuffer);
qlog("ERROR from backend in next_tuple: '%s'\n", msgbuffer);
- if (!internally_invoked ||
- PG_VERSION_LE(conn, 6.3))
+ if (!internally_invoked)
loopend = rcvend = TRUE;
ret = FALSE;
break;
}
if (!kill_conn && !rcvend && 0 == SOCK_get_errcode(sock))
{
- if (PROTOCOL_74(ci))
+ for (;;) /* discard the result until ReadyForQuery comes */
{
- for (;;) /* discard the result until ReadyForQuery comes */
+ id = SOCK_get_id(sock);
+ if (0 != SOCK_get_errcode(sock))
+ break;
+ if (NULL != LastMessageType)
+ *LastMessageType = id;
+ response_length = SOCK_get_response_length(sock);
+ if (0 != SOCK_get_errcode(sock))
+ break;
+ if ('Z' == id) /* ready for query */
{
- id = SOCK_get_id(sock);
- if (0 != SOCK_get_errcode(sock))
- break;
- if (NULL != LastMessageType)
- *LastMessageType = id;
- response_length = SOCK_get_response_length(sock);
- if (0 != SOCK_get_errcode(sock))
- break;
- if ('Z' == id) /* ready for query */
+ EatReadyForQuery(conn);
+ qlog("%s discarded data until ReadyForQuery comes\n", __FUNCTION__);
+ if (QR_is_fetching_tuples(self))
{
- EatReadyForQuery(conn);
- qlog("%s discarded data until ReadyForQuery comes\n", __FUNCTION__);
- if (QR_is_fetching_tuples(self))
- {
- reached_eof_now = TRUE;
- QR_set_no_fetching_tuples(self);
- }
- break;
+ reached_eof_now = TRUE;
+ QR_set_no_fetching_tuples(self);
}
+ break;
}
}
- else
- kill_conn = TRUE;
}
if (0 != SOCK_get_errcode(sock))
{
Int2 field_lf;
TupleField *this_tuplefield;
KeySet *this_keyset = NULL;
- char bmp = 0,
- bitmap[MAX_FIELDS]; /* Max. len of the bitmap */
- Int2 bitmaplen; /* len of the bitmap in bytes */
- Int2 bitmap_pos;
- Int2 bitcnt;
Int4 len;
char *buffer;
int ci_num_fields = QR_NumResultCols(self); /* speed up access */
ColumnInfoClass *flds;
int effective_cols;
char tidoidbuf[32];
- ConnInfo *ci = &(QR_get_conn(self)->connInfo);
/* set the current row to read the fields into */
effective_cols = QR_NumPublicResultCols(self);
* At first the server sends a bitmap that indicates which database
* fields are null
*/
- if (PROTOCOL_74(ci))
{
int numf = SOCK_get_int(sock, sizeof(Int2));
if (effective_cols > 0)
else
{inolog("%dth record in key numf=%d\n", self->num_cached_keys, numf);}
}
- else
- {
- bitmaplen = (Int2) ci_num_fields / BYTELEN;
- if ((ci_num_fields % BYTELEN) > 0)
- bitmaplen++;
-
- SOCK_get_n_char(sock, bitmap, bitmaplen);
-
- bitmap_pos = 0;
- bitcnt = 0;
- bmp = bitmap[bitmap_pos];
- }
flds = QR_get_fields(self);
{
BOOL isnull = FALSE;
- if (!PROTOCOL_74(ci))
- {
- isnull = ((bmp & 0200) == 0);
- /* move to next bit in the bitmap */
- bitcnt++;
- if (BYTELEN == bitcnt)
- {
- bitmap_pos++;
- bmp = bitmap[bitmap_pos];
- bitcnt = 0;
- }
- else
- bmp <<= 1;
-
- if (!isnull)
- {
- /* get the length of the field (four bytes) */
- len = SOCK_get_int(sock, sizeof(Int4));
-
- /*
- * In the old protocol version, the length
- * field of an AsciiRow message includes the
- * 4-byte length field itself, while the
- * length field in the BinaryRow does not.
- */
- if (!binary)
- len -= sizeof(Int4);
- }
- }
- else
- {
- /* get the length of the field (four bytes) */
- len = SOCK_get_int(sock, sizeof(Int4));
-
- /* -1 means NULL */
- if (len < 0)
- isnull = TRUE;
+ /* get the length of the field (four bytes) */
+ len = SOCK_get_int(sock, sizeof(Int4));
- }
+ /* -1 means NULL */
+ if (len < 0)
+ isnull = TRUE;
if (isnull)
{
#define DS_SHOWOIDCOLUMN 1012
#define DS_FAKEOIDINDEX 1013
#define DRV_COMMLOG 1014
-#define DS_PG62 1016
#define IDC_DATASOURCE 1018
#define DRV_OPTIMIZER 1019
#define DS_CONNSETTINGS 1020
#define DRV_PARSE 1052
#define DRV_CANCELASFREESTMT 1053
#define IDC_OPTIONS 1054
-#define DRV_KSQO 1055
-#define DS_PG64 1057
-#define DS_PG63 1058
#define DRV_OR_DSN 1059
#define DRV_DEBUG 1060
#define DS_DISALLOWPREMATURE 1061
#define IDC_DRIVERNAME 1076
#define IDC_MANAGEDSN 1077
#define IDC_DRIVER_LIST 1078
-#define DS_PG74 1079
#define DS_NO_ROLLBACK 1080
#define DS_TRANSACTION_ROLLBACK 1081
#define DS_STATEMENT_ROLLBACK 1082
* (i.e., because it was a function or expression, etc, then do it the
* old fashioned way.
*/
- BOOL build_fi = PROTOCOL_74(ci) && (NULL != pfNullable || NULL != pfSqlType);
+ BOOL build_fi = (NULL != pfNullable || NULL != pfSqlType);
fi = NULL;
if (!SC_pre_execute_ok(stmt, build_fi, icol, func))
{
BOOL build_fi = FALSE;
fi = NULL;
- if (PROTOCOL_74(ci))
+ switch (fDescType)
{
- switch (fDescType)
- {
- case SQL_COLUMN_OWNER_NAME:
- case SQL_COLUMN_TABLE_NAME:
- case SQL_COLUMN_TYPE:
- case SQL_COLUMN_TYPE_NAME:
- case SQL_COLUMN_AUTO_INCREMENT:
+ case SQL_COLUMN_OWNER_NAME:
+ case SQL_COLUMN_TABLE_NAME:
+ case SQL_COLUMN_TYPE:
+ case SQL_COLUMN_TYPE_NAME:
+ case SQL_COLUMN_AUTO_INCREMENT:
#if (ODBCVER >= 0x0300)
- case SQL_DESC_NULLABLE:
- case SQL_DESC_BASE_TABLE_NAME:
- case SQL_DESC_BASE_COLUMN_NAME:
+ case SQL_DESC_NULLABLE:
+ case SQL_DESC_BASE_TABLE_NAME:
+ case SQL_DESC_BASE_COLUMN_NAME:
#else
- case SQL_COLUMN_NULLABLE:
+ case SQL_COLUMN_NULLABLE:
#endif /* ODBCVER */
- case SQL_COLUMN_UPDATABLE:
- case 1212: /* SQL_CA_SS_COLUMN_KEY ? */
- build_fi = TRUE;
- break;
- }
+ case SQL_COLUMN_UPDATABLE:
+ case 1212: /* SQL_CA_SS_COLUMN_KEY ? */
+ build_fi = TRUE;
+ break;
}
if (!SC_pre_execute_ok(stmt, build_fi, col_idx, func))
return SQL_ERROR;
if (!stmt_updatable)
value = SQL_ATTR_READONLY;
else
- value = fi ? (fi->updatable ? SQL_ATTR_WRITE : SQL_ATTR_READONLY) : (QR_get_attid(res, col_idx) > 0 ? SQL_ATTR_WRITE : (PROTOCOL_74(ci) ? SQL_ATTR_READONLY : SQL_ATTR_READWRITE_UNKNOWN));
+ value = fi ? (fi->updatable ? SQL_ATTR_WRITE : SQL_ATTR_READONLY) : (QR_get_attid(res, col_idx) > 0 ? SQL_ATTR_WRITE : SQL_ATTR_READONLY);
if (SQL_ATTR_READONLY != value)
{
const char *name = fi ? SAFE_NAME(fi->column_name) : QR_get_fieldname(res, col_idx);
ConnectionClass *conn = SC_get_conn(stmt);
SQLLEN i;
int j, rowc, rcnt = 0;
- BOOL prepare;
OID oid;
UInt4 blocknum;
SQLLEN kres_ridx;
char *qval = NULL, *sval = NULL;
int keys_per_fetch = 10;
- prepare = PG_VERSION_GE(conn, 7.3);
for (i = SC_get_rowset_start(stmt), kres_ridx = GIdx2KResIdx(i, stmt, res), rowc = 0;; i++)
{
if (i >= limitrow)
{
size_t allen;
- if (prepare)
+ if (res->reload_count > 0)
+ keys_per_fetch = res->reload_count;
+ else
{
- if (res->reload_count > 0)
- keys_per_fetch = res->reload_count;
+ char planname[32];
+ int j;
+ QResultClass *qres;
+
+ if (rows_per_fetch >= pre_fetch_count * 2)
+ keys_per_fetch = pre_fetch_count;
else
+ keys_per_fetch = rows_per_fetch;
+ if (!keys_per_fetch)
+ keys_per_fetch = 2;
+ lodlen = strlen(stmt->load_statement);
+ sprintf(planname, "_KEYSET_%p", res);
+ allen = 8 + strlen(planname) +
+ 3 + 4 * keys_per_fetch + 1
+ + 1 + 2 + lodlen + 20 +
+ 4 * keys_per_fetch + 1;
+ SC_MALLOC_return_with_error(qval, char, allen,
+ stmt, "Couldn't alloc qval", -1);
+ sprintf(qval, "PREPARE \"%s\"", planname);
+ sval = strchr(qval, '\0');
+ for (j = 0; j < keys_per_fetch; j++)
{
- char planname[32];
- int j;
- QResultClass *qres;
-
- if (rows_per_fetch >= pre_fetch_count * 2)
- keys_per_fetch = pre_fetch_count;
+ if (j == 0)
+ strcpy(sval, "(tid");
else
- keys_per_fetch = rows_per_fetch;
- if (!keys_per_fetch)
- keys_per_fetch = 2;
- lodlen = strlen(stmt->load_statement);
- sprintf(planname, "_KEYSET_%p", res);
- allen = 8 + strlen(planname) +
- 3 + 4 * keys_per_fetch + 1
- + 1 + 2 + lodlen + 20 +
- 4 * keys_per_fetch + 1;
- SC_MALLOC_return_with_error(qval, char, allen,
- stmt, "Couldn't alloc qval", -1);
- sprintf(qval, "PREPARE \"%s\"", planname);
- sval = strchr(qval, '\0');
- for (j = 0; j < keys_per_fetch; j++)
- {
- if (j == 0)
- strcpy(sval, "(tid");
- else
- strcpy(sval, ",tid");
- sval = strchr(sval, '\0');
- }
- sprintf(sval, ") as %s where ctid in ", stmt->load_statement);
+ strcpy(sval, ",tid");
sval = strchr(sval, '\0');
- for (j = 0; j < keys_per_fetch; j++)
- {
- if (j == 0)
- strcpy(sval, "($1");
- else
- sprintf(sval, ",$%d", j + 1);
- sval = strchr(sval, '\0');
- }
- strcpy(sval, ")");
- qres = CC_send_query(conn, qval, NULL, 0, stmt);
- if (QR_command_maybe_successful(qres))
- {
- res->reload_count = keys_per_fetch;
- }
+ }
+ sprintf(sval, ") as %s where ctid in ", stmt->load_statement);
+ sval = strchr(sval, '\0');
+ for (j = 0; j < keys_per_fetch; j++)
+ {
+ if (j == 0)
+ strcpy(sval, "($1");
else
- {
- SC_set_error(stmt, STMT_EXEC_ERROR, "Prepare for Data Load Error", func);
- rcnt = -1;
- QR_Destructor(qres);
- break;
- }
+ sprintf(sval, ",$%d", j + 1);
+ sval = strchr(sval, '\0');
+ }
+ strcpy(sval, ")");
+ qres = CC_send_query(conn, qval, NULL, 0, stmt);
+ if (QR_command_maybe_successful(qres))
+ {
+ res->reload_count = keys_per_fetch;
+ }
+ else
+ {
+ SC_set_error(stmt, STMT_EXEC_ERROR, "Prepare for Data Load Error", func);
+ rcnt = -1;
QR_Destructor(qres);
+ break;
}
- allen = 25 + 23 * keys_per_fetch;
- }
- else
- {
- keys_per_fetch = pre_fetch_count;
- lodlen = strlen(stmt->load_statement);
- allen = lodlen + 20 + 23 * keys_per_fetch;
+ QR_Destructor(qres);
}
+ allen = 25 + 23 * keys_per_fetch;
+
SC_REALLOC_return_with_error(qval, char, allen,
stmt, "Couldn't alloc qval", -1);
}
sscanf(cmdstr, "INSERT %u %d", &oid, &addcnt) == 2 &&
addcnt == 1)
{
- ConnectionClass *conn = SC_get_conn(stmt);
RETCODE qret;
+ const char * tidval = NULL;
if (0 != oid)
poid = &oid;
qret = SQL_NO_DATA_FOUND;
- if (PG_VERSION_GE(conn, 7.2))
- {
- const char * tidval = NULL;
- if (NULL != tres->backend_tuples &&
- 1 == QR_get_num_cached_tuples(tres))
- tidval = QR_get_value_backend_text(tres, 0, 0);
- qret = SC_pos_newload(stmt, poid, TRUE, tidval);
- if (SQL_ERROR == qret)
- return qret;
- }
+ if (NULL != tres->backend_tuples &&
+ 1 == QR_get_num_cached_tuples(tres))
+ tidval = QR_get_value_backend_text(tres, 0, 0);
+ qret = SC_pos_newload(stmt, poid, TRUE, tidval);
+ if (SQL_ERROR == qret)
+ return qret;
+
if (SQL_NO_DATA_FOUND == qret)
{
qret = SC_pos_newload(stmt, poid, FALSE, NULL);
}
rv->_errormsg_ = NULL;
rv->errornumber = 0;
- rv->reverse = FALSE;
}
return rv;
}
if (self->socket != (SOCKETFD) -1)
{
SOCK_put_char(self, 'X');
- if (PG_PROTOCOL_74 == self->pversion)
- SOCK_put_int(self, 4, 4);
+ SOCK_put_int(self, 4, 4);
SOCK_flush_output(self);
closesocket(self->socket);
}
}
}
-#define REVERSE_SHORT(val) ((val & 0xff) << 8) | (val >> 8)
-#define REVERSE_INT(val) ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | (val >> 24)
-
int
SOCK_get_int(SocketClass *self, short len)
{
unsigned short buf;
SOCK_get_n_char(self, (char *) &buf, len);
- if (self->reverse)
- return REVERSE_SHORT(ntohs(buf));
- else
- return ntohs(buf);
+ return ntohs(buf);
}
case 4:
unsigned int buf;
SOCK_get_n_char(self, (char *) &buf, len);
- if (self->reverse)
- return REVERSE_INT(htonl(buf));
- else
- return ntohl(buf);
+ return ntohl(buf);
}
default:
{
case 2:
rsv = htons((unsigned short) value);
- if (self->reverse)
- rsv = REVERSE_SHORT(rsv);
SOCK_put_n_char(self, (char *) &rsv, 2);
return;
case 4:
rv = htonl((unsigned int) value);
- if (self->reverse)
- rv = REVERSE_INT(rv);
SOCK_put_n_char(self, (char *) &rv, 4);
return;
}
if (peek)
return self->buffer_in[self->buffer_read_in];
- if (PG_PROTOCOL_74 == self->pversion)
- self->reslen--;
+ self->reslen--;
return self->buffer_in[self->buffer_read_in++];
}
if (buf)
memcpy(buf + n - rest, self->buffer_in + self->buffer_read_in, rlen);
rest -= rlen;
- if (PG_PROTOCOL_74 == self->pversion)
- self->reslen -= rlen;
+ self->reslen -= rlen;
self->buffer_read_in += rlen;
}
{
int leng = -1;
- if (PG_PROTOCOL_74 == self->pversion)
- {
- leng = SOCK_get_int(self, 4) - 4;
- self->reslen = leng;
- }
+ leng = SOCK_get_int(self, 4) - 4;
+ self->reslen = leng;
return leng;
}
gss_name_t gtarg_nam; /* GSS target name */
#endif /* USE_GSS */
- char reverse; /* used to handle Postgres 6.2 protocol
- * (reverse byte order) */
char keepalive; /* TCP keepalive */
int keepalive_idle;
int keepalive_interval;
ardopts = SC_get_ARDF(stmt);
ARD_AllocBookmark(ardopts);
- stmt->stmt_size_limit = CC_get_max_query_len(conn);
/* Save the handle for later */
stmt->phstmt = phstmt;
static void SC_clear_parse_status(StatementClass *self, ConnectionClass *conn)
{
self->parse_status = STMT_PARSE_NONE;
- if (PG_VERSION_LT(conn, 7.2))
- {
- SC_set_checked_hasoids(self, TRUE);
- self->num_key_fields = PG_NUM_NORMAL_KEYS;
- }
}
static void SC_init_discard_output_params(StatementClass *self)
rv->statement = NULL;
rv->stmt_with_params = NULL;
rv->load_statement = NULL;
- rv->execute_statement = NULL;
- rv->stmt_size_limit = -1;
rv->statement_type = STMT_TYPE_UNKNOWN;
rv->currTuple = -1;
}
/*
- * Initialize stmt_with_params, load_statement and execute_statement
- * member pointer deallocating corresponding prepared plan.
- * Also initialize statement member pointer if specified.
+ * Initialize stmt_with_params and load_statement member pointer
+ * deallocating corresponding prepared plan. Also initialize
+ * statement member pointer if specified.
*/
RETCODE
SC_initialize_stmts(StatementClass *self, BOOL initializeOriginal)
free(self->statement);
self->statement = NULL;
}
- if (self->execute_statement)
- {
- free(self->execute_statement);
- self->execute_statement = NULL;
- }
self->prepare = NON_PREPARE_STATEMENT;
SC_set_prepared(self, NOT_YET_PREPARED);
self->statement_type = STMT_TYPE_UNKNOWN; /* unknown */
if (issue_begin)
{
mylog(" about to begin a transaction on statement = %p\n", self);
- if (PG_VERSION_GE(conn, 7.1))
- qflag |= GO_INTO_TRANSACTION;
- else if (!CC_begin(conn))
- {
- SC_set_error(self, STMT_EXEC_ERROR, "Could not begin a transaction", func);
- goto cleanup;
- }
+ qflag |= GO_INTO_TRANSACTION;
}
/* self->status = STMT_EXECUTING; */
{
case PREPARING_PERMANENTLY:
case PREPARED_PERMANENTLY:
- if (PROTOCOL_74(ci))
- use_extended_protocol = TRUE;
+ use_extended_protocol = TRUE;
break;
case PREPARING_TEMPORARILY:
case PREPARED_TEMPORARILY:
}
}
-inolog("!!%p->SC_is_concat_pre=%x res=%p\n", self, self->miscinfo, res);
+inolog("!!%p->miscinfo=%x res=%p\n", self, self->miscinfo, res);
/*
* special handling of result for keyset driven cursors.
* Use the columns info of the 1st query and
res = tres;
}
}
- /* skip the result of PREPARE in 'PREPARE ..:EXECUTE ..' call */
- else if (SC_is_concat_prepare_exec(self))
- {
- tres = res->next;
-inolog("res->next=%p\n", tres);
- res->next = NULL;
- if (res != SC_get_Result(self))
- QR_Destructor(res);
- SC_set_Result(self, tres);
- res = tres;
- SC_set_prepared(self, PREPARED_PERMANENTLY);
- SC_no_concat_prepare_exec(self);
- }
}
}
else
char *stmt_with_params; /* statement after parameter
* substitution */
- Int4 stmt_size_limit; /* PG restriction */
SQLLEN exec_start_row;
SQLLEN exec_end_row;
SQLLEN exec_current_row;
po_ind_t updatable;
SQLLEN diag_row_count;
char *load_statement; /* to (re)load updatable individual rows */
- char *execute_statement; /* to execute the prepared plans */
Int4 from_pos;
Int4 where_pos;
SQLLEN last_fetch_count_include_ommitted;
NON_PREPARE_STATEMENT = 0
, PREPARE_STATEMENT = 1
, PREPARE_BY_THE_DRIVER = (1L << 1)
- , USING_PREPARE_COMMAND = (2L << 1)
, NAMED_PARSE_REQUEST = (3L << 1)
, PARSE_TO_EXEC_ONCE = (4L << 1)
, PARSE_REQ_FOR_INFO = (5L << 1)
#define SC_set_fetchcursor(a) (a->miscinfo |= (1L << 1))
#define SC_no_fetchcursor(a) (a->miscinfo &= ~(1L << 1))
#define SC_is_fetchcursor(a) ((a->miscinfo & (1L << 1)) != 0)
-#define SC_set_concat_prepare_exec(a) (a->miscinfo |= (1L << 2))
-#define SC_no_concat_prepare_exec(a) (a->miscinfo &= ~(1L << 2))
-#define SC_is_concat_prepare_exec(a) ((a->miscinfo & (1L << 2)) != 0)
#define SC_set_with_hold(a) (a->miscinfo |= (1L << 3))
#define SC_set_without_hold(a) (a->miscinfo &= ~(1L << 3))
#define SC_is_with_hold(a) ((a->miscinfo & (1L << 3)) != 0)