. Fix a select() blocking bug in *nix environment.
authorHiroshi Inoue <inoue@tpf.co.jp>
Sat, 26 Aug 2006 22:54:17 +0000 (22:54 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Sat, 26 Aug 2006 22:54:17 +0000 (22:54 +0000)
. Fix some header files depedecies.

connection.c
inouealc.c
psqlodbc.h
qresult.c
qresult.h
results.c
socket.c
statement.c
version.h
win_unicode.c

index f22a4bcfbb154674ca9f5eb66aa6a5300ef269f1..4cb7ce03c6d5302cc5bab7e6dd7c1518d6dd4fab 100644 (file)
@@ -23,6 +23,7 @@
 #include <errno.h>
 #endif /* WIN32 */
 
+#include <libpq-fe.h>
 #include "environ.h"
 #include "socket.h"
 #include "statement.h"
@@ -813,7 +814,7 @@ inolog("new_format=%d\n", new_format);
        CC_on_abort(self, abort_opt);
    if (res)
    {
-       QR_set_rstatus(res, PGRES_FATAL_ERROR);
+       QR_set_rstatus(res, PORES_FATAL_ERROR);
        QR_set_message(res, msgbuf);
        QR_set_aborted(res, TRUE);
    }
@@ -897,7 +898,7 @@ handle_notice_message(ConnectionClass *self, char *msgbuf, int buflen, char *sql
    if (res)
    {
        if (QR_command_successful(res))
-           QR_set_rstatus(res, PGRES_NONFATAL_ERROR);
+           QR_set_rstatus(res, PORES_NONFATAL_ERROR);
        QR_set_notice(res, msgbuf);  /* will dup this string */
    }
 
@@ -1517,7 +1518,7 @@ inolog("Ekita\n");
 
        res = CC_send_query(self, " ", NULL, 0, NULL);
        if (res == NULL ||
-           (QR_get_rstatus(res) != PGRES_EMPTY_QUERY &&
+           (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);
@@ -2190,7 +2191,7 @@ inolog("Discarded the first SAVEPOINT\n");
                    }
 
                    if (QR_command_successful(res))
-                       QR_set_rstatus(res, PGRES_COMMAND_OK);
+                       QR_set_rstatus(res, PORES_COMMAND_OK);
                    QR_set_command(res, cmdbuffer);
                    query_completed = TRUE;
                    mylog("send_query: returning res = %x\n", res);
@@ -2239,7 +2240,7 @@ inolog("Discarded the first SAVEPOINT\n");
                {
                    CC_set_errornumber(self, CONNECTION_BACKEND_CRAZY);
                    QR_set_message(res, "Unexpected protocol character from backend (send_query - I)");
-                   QR_set_rstatus(res, PGRES_FATAL_ERROR);
+                   QR_set_rstatus(res, PORES_FATAL_ERROR);
                    ReadyToReturn = TRUE;
                    retres = cmdres;
                    break;
@@ -2247,7 +2248,7 @@ inolog("Discarded the first SAVEPOINT\n");
                else
                {
                    /* We return the empty query */
-                   QR_set_rstatus(res, PGRES_EMPTY_QUERY);
+                   QR_set_rstatus(res, PORES_EMPTY_QUERY);
                }
                if (empty_reqs > 0)
                {
@@ -2305,7 +2306,7 @@ inolog("Discarded the first SAVEPOINT\n");
                    {
                        CC_set_error(self, CONNECTION_COULD_NOT_RECEIVE, QR_get_message(res), func);
                        ReadyToReturn = TRUE;
-                       if (PGRES_FATAL_ERROR == QR_get_rstatus(res))
+                       if (PORES_FATAL_ERROR == QR_get_rstatus(res))
                            retres = cmdres;
                        else
                            retres = NULL;
@@ -2336,7 +2337,7 @@ inolog("Discarded the first SAVEPOINT\n");
                    res->next = QR_Constructor();
                    res = res->next;
                }
-               QR_set_rstatus(res, PGRES_COPY_IN);
+               QR_set_rstatus(res, PORES_COPY_IN);
                ReadyToReturn = TRUE;
                retres = cmdres;
                break;
@@ -2346,7 +2347,7 @@ inolog("Discarded the first SAVEPOINT\n");
                    res->next = QR_Constructor();
                    res = res->next;
                }
-               QR_set_rstatus(res, PGRES_COPY_OUT);
+               QR_set_rstatus(res, PORES_COPY_OUT);
                ReadyToReturn = TRUE;
                retres = cmdres;
                break;
index d010ada13cdf2925313f7dd0e363eef3a8b6f481..4505f2c0ef3d8016df760128684eb1d2492e43ea 100644 (file)
@@ -14,7 +14,9 @@
 #undef memset
 */
 #include   "misc.h"
+#ifdef WIN32
 #include   <malloc.h>
+#endif /* WIN32 */
 #ifdef _DEBUG
 #include   <stdlib.h>
 #define    _CRTDBG_MAP_ALLOC
index 3b2e7905acd40ee78b0a64ef4abdc51761515cbb..743e5af85c4cbef0c15b30dc94f705e35f999862 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Comments:       See "notice.txt" for copyright and license information.
  *
- * $Id: psqlodbc.h,v 1.104 2006/08/24 15:03:56 hinoue Exp $
+ * $Id: psqlodbc.h,v 1.105 2006/08/26 22:54:16 hinoue Exp $
  *
  */
 
@@ -64,7 +64,7 @@
 #include "iodbc.h"
 #include "isql.h"
 #include "isqlext.h"
-#endif
+#endif /* WIN32 */
 
 #if defined(WIN32)
 #include <odbcinst.h>
 #include "gpps.h"
 #endif
 
-/* #include <libpq-fe.h> */
-
 #ifdef __cplusplus
 extern "C" {
 #endif
-#ifndef WIN32
+
 #define Int4 int
 #define UInt4 unsigned int
 #define Int2 short
 #define UInt2 unsigned short
 
+#ifndef WIN32
 #if !defined(WITH_UNIXODBC) && !defined(WITH_IODBC)
 typedef float SFLOAT;
 typedef double SDOUBLE;
-#endif
+#endif /* WITH_UNIXODBC */
 
 #ifndef CALLBACK
 #define CALLBACK
-#endif
+#endif /* CALLBACK */
+#endif /* WIN32 */
 
-#else
-#define Int4 int
-#define UInt4 unsigned int
-#define Int2 short
-#define UInt2 unsigned short
-#endif
+#ifndef LIBPQ_FE_H
 typedef    UInt4   Oid;
+#endif /* LIBPQ_FE_H */
 
 #ifndef WIN32
 #define stricmp strcasecmp
@@ -119,7 +115,7 @@ typedef UInt4   Oid;
 #define strnicmp _strnicmp
 #define stricmp _stricmp
 #define vsnprintf _vsnprintf
-#endif
+#endif /* WIN32 */
 
 #ifndef    SQL_ATTR_APP_ROW_DESC
 #define    SQL_ATTR_APP_ROW_DESC   10010
index fb130b9f278c9257286a73d834ed8ee5dc823f0e..3c96c38e5c21fe341c70cce96ec1eac601a1b4ae 100644 (file)
--- a/qresult.c
+++ b/qresult.c
@@ -131,7 +131,7 @@ QR_Constructor()
 
    if (rv != NULL)
    {
-       rv->rstatus = PGRES_EMPTY_QUERY;
+       rv->rstatus = PORES_EMPTY_QUERY;
        rv->pstatus = 0;
 
        /* construct the column info */
@@ -521,7 +521,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor)
        {
            if (!cursor)
            {
-               QR_set_rstatus(self, PGRES_INTERNAL_ERROR);
+               QR_set_rstatus(self, PORES_INTERNAL_ERROR);
                QR_set_message(self, "Internal Error -- no cursor for fetch");
                return FALSE;
            }
@@ -535,14 +535,14 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor)
         */
        if (CI_read_fields(self->fields, QR_get_conn(self)))
        {
-           QR_set_rstatus(self, PGRES_FIELDS_OK);
+           QR_set_rstatus(self, PORES_FIELDS_OK);
            self->num_fields = CI_get_num_fields(self->fields);
            if (QR_haskeyset(self))
                self->num_fields -= self->num_key_fields;
        }
        else
        {
-           QR_set_rstatus(self, PGRES_BAD_RESPONSE);
+           QR_set_rstatus(self, PORES_BAD_RESPONSE);
            QR_set_message(self, "Error reading field information");
            return FALSE;
        }
@@ -570,7 +570,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor)
        {
            if (self->keyset = (KeySet *) calloc(sizeof(KeySet), tuple_size), !self->keyset)
            {
-               QR_set_rstatus(self, PGRES_FATAL_ERROR);
+               QR_set_rstatus(self, PORES_FATAL_ERROR);
                QR_set_message(self, "Could not get memory for tuple cache.");
                return FALSE;
            }
@@ -596,7 +596,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor)
 
        if (!CI_read_fields(NULL, QR_get_conn(self)))
        {
-           QR_set_rstatus(self, PGRES_BAD_RESPONSE);
+           QR_set_rstatus(self, PORES_BAD_RESPONSE);
            QR_set_message(self, "Error reading field information");
            return FALSE;
        }
@@ -649,7 +649,7 @@ QR_close(QResultClass *self)
 
            if (!CC_commit(conn))
            {
-               QR_set_rstatus(self, PGRES_FATAL_ERROR);
+               QR_set_rstatus(self, PORES_FATAL_ERROR);
                QR_set_message(self, "Error ending transaction.");
                ret = FALSE;
            }
@@ -699,7 +699,7 @@ inolog("QR_get_tupledata num_fields=%d\n", self->num_fields);
 
    if (!QR_read_a_tuple_from_db(self, (char) binary))
    {
-       QR_set_rstatus(self, PGRES_BAD_RESPONSE);
+       QR_set_rstatus(self, PORES_BAD_RESPONSE);
        QR_set_message(self, "Error reading the tuple");
        return FALSE;
    }
@@ -1071,7 +1071,7 @@ inolog("clear obsolete %d tuples\n", num_backend_rows);
            res = CC_send_query(conn, fetch, &qi, 0, stmt);
            if (!QR_command_maybe_successful(res))
            {
-               QR_set_rstatus(self, PGRES_FATAL_ERROR);
+               QR_set_rstatus(self, PORES_FATAL_ERROR);
                QR_set_message(self, "Error fetching next group.");
                return FALSE;
            }
@@ -1231,7 +1231,7 @@ inolog("id='%c' response_length=%d\n", id, response_length);
                mylog("%s: Unexpected result from backend: id = '%c' (%d)\n", func, id, id);
                qlog("%s: Unexpected result from backend: id = '%c' (%d)\n", func, id, id);
                QR_set_message(self, "Unexpected result from backend. It probably crashed");
-               QR_set_rstatus(self, PGRES_FATAL_ERROR);
+               QR_set_rstatus(self, PORES_FATAL_ERROR);
                CC_on_abort(conn, CONN_DEAD);
                ret = FALSE;
                rcvend = TRUE;
index b5db09ab7925072b310f47d1db9ca394a2e36703..5fdf72489077be7f5d19030218049a4f3211164d 100644 (file)
--- a/qresult.h
+++ b/qresult.h
 #include "columninfo.h"
 #include "tuple.h"
 
-#include   <libpq-fe.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef ExecStatusType QueryResultCode;
-#define    PGRES_FIELDS_OK     100
-#define    PGRES_INTERNAL_ERROR    (PGRES_FIELDS_OK + 1)
+typedef
+enum   QueryResultCode_
+{
+   PORES_EMPTY_QUERY = 0,
+   PORES_COMMAND_OK,   /* a query command that doesn't return
+                * anything was executed properly by the backend */
+   PORES_TUPLES_OK,    /* a query command that returns tuples
+                * was executed properly by the backend, PGresult
+                * contains the resulttuples */
+   PORES_COPY_OUT,
+   PORES_COPY_IN,
+   PORES_BAD_RESPONSE, /* an unexpected response was recv'd from
+                * the backend */
+   PORES_NONFATAL_ERROR,
+   PORES_FATAL_ERROR,
+   PORES_FIELDS_OK = 100,  /* field information from a query was
+                * successful */
+   /* PORES_END_TUPLES, */
+   PORES_INTERNAL_ERROR
+} QueryResultCode;
 
 enum
 {
@@ -132,9 +147,9 @@ enum {
 #define QR_set_field_info_v(self, field_num, name, adtid, adtsize)  (CI_set_field_info(self->fields, field_num, name, adtid, adtsize, -1, 0, 0))
 
 /* status macros */
-#define QR_command_successful(self)    (self && !(self->rstatus == PGRES_BAD_RESPONSE || self->rstatus == PGRES_NONFATAL_ERROR || self->rstatus == PGRES_FATAL_ERROR))
-#define QR_command_maybe_successful(self) (self && !(self->rstatus == PGRES_BAD_RESPONSE || self->rstatus == PGRES_FATAL_ERROR))
-#define QR_command_nonfatal(self)  ( self->rstatus == PGRES_NONFATAL_ERROR)
+#define QR_command_successful(self)    (self && !(self->rstatus == PORES_BAD_RESPONSE || self->rstatus == PORES_NONFATAL_ERROR || self->rstatus == PORES_FATAL_ERROR))
+#define QR_command_maybe_successful(self) (self && !(self->rstatus == PORES_BAD_RESPONSE || self->rstatus == PORES_FATAL_ERROR))
+#define QR_command_nonfatal(self)  ( self->rstatus == PORES_NONFATAL_ERROR)
 #define QR_set_conn(self, conn_)           ( self->conn = conn_ )
 #define QR_set_rstatus(self, condition)        ( self->rstatus = condition )
 #define QR_set_sqlstatus(self, status)     strcpy(self->sqlstatus, status)
@@ -224,7 +239,7 @@ Int4        getNthValid(const QResultClass *self, Int4 sta, UWORD orientation, UInt4 n
 do { \
    if (t = (tp *) malloc(s), NULL == t) \
    { \
-       QR_set_rstatus(a, PGRES_FATAL_ERROR); \
+       QR_set_rstatus(a, PORES_FATAL_ERROR); \
        QR_set_message(a, m); \
        return r; \
    } \
@@ -233,7 +248,7 @@ do { \
 do { \
    if (t = (tp *) realloc(t, s), NULL == t) \
    { \
-       QR_set_rstatus(a, PGRES_FATAL_ERROR); \
+       QR_set_rstatus(a, PORES_FATAL_ERROR); \
        QR_set_message(a, m); \
        return r; \
    } \
index 9d7caeac4f5f34db1052932fa2b260948e5512b3..0922ddaebf8013578e7730787bcb21bbcf102415 100644 (file)
--- a/results.c
+++ b/results.c
@@ -3527,7 +3527,7 @@ QR_get_rowstart_in_cache(res), SC_get_rowset_start(stmt), stmt->options.cursor_t
                        res->num_fields * sizeof(TupleField) * tuple_size);
                    if (!res->backend_tuples)
                    {
-                       SC_set_error(stmt, QR_set_rstatus(res, PGRES_FATAL_ERROR), "Out of memory while reading tuples.", func);
+                       SC_set_error(stmt, QR_set_rstatus(res, PORES_FATAL_ERROR), "Out of memory while reading tuples.", func);
                        QR_Destructor(qres);
                        return SQL_ERROR;
                    }
index f50d59ebe47934c751b539c39a91c32c82a432a3..b9b1ed5ba3a898b25682b68190d83d795cee778c 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -271,7 +271,7 @@ retry:
        do {
            FD_ZERO(&fds);
            FD_SET(self->socket, &fds);
-           ret = select(1, NULL, &fds, NULL, timeout > 0 ? &tm : NULL);
+           ret = select(self->socket + 1, NULL, &fds, NULL, timeout > 0 ? &tm : NULL);
            if (0 < ret)
                break;
            else if (0 == ret)
@@ -354,7 +354,7 @@ static int SOCK_wait_for_ready(SocketClass *sock, BOOL output, int retry_count)
            tm.tv_sec = retry_count;
            tm.tv_usec = 0;
        }
-       ret = select(1, output ? NULL : &fds, output ? &fds : NULL, NULL, sock->ssl ? &tm : NULL);
+       ret = select(sock->socket + 1, output ? NULL : &fds, output ? &fds : NULL, NULL, sock->ssl ? &tm : NULL);
    } while (ret < 0 && EINTR == SOCK_ERRNO);
    if (0 == ret && retry_count > MAX_RETRY_COUNT)
    {
index 46ac1f8df00492fdc25bff476939661b1d96317c..8c6e3480992608462645f9e9934ba04df84fcb82 100644 (file)
@@ -889,7 +889,7 @@ SC_pre_execute(StatementClass *self)
        if (!SC_is_pre_executable(self))
        {
            SC_set_Result(self, QR_Constructor());
-           QR_set_rstatus(SC_get_Result(self), PGRES_TUPLES_OK);
+           QR_set_rstatus(SC_get_Result(self), PORES_TUPLES_OK);
            self->inaccurate_result = TRUE;
            self->status = STMT_PREMATURE;
            num_fields = 0;
@@ -2165,7 +2165,7 @@ inolog("num_params=%d info=%d\n", stmt->num_params, num_p);
                    Int2    dummy1, dummy2;
                    int cidx;
 
-                   QR_set_rstatus(res, PGRES_FIELDS_OK);
+                   QR_set_rstatus(res, PORES_FIELDS_OK);
                    res->num_fields = CI_get_num_fields(res->fields);
                    if (QR_haskeyset(res))
                        res->num_fields -= res->num_key_fields;
@@ -2192,7 +2192,7 @@ inolog("!![%d].PGType %u->%u\n", i, ipdopts->parameters[i].PGType, CI_get_oid(re
                }
                else
                {
-                   QR_set_rstatus(res, PGRES_BAD_RESPONSE);
+                   QR_set_rstatus(res, PORES_BAD_RESPONSE);
                    QR_set_message(res, "Error reading field information");
                    rcvend = TRUE;
                }
index 7b7ce314f2ebd88fbb7f6e38deec355d932fefe8..b462d48426e3f5fdb81efa317cc3053250108c29 100644 (file)
--- a/version.h
+++ b/version.h
@@ -11,6 +11,6 @@
 
 #define POSTGRESDRIVERVERSION      "08.02.0007"
 #define POSTGRES_RESOURCE_VERSION  "08.02.0007\0"
-#define PG_DRVFILE_VERSION     8,2,0,07 
+#define PG_DRVFILE_VERSION     8,2,0,07  
 
 #endif
index 9a43b075147d3f8a788c6e244d9a40046c74a6c6..b0396d21dce9d4f2075993345737d4b1b3074d84 100644 (file)
@@ -10,7 +10,9 @@
 #include "psqlodbc.h"
 #include <stdio.h>
 #include <string.h>
+#ifdef WIN32
 #include <malloc.h>
+#endif /* WIN32 */
 
 #define    byte3check  0xfffff800
 #define    byte2_base  0x80c0