Refine oneshot exection sequence.
authorHiroshi Inoue <inoue@tpf.co.jp>
Wed, 13 Sep 2006 15:30:27 +0000 (15:30 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Wed, 13 Sep 2006 15:30:27 +0000 (15:30 +0000)
More type changes for 64 bit compilation.

bind.c
connection.c
execute.c
md5.c
multibyte.c
multibyte.h
odbcapi30.c
pgapi30.c
psqlodbc.h
statement.c
version.h

diff --git a/bind.c b/bind.c
index 3186d7e298692e7072e67bb1d897135ca18dcc0e..d6c35aae5b3fc639283796ac723e8dbe3115a92a 100644 (file)
--- a/bind.c
+++ b/bind.c
@@ -408,7 +408,7 @@ PGAPI_ParamOptions(
 
    apdopts = SC_get_APDF(stmt);
    apdopts->paramset_size = crow;
-   SC_get_IPDF(stmt)->param_processed_ptr = (UInt4 *) pirow;
+   SC_get_IPDF(stmt)->param_processed_ptr = pirow;
    return SQL_SUCCESS;
 }
 
@@ -459,7 +459,7 @@ inolog("num_params=%d,%d\n", stmt->num_params, stmt->proc_return);
    {
        const   char *sptr, *tag = NULL;
        ConnectionClass *conn = SC_get_conn(stmt);
-       int taglen;
+       size_t  taglen;
        char    tchar, bchar, escape_in_literal;
        char    in_literal = FALSE, in_identifier = FALSE,
            in_dollar_quote = FALSE, in_escape = FALSE,
index f1c8bf12ec3ae397d59c04f81521893b9616b4fe..3f14733627dcd05f06d791042ded8e31412f0846 100644 (file)
@@ -2090,7 +2090,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, UDWORD flag, St
    if (rollback_on_error)
        rollback_on_error = consider_rollback;
    query_rollback = (rollback_on_error && PG_VERSION_GE(self, 8.0));
-   if (!query_rollback && consider_rollback )
+   if (!query_rollback && consider_rollback)
    {
        if (stmt)
        {
@@ -2113,6 +2113,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, UDWORD flag, St
        CC_on_abort(self, CONN_DEAD);
        goto cleanup;
    }
+   if (stmt)
+       SC_forget_unnamed(stmt);
 
    if (PROTOCOL_74(ci))
    {
index 4e5fef20d31d3fe29ea3ae8d3811dacc38f70fe8..b2fad493e62ff48c3b873d04a78584cd807d2436 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -309,9 +309,9 @@ RETCODE Exec_with_parameters_resolved(StatementClass *stmt, BOOL *exec_end)
        {
            case USING_PREPARE_COMMAND:
            case NAMED_PARSE_REQUEST:
-#ifdef TRY_ONESHOT_PLAN
+#ifndef    BYPASS_ONESHOT_PLAN_EXECUTION
            case PARSE_TO_EXEC_ONCE:
-#endif /* TRY_ONESHOT_PLAN */
+#endif/* BYPASS_ONESHOT_PLAN_EXECUTION */
                prepare_before_exec = TRUE;
        }
    }
@@ -881,6 +881,7 @@ PGAPI_Execute(HSTMT hstmt, UWORD flag)
           parameters even in case of non-prepared statements.
         */
        BOOL    bCallPrepare = FALSE;
+       int pre_decided = stmt->prepare;
 
        ConnInfo *ci = &(conn->connInfo);
        if (NOT_YET_PREPARED == stmt->prepared &&
@@ -936,7 +937,9 @@ PGAPI_Execute(HSTMT hstmt, UWORD flag)
            if (retval = prepareParameters(stmt), SQL_ERROR == retval)
                goto cleanup;
        }
-mylog("prepareParameters end\n");
+       else
+           /* stmt->prepare = pre_decided; */ /* put back */
+mylog("prepareParameters %d end\n", stmt->prepare);
 
        if (ipdopts->param_processed_ptr)
            *ipdopts->param_processed_ptr = 0;
diff --git a/md5.c b/md5.c
index d56e6136d2ee0aedf21b109b79649d821d590437..da327e7645fa22548fc327a5cf2cefebc49a407e 100644 (file)
--- a/md5.c
+++ b/md5.c
@@ -14,7 +14,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/md5.c,v 1.11 2006/04/08 16:30:01 dpage Exp $
+ *   $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/md5.c,v 1.12 2006/09/13 15:30:27 hinoue Exp $
  */
 
 
@@ -309,7 +309,7 @@ md5_hash(const void *buff, size_t len, char *hexsum)
 {
    uint8       sum[16];
 
-   if (!calculateDigestFromBuffer((uint8 *) buff, len, sum))
+   if (!calculateDigestFromBuffer((uint8 *) buff, (uint32) len, sum))
        return false;
 
    bytesToHex(sum, hexsum);
index 266d1fb33411ed14d21b9c676b6d9f9b862d010c..7b4c96d4b3d7f1167f1cb005b9f89d95b4612e33 100644 (file)
@@ -318,11 +318,12 @@ pg_mbschr(int csc, const UCHAR *string, unsigned int character)
    return ((UCHAR *) rs);
 }
 
-int
+size_t
 pg_mbslen(int csc, const UCHAR *string)
 {
    UCHAR *s;
-   int len, cs_stat;
+   size_t  len;
+   int cs_stat;
    for (len = 0, cs_stat = 0, s = (UCHAR *) string; *s != 0; s++)
    {
        cs_stat = pg_CS_stat(cs_stat,(unsigned int) *s, csc);
@@ -517,12 +518,12 @@ int encoded_nextchar(encoded_str *encstr)
    encstr->ccst = pg_CS_stat(encstr->ccst, (unsigned int) chr, encstr->ccsc);
    return chr; 
 }
-int encoded_position_shift(encoded_str *encstr, int shift)
+ssize_t encoded_position_shift(encoded_str *encstr, size_t shift)
 {
    encstr->pos += shift; 
    return encstr->pos; 
 }
-int encoded_byte_check(encoded_str *encstr, int abspos)
+int encoded_byte_check(encoded_str *encstr, size_t abspos)
 {
    int chr;
 
index 5224338a0600fe641b15b2ca5952953d3911bcbe..1d6e831c4a3e2562867eee7e4cbf21568c299a7d 100644 (file)
@@ -78,7 +78,7 @@ typedef struct pg_CS
    UCHAR *name;
    int code;
 }pg_CS;
-extern int pg_mbslen(int ccsc, const UCHAR *string);
+extern size_t  pg_mbslen(int ccsc, const UCHAR *string);
 extern UCHAR *pg_mbschr(int ccsc, const UCHAR *string, unsigned int character);
 extern UCHAR *pg_mbsinc(int ccsc, const UCHAR *current );
 
@@ -87,7 +87,7 @@ typedef struct
 {
    int ccsc;
    const UCHAR *encstr;
-   int pos;
+   ssize_t pos;
    int ccst;
 } encoded_str;
 #define ENCODE_STATUS(enc) ((enc).ccst)
@@ -95,7 +95,7 @@ typedef struct
 void encoded_str_constr(encoded_str *encstr, int ccsc, const char *str);
 #define make_encoded_str(encstr, conn, str) encoded_str_constr(encstr, conn->ccsc, str)
 extern int encoded_nextchar(encoded_str *encstr);
-extern int encoded_position_shift(encoded_str *encstr, int shift);
-extern int encoded_byte_check(encoded_str *encstr, int abspos);
+extern ssize_t encoded_position_shift(encoded_str *encstr, size_t shift);
+extern int encoded_byte_check(encoded_str *encstr, size_t abspos);
 #define check_client_encoding(X) pg_CS_name(pg_CS_code(X))
 #endif /* __MULTIBUYTE_H__ */
index e2af58cfbd70e23a80d2239b8a11a4a429a347c4..6952f259dfdc18cfff24e3de4a9c84256aaae9da 100644 (file)
@@ -117,7 +117,9 @@ SQLColAttribute(SQLHSTMT StatementHandle,
            SQLPOINTER CharacterAttribute,
            SQLSMALLINT BufferLength,
            SQLSMALLINT *StringLength,
-#if defined(WITH_UNIXODBC) || defined(WIN32)
+#if defined(_WIN64)
+           SQLLEN *NumericAttribute
+#elif defined(WITH_UNIXODBC) || defined(WIN32)
            SQLPOINTER NumericAttribute
 #else
            SQLLEN *NumericAttribute
index 2940422959cd53f045e55e52307bccc3484cb0e1..08a8e0a1e8315029ac2bda014051f9d66a78ee97 100644 (file)
--- a/pgapi30.c
+++ b/pgapi30.c
@@ -823,7 +823,7 @@ IPDSetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
            ipdopts->param_status_ptr = (SQLUSMALLINT *) Value;
            return ret;
        case SQL_DESC_ROWS_PROCESSED_PTR:
-           ipdopts->param_processed_ptr = (UInt4 *) Value;
+           ipdopts->param_processed_ptr = (SQLUINTEGER *) Value;
            return ret;
        case SQL_DESC_COUNT:
            parameter_ibindings_set(ipdopts, CAST_PTR(SQLSMALLINT, Value), FALSE);
@@ -1513,7 +1513,7 @@ PGAPI_GetStmtAttr(HSTMT StatementHandle,
    CSTR func = "PGAPI_GetStmtAttr";
    StatementClass *stmt = (StatementClass *) StatementHandle;
    RETCODE     ret = SQL_SUCCESS;
-   int         len = 0;
+   SQLINTEGER  len = 0;
 
    mylog("%s Handle=%x %d\n", func, StatementHandle, Attribute);
    switch (Attribute)
@@ -1599,7 +1599,7 @@ PGAPI_GetStmtAttr(HSTMT StatementHandle,
            SC_set_error(stmt, DESC_INVALID_OPTION_IDENTIFIER, "Unsupported statement option (Get)", func);
            return SQL_ERROR;
        default:
-           ret = PGAPI_GetStmtOption(StatementHandle, (UWORD) Attribute, Value, &len, BufferLength);
+           ret = PGAPI_GetStmtOption(StatementHandle, (SQLSMALLINT) Attribute, Value, &len, BufferLength);
    }
    if (ret == SQL_SUCCESS && StringLength)
        *StringLength = len;
@@ -1843,7 +1843,7 @@ inolog("set ard=%x\n", stmt->ard);
            SC_get_IPDF(stmt)->param_status_ptr = (SQLUSMALLINT *) Value;
            break;
        case SQL_ATTR_PARAMS_PROCESSED_PTR:     /* 21 */
-           SC_get_IPDF(stmt)->param_processed_ptr = (UInt4 *) Value;
+           SC_get_IPDF(stmt)->param_processed_ptr = (SQLUINTEGER *) Value;
            break;
        case SQL_ATTR_PARAMSET_SIZE:    /* 22 */
            SC_get_APDF(stmt)->paramset_size = CAST_UPTR(SQLUINTEGER, Value);
index 68ec757afdc5189ad8b0e491174c1e2457668775..84fc0e93ce45d46c0bbb9db228a1b2954c74ab13 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Comments:       See "notice.txt" for copyright and license information.
  *
- * $Id: psqlodbc.h,v 1.108 2006/09/11 16:28:03 hinoue Exp $
+ * $Id: psqlodbc.h,v 1.109 2006/09/13 15:30:27 hinoue Exp $
  *
  */
 
@@ -443,5 +443,4 @@ void        debug_memory_check(void);
 CSTR   NULL_STRING = "";
 CSTR   PRINT_NULL = "(null)";
 CSTR   OID_NAME = "oid";
-#define    TRY_ONESHOT_PLAN
 #endif /* __PSQLODBC_H__ */
index f5150b41a92fe5790eb8d63252cdf46b700d33f8..701d707a82b4004fa5994cccd537c3e34f312e1d 100644 (file)
@@ -1615,9 +1615,9 @@ SC_execute(StatementClass *self)
    {
        switch (SC_get_prepare_method(self))
        {
-#ifdef TRY_ONESHOT_PLAN
+#ifndef    BYPASS_ONESHOT_PLAN_EXECUTION
        case PARSE_TO_EXEC_ONCE:
-#endif /* TRY_ONESHOT_PLAN */
+#endif /* BYPASS_ONESHOT_PLAN_EXECUTION */
            case NAMED_PARSE_REQUEST:
                use_extended_protocol = TRUE;
        }
@@ -2044,6 +2044,29 @@ SC_log_error(const char *func, const char *desc, const StatementClass *self)
  * Extended Query 
  */
 
+static BOOL
+RequestStart(StatementClass *stmt, ConnectionClass *conn, const char *func)
+{
+   BOOL    ret = TRUE;
+
+   if (SC_accessed_db(stmt))
+       return TRUE;
+   if (SQL_ERROR == SetStatementSvp(stmt))
+   {
+       char    emsg[128];
+
+       snprintf(emsg, sizeof(emsg), "internal savepoint error in %s", func);
+       SC_set_error(stmt, STMT_INTERNAL_ERROR, emsg, func);
+       return FALSE;
+   }
+   if (!CC_is_in_trans(conn) && !CC_is_in_autocommit(conn))
+   {
+       if (ret = CC_begin(conn), !ret)
+           return ret;
+   }
+   return ret;
+}
+
 BOOL
 SendBindRequest(StatementClass *stmt, const char *plan_name)
 {
@@ -2052,6 +2075,8 @@ SendBindRequest(StatementClass *stmt, const char *plan_name)
    SocketClass *sock = conn->sock;
 
    mylog("%s: plan_name=%s\n", func, plan_name);
+   if (!RequestStart(stmt, conn, func))
+       return FALSE;
    if (!BuildBindRequest(stmt, plan_name))
        return FALSE;
 
@@ -2074,17 +2099,11 @@ QResultClass *SendSyncAndReceive(StatementClass *stmt, QResultClass *res, const
    IPDFields   *ipdopts;
    QResultClass    *newres = NULL;
 
-   if (CC_is_in_trans(conn) && !SC_accessed_db(stmt))
-   { 
-       if (SQL_ERROR == SetStatementSvp(stmt))
-       {
-           SC_set_error(stmt, STMT_INTERNAL_ERROR, "internal savepoint error in SendSynAndReceive", func);
-           return FALSE;
-       }
-   }
+   if (!RequestStart(stmt, conn, func))
+       return NULL;
 
-   SOCK_put_char(sock, 'S');   /* Sync message */
-   SOCK_put_int(sock, 4, 4);
+   SOCK_put_char(sock, 'S');   /* Sync command */
+   SOCK_put_int(sock, 4, 4);   /* length */
    SOCK_flush_output(sock);
 
    if (!res)
@@ -2119,6 +2138,11 @@ inolog(" response_length=%d\n", response_length);
                        mylog("%s: reached eof now\n", func);
                        QR_set_reached_eof(res);
                    }
+                   else
+                   {
+                       res->recent_processed_row_count = 0;
+                       sscanf(msgbuffer, "%*s %d", &res->recent_processed_row_count);
+                   }
                }
                break;
            case 'E': /* ErrorMessage */
@@ -2248,19 +2272,10 @@ SendParseRequest(StatementClass *stmt, const char *plan_name, const char *query)
    size_t      pileng, leng;
 
    mylog("%s: plan_name=%s query=%s\n", func, plan_name, query);
-   if (CC_is_in_trans(conn) && !SC_accessed_db(stmt))
-   { 
-       if (SQL_ERROR == SetStatementSvp(stmt))
-       {
-           SC_set_error(stmt, STMT_INTERNAL_ERROR, "internal savepoint error in SendParseRequest", func);
-           return FALSE;
-       }
-   }
-   else if (!CC_is_in_trans(conn) && !CC_is_in_autocommit(conn))
-   {
-       CC_begin(conn);
-   }
-   SOCK_put_char(sock, 'P');
+   if (!RequestStart(stmt, conn, func))
+       return FALSE;
+
+   SOCK_put_char(sock, 'P'); /* Parse command */
    if (SOCK_get_errcode(sock) != 0)
    {
        CC_set_error(conn, CONNECTION_COULD_NOT_SEND, "Could not send P request to backend", func);
@@ -2272,7 +2287,7 @@ SendParseRequest(StatementClass *stmt, const char *plan_name, const char *query)
    if (!stmt->discard_output_params)
        pileng += sizeof(UInt4) * (stmt->num_params - stmt->proc_return); 
    leng = strlen(plan_name) + 1 + strlen(query) + 1 + pileng;
-   SOCK_put_int(sock, (Int4) (leng + 4), 4);
+   SOCK_put_int(sock, (Int4) (leng + 4), 4); /* length */
 inolog("parse leng=%d\n", leng);
    SOCK_put_string(sock, plan_name);
    SOCK_put_string(sock, query);
@@ -2305,28 +2320,23 @@ SendDescribeRequest(StatementClass *stmt, const char *plan_name)
    BOOL        sockerr = FALSE;
 
    mylog("%s:plan_name=%s\n", func, plan_name);
-   if (CC_is_in_trans(conn) && !SC_accessed_db(stmt))
-   {
-       if (SQL_ERROR == SetStatementSvp(stmt))
-       {
-           SC_set_error(stmt, STMT_INTERNAL_ERROR, "internal savepoint error", func);
-           return FALSE;
-       }
-   }
-   SOCK_put_char(sock, 'D');
+   if (!RequestStart(stmt, conn, func))
+       return FALSE;
+
+   SOCK_put_char(sock, 'D'); /* Describe command */
    if (SOCK_get_errcode(sock) != 0)
        sockerr = TRUE;
    if (!sockerr)
    {
        leng = 1 + strlen(plan_name) + 1;
-       SOCK_put_int(sock, (Int4) (leng + 4), 4);
+       SOCK_put_int(sock, (Int4) (leng + 4), 4); /* length */
        if (SOCK_get_errcode(sock) != 0)
            sockerr = TRUE;
    }
    if (!sockerr)
    {
 inolog("describe leng=%d\n", leng);
-       SOCK_put_char(sock, 'S');
+       SOCK_put_char(sock, 'S'); /* describe a prepared statement */
        if (SOCK_get_errcode(sock) != 0)
            sockerr = TRUE;
    }
@@ -2359,16 +2369,18 @@ SendExecuteRequest(StatementClass *stmt, const char *plan_name, UInt4 count)
    if (sock = conn->sock, !sock)   return FALSE;
 
    mylog("%s: plan_name=%s count=%d\n", func, plan_name, count);
-   if (CC_is_in_trans(conn) && !SC_accessed_db(stmt))
+   switch (stmt->prepared)
    {
-       if (SQL_ERROR == SetStatementSvp(stmt))
-       {
-           SC_set_error(stmt, STMT_INTERNAL_ERROR, "internal savepoint error", func);
+       case NOT_YET_PREPARED:
+       case ONCE_DESCRIBED:
+           SC_set_error(stmt, STMT_EXEC_ERROR, "about to execute a non-prepared statement", func);
            return FALSE;
-       }
    }
-   SOCK_put_char(sock, 'E');
-   SC_forget_unnamed(stmt); /* don't reuse the unnamed plan */
+   if (!RequestStart(stmt, conn, func))
+       return FALSE;
+
+   SOCK_put_char(sock, 'E'); /* Execute command */
+   SC_forget_unnamed(stmt); /* unnamed plans are unavailable */
    if (SOCK_get_errcode(sock) != 0)
    {
        CC_set_error(conn, CONNECTION_COULD_NOT_SEND, "Could not send E Request to backend", func);
@@ -2377,13 +2389,13 @@ SendExecuteRequest(StatementClass *stmt, const char *plan_name, UInt4 count)
    }
 
    leng = strlen(plan_name) + 1 + 4;
-   SOCK_put_int(sock, (Int4) (leng + 4), 4);
+   SOCK_put_int(sock, (Int4) (leng + 4), 4); /* length */
 inolog("execute leng=%d\n", leng);
    SOCK_put_string(sock, plan_name);
    SOCK_put_int(sock, count, 4);
-   if (0 == count) /* Close message */
+   if (0 == count) /* will send a Close portal command */
    {
-       SOCK_put_char(sock, 'C');
+       SOCK_put_char(sock, 'C');   /* Close command */
        if (SOCK_get_errcode(sock) != 0)
        {
            CC_set_error(conn, CONNECTION_COULD_NOT_SEND, "Could not send C Request to backend", func);
@@ -2392,9 +2404,9 @@ inolog("execute leng=%d\n", leng);
        }
 
        leng = 1 + strlen(plan_name) + 1;
-       SOCK_put_int(sock, (Int4) (leng + 4), 4); /* Close portal */
+       SOCK_put_int(sock, (Int4) (leng + 4), 4); /* length */
 inolog("Close leng=%d\n", leng);
-       SOCK_put_char(sock, 'P');
+       SOCK_put_char(sock, 'P');   /* Portal */
        SOCK_put_string(sock, plan_name);
    }
 
@@ -2405,7 +2417,7 @@ BOOL  SendSyncRequest(ConnectionClass *conn)
 {
    SocketClass *sock = conn->sock;
 
-   SOCK_put_char(sock, 'S');   /* Sync message */
+   SOCK_put_char(sock, 'S');   /* Sync command */
    SOCK_put_int(sock, 4, 4);
    SOCK_flush_output(sock);
 
index 6e512c40441f03a5131db83bf7e621c08e0414f6..ef39613994969dd704f95d4def456e7e05f3d003 100644 (file)
--- a/version.h
+++ b/version.h
@@ -11,6 +11,6 @@
 
 #define POSTGRESDRIVERVERSION      "08.02.0102"
 #define POSTGRES_RESOURCE_VERSION  "08.02.0102\0"
-#define PG_DRVFILE_VERSION     8,2,01,02
+#define PG_DRVFILE_VERSION     8,2,01,02 
 
 #endif