1) Handle SQL_C_CHAR under Unicode driver.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 11 Feb 2003 16:57:50 +0000 (16:57 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Tue, 11 Feb 2003 16:57:50 +0000 (16:57 +0000)
2) Improve ? SQLSpecialColumns for views.

convert.c
execute.c
info.c
odbcapi30w.c
pgtypes.c
pgtypes.h

index 63c72a86e748ccafdfb59098fa689434367bcfd1..e090bf18e498221971edbf8cb3c003b52c32b8cf 100644 (file)
--- a/convert.c
+++ b/convert.c
 #include "connection.h"
 #include "pgapifunc.h"
 
+#if defined(UNICODE_SUPPORT) && defined(WIN32)
+#define    WIN_UNICODE_SUPPORT
+#endif
+
 #ifdef __CYGWIN__
 #define TIMEZONE_GLOBAL _timezone
 #elif  defined(WIN32) || defined(HAVE_INT_TIMEZONE)
@@ -378,6 +382,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
    int         bind_row = stmt->bind_row;
    int         bind_size = opts->bind_size;
    int         result = COPY_OK;
+   ConnectionClass     *conn = SC_get_conn(stmt);
 #ifdef HAVE_LOCALE_H
    char saved_locale[256];
 #endif /* HAVE_LOCALE_H */
@@ -390,6 +395,10 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
 #ifdef UNICODE_SUPPORT
    BOOL    wchanged =   FALSE;
 #endif /* UNICODE_SUPPORT */
+#ifdef WIN_UNICODE_SUPPORT
+   SQLWCHAR    *allocbuf = NULL;
+   Int4        wstrlen;    
+#endif /* WIN_UNICODE_SUPPORT */
 
    if (stmt->current_col >= 0)
    {
@@ -516,7 +525,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
            }
            if (strnicmp(value, "invalid", 7) != 0)
            {
-               BOOL        bZone = (field_type != PG_TYPE_TIMESTAMP_NO_TMZONE && PG_VERSION_GE(SC_get_conn(stmt), 7.2));
+               BOOL        bZone = (field_type != PG_TYPE_TIMESTAMP_NO_TMZONE && PG_VERSION_GE(conn, 7.2));
                int         zone;
 
                /*
@@ -654,10 +663,11 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
    rgbValueBindRow = (char *) rgbValue + rgbValueOffset;
 
 #ifdef UNICODE_SUPPORT
-   if (fCType == SQL_C_CHAR || fCType == SQL_C_WCHAR)
+   if (fCType == SQL_C_CHAR || fCType == SQL_C_WCHAR
 #else
-   if (fCType == SQL_C_CHAR)
+   if (fCType == SQL_C_CHAR
 #endif /* UNICODE_SUPPORT */
+       || fCType == INTERNAL_ASIS_TYPE)
    {
        /* Special character formatting as required */
 
@@ -724,7 +734,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
                    pbic = &opts->bindings[stmt->current_col];
                if (pbic->data_left < 0)
                {
-                   BOOL lf_conv = SC_get_conn(stmt)->connInfo.lf_conversion;
+                   BOOL lf_conv = conn->connInfo.lf_conversion;
 #ifdef UNICODE_SUPPORT
                    if (fCType == SQL_C_WCHAR)
                    {
@@ -741,12 +751,27 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
                        changed = TRUE;
                    }
                    else
+#ifdef WIN_UNICODE_SUPPORT
+                   if (fCType == SQL_C_CHAR)
+                   {
+                       wstrlen = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0);
+                       allocbuf = (SQLWCHAR *) malloc(2 * (wstrlen + 1));
+                       wstrlen = utf8_to_ucs2_lf(neut_str, -1, lf_conv, allocbuf, wstrlen + 1);
+                       len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) allocbuf, wstrlen, NULL, 0, NULL, NULL);
+                       changed = TRUE;
+                   }
+                   else
+#endif /* WIN_UNICODE_SUPPORT */
                        /* convert linefeeds to carriage-return/linefeed */
                        len = convert_linefeeds(neut_str, NULL, 0, lf_conv, &changed);
                    if (cbValueMax == 0)        /* just returns length
                                                 * info */
                    {
                        result = COPY_RESULT_TRUNCATED;
+#ifdef WIN_UNICODE_SUPPORT
+                       if (allocbuf)
+                           free(allocbuf);
+#endif /* WIN_UNICODE_SUPPORT */
                        break;
                    }
                    if (!pbic->ttlbuf)
@@ -772,6 +797,15 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
                            len *= 2; 
                        }
                        else
+#ifdef WIN_UNICODE_SUPPORT
+                       if (fCType == SQL_C_CHAR)
+                       {
+                           len = WideCharToMultiByte(CP_ACP, 0, allocbuf, wstrlen, pbic->ttlbuf, pbic->ttlbuflen, NULL, NULL);
+                           free(allocbuf);
+                           allocbuf = NULL;
+                       }
+                       else
+#endif /* WIN_UNICODE_SUPPORT */
                            convert_linefeeds(neut_str, pbic->ttlbuf, pbic->ttlbuflen, lf_conv, &changed);
                        ptr = pbic->ttlbuf;
                        pbic->ttlbufused = len;
@@ -2439,6 +2473,11 @@ ResolveOneParam(QueryBuild *qb)
        CVT_APPEND_STR(qb, "NULL");
        return SQL_SUCCESS;
    }
+   /* Handle DEFAULT_PARAM parameter data */
+   if (used == SQL_DEFAULT_PARAM)
+   {
+       return SQL_SUCCESS;
+   }
 
    /*
     * If no buffer, and it's not null, then what the hell is it? Just
@@ -2468,7 +2507,7 @@ ResolveOneParam(QueryBuild *qb)
 
    /* replace DEFAULT with something we can use */
    if (param_ctype == SQL_C_DEFAULT)
-       param_ctype = sqltype_to_default_ctype(param_sqltype);
+       param_ctype = sqltype_to_default_ctype(conn, param_sqltype);
 
    allocbuf = buf = NULL;
    param_string[0] = '\0';
@@ -2488,8 +2527,30 @@ ResolveOneParam(QueryBuild *qb)
    switch (param_ctype)
    {
        case SQL_C_BINARY:
+           buf = buffer;
+           break;
        case SQL_C_CHAR:
+#ifdef WIN_UNICODE_SUPPORT
+           switch (param_sqltype)
+           {
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
+               case SQL_WLONGVARCHAR:
+                   if (SQL_NTS == used)
+                       used = strlen(buffer);
+                   allocbuf = malloc(2 * (used + 1));
+                   used = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer,
+                       used, (LPWSTR) allocbuf, used + 1);
+                   buf = ucs2_to_utf8((SQLWCHAR *) allocbuf, used, &used);
+                   free(allocbuf);
+                   allocbuf = buf;
+                   break;
+               default:
+                   buf = buffer;
+           }
+#else
            buf = buffer;
+#endif /* WIN_UNICODE_SUPPORT */
            break;
 
 #ifdef UNICODE_SUPPORT
index eb455b77501f4e1d518e64d44ff9a3b8929e7d37..d4060f355c26e481c65ef0c9fc6eaa6337690a6a 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -1018,7 +1018,7 @@ PGAPI_PutData(
        {
            Int2        ctype = current_param->CType;
            if (ctype == SQL_C_DEFAULT)
-               ctype = sqltype_to_default_ctype(current_iparam->SQLType);
+               ctype = sqltype_to_default_ctype(conn, current_iparam->SQLType);
 
 #ifdef UNICODE_SUPPORT
            if (SQL_NTS == cbValue && SQL_C_WCHAR == ctype)
@@ -1088,7 +1088,7 @@ PGAPI_PutData(
            Int2    ctype = current_param->CType;
 
            if (ctype == SQL_C_DEFAULT)
-               ctype = sqltype_to_default_ctype(current_iparam->SQLType);
+               ctype = sqltype_to_default_ctype(conn, current_iparam->SQLType);
            buffer = current_param->EXEC_buffer;
            if (old_pos = *current_param->EXEC_used, SQL_NTS == old_pos)
            {
diff --git a/info.c b/info.c
index ea7af74c72a55f8864ef14963c312e514389c7d3..554a75b3f8276c698fcedc185b538002042a422c 100644 (file)
--- a/info.c
+++ b/info.c
@@ -1239,6 +1239,7 @@ PGAPI_Tables(
                view,
                systable;
    int         i;
+   SWORD           internal_asis_type = SQL_C_CHAR;
 
    mylog("%s: entering...stmt=%u scnm=%x len=%d\n", func, stmt, szTableOwner, cbTableOwner);
 
@@ -1393,7 +1394,11 @@ PGAPI_Tables(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(htbl_stmt, 1, SQL_C_CHAR,
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
+   result = PGAPI_BindCol(htbl_stmt, 1, internal_asis_type,
                           table_name, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1403,7 +1408,7 @@ PGAPI_Tables(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(htbl_stmt, 2, SQL_C_CHAR,
+   result = PGAPI_BindCol(htbl_stmt, 2, internal_asis_type,
                           table_owner, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1412,7 +1417,7 @@ PGAPI_Tables(
        PGAPI_FreeStmt(htbl_stmt, SQL_DROP);
        return SQL_ERROR;
    }
-   result = PGAPI_BindCol(htbl_stmt, 3, SQL_C_CHAR,
+   result = PGAPI_BindCol(htbl_stmt, 3, internal_asis_type,
                           relkind_or_hasrules, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1652,6 +1657,7 @@ PGAPI_Columns(
    BOOL        relisaview;
    ConnInfo   *ci;
    ConnectionClass *conn;
+   SWORD       internal_asis_type = SQL_C_CHAR;
 
 
    mylog("%s: entering...stmt=%u scnm=%x len=%d\n", func, stmt, szTableOwner, cbTableOwner);
@@ -1667,6 +1673,10 @@ PGAPI_Columns(
 
    conn = SC_get_conn(stmt);
    ci = &(conn->connInfo);
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
 
    /*
     * Create the query to find out the columns (Note: pre 6.3 did not
@@ -1741,7 +1751,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 1, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 1, internal_asis_type,
                           table_owner, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1751,7 +1761,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 2, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 2, internal_asis_type,
                           table_name, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1761,7 +1771,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 3, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 3, internal_asis_type,
                           field_name, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1781,7 +1791,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 5, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 5, internal_asis_type,
                           field_type_name, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1821,7 +1831,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 9, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 9, internal_asis_type,
                           not_null, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1831,7 +1841,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 10, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 10, internal_asis_type,
                           relhasrules, MAX_INFO_STRING, NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -1841,7 +1851,7 @@ PGAPI_Columns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 11, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 11, internal_asis_type,
                           relkind, sizeof(relkind), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2165,8 +2175,9 @@ PGAPI_SpecialColumns(
    StatementClass *col_stmt;
    char        columns_query[INFO_INQUIRY_LEN];
    RETCODE     result;
-   char        relhasrules[MAX_INFO_STRING], relkind[8];
+   char        relhasrules[MAX_INFO_STRING], relkind[8], relhasoids[8];
    BOOL        relisaview;
+   SWORD       internal_asis_type = SQL_C_CHAR;
 
    mylog("%s: entering...stmt=%u scnm=%x len=%d colType=%d\n", func, stmt, szTableOwner, cbTableOwner, fColType);
 
@@ -2177,19 +2188,24 @@ PGAPI_SpecialColumns(
    }
    conn = SC_get_conn(stmt);
    ci = &(conn->connInfo);
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
 
    stmt->manual_result = TRUE;
 
    /*
     * 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)
-       sprintf(columns_query, "select c.relhasrules, c.relkind "
-           "from pg_namespace u, pg_class c where "
+       strcat(columns_query, " from pg_namespace u, pg_class c where "
            "u.oid = c.relnamespace");
    else
-       sprintf(columns_query, "select c.relhasrules, c.relkind "
-           "from pg_user u, pg_class c where "
+       strcat(columns_query, " from pg_user u, pg_class c where "
            "u.usesysid = c.relowner");
 
    /* TableName cannot contain a string search pattern */
@@ -2222,8 +2238,8 @@ PGAPI_SpecialColumns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 1, SQL_C_CHAR,
-                          relhasrules, MAX_INFO_STRING, NULL);
+   result = PGAPI_BindCol(hcol_stmt, 1, internal_asis_type,
+                   relhasrules, sizeof(relhasrules), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
        SC_error_copy(stmt, col_stmt);
@@ -2232,7 +2248,7 @@ PGAPI_SpecialColumns(
        return SQL_ERROR;
    }
 
-   result = PGAPI_BindCol(hcol_stmt, 2, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 2, internal_asis_type,
                    relkind, sizeof(relkind), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2241,6 +2257,19 @@ PGAPI_SpecialColumns(
        PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
        return SQL_ERROR;
    }
+   relhasoids[0] = '1';
+   if (PG_VERSION_GE(conn, 7.2))
+   {
+       result = PGAPI_BindCol(hcol_stmt, 3, internal_asis_type,
+                   relhasoids, sizeof(relhasoids), NULL);
+       if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+       {
+           SC_error_copy(stmt, col_stmt);
+           SC_log_error(func, "", stmt);
+           PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
+           return SQL_ERROR;
+       }
+   }
 
    result = PGAPI_Fetch(hcol_stmt);
    if (PG_VERSION_GE(conn, 7.1))
@@ -2263,11 +2292,39 @@ PGAPI_SpecialColumns(
    QR_set_field_info(res, 6, "SCALE", PG_TYPE_INT2, 2);
    QR_set_field_info(res, 7, "PSEUDO_COLUMN", PG_TYPE_INT2, 2);
 
-   if (!relisaview)
+   if (relisaview)
+   {
+       /* there's no oid for views */
+       if (fColType == SQL_BEST_ROWID)
+       {
+           return SQL_NO_DATA_FOUND;
+       }
+       else if (fColType == SQL_ROWVER)
+       {
+           Int2        the_type = PG_TYPE_TID;
+
+           row = (TupleNode *) malloc(sizeof(TupleNode) + (8 - 1) *sizeof(TupleField));
+
+           set_tuplefield_null(&row->tuple[0]);
+           set_tuplefield_string(&row->tuple[1], "ctid");
+           set_tuplefield_int2(&row->tuple[2], pgtype_to_concise_type(stmt, the_type));
+           set_tuplefield_string(&row->tuple[3], pgtype_to_name(stmt, the_type));
+           set_tuplefield_int4(&row->tuple[4], pgtype_column_size(stmt, the_type, PG_STATIC, PG_STATIC));
+           set_tuplefield_int4(&row->tuple[5], pgtype_buffer_length(stmt, the_type, PG_STATIC, PG_STATIC));
+           set_tuplefield_int2(&row->tuple[6], pgtype_decimal_digits(stmt, the_type, PG_STATIC));
+           set_tuplefield_int2(&row->tuple[7], SQL_PC_NOT_PSEUDO);
+
+           QR_add_tuple(res, row);
+inolog("Add ctid\n");
+       }
+   }
+   else
    {
        /* use the oid value for the rowid */
        if (fColType == SQL_BEST_ROWID)
        {
+           if (relhasoids[0] != '1')
+               return SQL_NO_DATA_FOUND;
            row = (TupleNode *) malloc(sizeof(TupleNode) + (8 - 1) *sizeof(TupleField));
 
            set_tuplefield_int2(&row->tuple[0], SQL_SCOPE_SESSION);
@@ -2303,45 +2360,6 @@ PGAPI_SpecialColumns(
            }
        }
    }
-   else
-   {
-       /* use the oid value for the rowid */
-       if (fColType == SQL_BEST_ROWID)
-       {
-           row = (TupleNode *) malloc(sizeof(TupleNode) + (8 - 1) *sizeof(TupleField));
-
-           set_tuplefield_int2(&row->tuple[0], SQL_SCOPE_SESSION);
-           set_tuplefield_string(&row->tuple[1], "oid");
-           set_tuplefield_int2(&row->tuple[2], pgtype_to_concise_type(stmt, PG_TYPE_OID));
-           set_tuplefield_string(&row->tuple[3], "OID");
-           set_tuplefield_int4(&row->tuple[4], pgtype_column_size(stmt, PG_TYPE_OID, PG_STATIC, PG_STATIC));
-           set_tuplefield_int4(&row->tuple[5], pgtype_buffer_length(stmt, PG_TYPE_OID, PG_STATIC, PG_STATIC));
-           set_tuplefield_int2(&row->tuple[6], pgtype_decimal_digits(stmt, PG_TYPE_OID, PG_STATIC));
-           set_tuplefield_int2(&row->tuple[7], SQL_PC_NOT_PSEUDO);
-
-           QR_add_tuple(res, row);
-inolog("Add oid\n");
-
-       }
-       else if (fColType == SQL_ROWVER)
-       {
-           Int2        the_type = PG_TYPE_TID;
-
-           row = (TupleNode *) malloc(sizeof(TupleNode) + (8 - 1) *sizeof(TupleField));
-
-           set_tuplefield_null(&row->tuple[0]);
-           set_tuplefield_string(&row->tuple[1], "ctid");
-           set_tuplefield_int2(&row->tuple[2], pgtype_to_concise_type(stmt, the_type));
-           set_tuplefield_string(&row->tuple[3], pgtype_to_name(stmt, the_type));
-           set_tuplefield_int4(&row->tuple[4], pgtype_column_size(stmt, the_type, PG_STATIC, PG_STATIC));
-           set_tuplefield_int4(&row->tuple[5], pgtype_buffer_length(stmt, the_type, PG_STATIC, PG_STATIC));
-           set_tuplefield_int2(&row->tuple[6], pgtype_decimal_digits(stmt, the_type, PG_STATIC));
-           set_tuplefield_int2(&row->tuple[7], SQL_PC_NOT_PSEUDO);
-
-           QR_add_tuple(res, row);
-inolog("Add ctid\n");
-       }
-   }
 
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
@@ -2394,6 +2412,7 @@ PGAPI_Statistics(
    char        error = TRUE;
    ConnInfo   *ci;
    char        buf[256];
+   SWORD       internal_asis_type = SQL_C_CHAR;
 
    mylog("%s: entering...stmt=%u scnm=%x len=%d\n", func, stmt, szTableOwner, cbTableOwner);
 
@@ -2408,6 +2427,10 @@ PGAPI_Statistics(
 
    conn = SC_get_conn(stmt);
    ci = &(conn->connInfo);
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
 
    if (res = QR_Constructor(), !res)
    {
@@ -2487,7 +2510,7 @@ PGAPI_Statistics(
        PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
        goto SEEYA;
    }
-   result = PGAPI_BindCol(hcol_stmt, 4, SQL_C_CHAR,
+   result = PGAPI_BindCol(hcol_stmt, 4, internal_asis_type,
                         column_name, sizeof(column_name), &column_name_len);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2576,7 +2599,7 @@ PGAPI_Statistics(
    }
 
    /* bind the index name column */
-   result = PGAPI_BindCol(hindx_stmt, 1, SQL_C_CHAR,
+   result = PGAPI_BindCol(hindx_stmt, 1, internal_asis_type,
                           index_name, MAX_INFO_STRING, &index_name_len);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2598,7 +2621,7 @@ PGAPI_Statistics(
 
    }
    /* bind the "is unique" column */
-   result = PGAPI_BindCol(hindx_stmt, 3, SQL_C_CHAR,
+   result = PGAPI_BindCol(hindx_stmt, 3, internal_asis_type,
                           isunique, sizeof(isunique), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2609,7 +2632,7 @@ PGAPI_Statistics(
    }
 
    /* bind the "is clustered" column */
-   result = PGAPI_BindCol(hindx_stmt, 4, SQL_C_CHAR,
+   result = PGAPI_BindCol(hindx_stmt, 4, internal_asis_type,
                           isclustered, sizeof(isclustered), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2621,7 +2644,7 @@ PGAPI_Statistics(
    }
 
    /* bind the "is hash" column */
-   result = PGAPI_BindCol(hindx_stmt, 5, SQL_C_CHAR,
+   result = PGAPI_BindCol(hindx_stmt, 5, internal_asis_type,
                           ishash, sizeof(ishash), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2632,7 +2655,7 @@ PGAPI_Statistics(
 
    }
 
-   result = PGAPI_BindCol(hindx_stmt, 6, SQL_C_CHAR,
+   result = PGAPI_BindCol(hindx_stmt, 6, internal_asis_type,
                    relhasrules, sizeof(relhasrules), NULL);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -2843,6 +2866,7 @@ PGAPI_PrimaryKeys(
    int         qno,
                qstart,
                qend;
+   SWORD       internal_asis_type = SQL_C_CHAR;
 
    mylog("%s: entering...stmt=%u scnm=%x len=%d\n", func, stmt, szTableOwner, cbTableOwner);
 
@@ -2891,6 +2915,10 @@ PGAPI_PrimaryKeys(
    tbl_stmt = (StatementClass *) htbl_stmt;
 
    conn = SC_get_conn(stmt);
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
    pktab[0] = '\0';
    make_string(szTableName, cbTableName, pktab);
    if (pktab[0] == '\0')
@@ -2904,7 +2932,7 @@ PGAPI_PrimaryKeys(
    if (conn->schema_support)
        schema_strcat(pkscm, "%.*s", szTableOwner, cbTableOwner, szTableName, cbTableName, conn);
 
-   result = PGAPI_BindCol(htbl_stmt, 1, SQL_C_CHAR,
+   result = PGAPI_BindCol(htbl_stmt, 1, internal_asis_type,
                           attname, MAX_INFO_STRING, &attname_len);
    if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
    {
@@ -3329,6 +3357,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
    SWORD       trig_nargs,
                upd_rule_type = 0,
                del_rule_type = 0;
+   SWORD       internal_asis_type = SQL_C_CHAR;
 
 #if (ODBCVER >= 0x0300)
    SWORD       defer_type;
@@ -3420,6 +3449,10 @@ char     schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
    make_string(szFkTableName, cbFkTableName, fk_table_needed);
 
    conn = SC_get_conn(stmt);
+#ifdef UNICODE_SUPPORT
+   if (conn->unicode)
+       internal_asis_type = INTERNAL_ASIS_TYPE;
+#endif /* UNICODE_SUPPORT */
    pkey_text = fkey_text = NULL;
    pkey_alloced = fkey_alloced = FALSE;
 
@@ -3433,81 +3466,79 @@ char        schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
        if (conn->schema_support)
        {
            schema_strcat(schema_needed, "%.*s", szFkTableOwner, cbFkTableOwner, szFkTableName, cbFkTableName, conn);   
-           sprintf(tables_query,
-               "SELECT pt1.tgargs, "
-               "       pt1.tgnargs, "
-               "       pt1.tgdeferrable, "
-               "       pt1.tginitdeferred, "
+           sprintf(tables_query, "SELECT   pt.tgargs, "
+               "       pt.tgnargs, "
+               "       pt.tgdeferrable, "
+               "       pt.tginitdeferred, "
+               "       pp1.proname, "
                "       pp2.proname, "
-               "       pp3.proname, "
+               "       pc.oid, "
                "       pc1.oid, "
-               "       pc2.oid, "
-               "       pc2.relname, "
-               "       pn2.nspname "
-               "FROM   pg_class pc1, "
-               "       pg_class pc2, "
+               "       pc1.relname, "
+               "       pn.nspname "
+               "FROM   pg_class pc, "
                "       pg_proc pp1, "
                "       pg_proc pp2, "
-               "       pg_proc pp3, "
                "       pg_trigger pt1, "
                "       pg_trigger pt2, "
-               "       pg_trigger pt3, "
-               "       pg_namespace pn1, "
-               "       pg_namespace pn2 "
-               "WHERE  pt1.tgrelid = pc1.oid "
+               "       pg_proc pp, "
+               "       pg_trigger pt, "
+               "       pg_class pc1, "
+               "       pg_namespace pn "
+               "       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.tgconstrrelid = pc1.oid "
-               "AND pp2.oid = pt2.tgfoid "
-               "AND pt3.tgfoid = pp3.oid "
-               "AND pt3.tgconstrrelid = pc1.oid "
-               "AND pc1.relname='%s' "
-               "AND pn1.oid = pc1.relnamespace "
-               "AND pn1.nspname = '%s' "
-               "AND pp1.proname LIKE '%%ins' "
-               "AND pp2.proname LIKE '%%upd' "
-               "AND pp3.proname LIKE '%%del' "
-               "AND pt2.tgrelid=pt1.tgconstrrelid "
-               "AND pt2.tgconstrname=pt1.tgconstrname "
-               "AND pt3.tgrelid=pt1.tgconstrrelid "
-               "AND pt3.tgconstrname=pt1.tgconstrname "
-               "AND pt1.tgconstrrelid=pc2.oid "
-               "AND pc2.relnamespace=pn2.oid ",
+               "AND pt2.tgfoid = pp2.oid "
+               "AND pt2.tgconstrrelid = pc.oid "
+               "AND ((pc.relname='%s') "
+               "AND (pn1.oid = pc.relnamespace) "
+               "AND (pn1.nspname = '%s') "
+               "AND (pp.proname LIKE '%%ins') "
+               "AND (pp1.proname LIKE '%%upd') "
+               "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))",
                fk_table_needed, schema_needed);
        }
        else
-           sprintf(tables_query,
-               "SELECT pt1.tgargs, "
-               "       pt1.tgnargs, "
-               "       pt1.tgdeferrable, "
-               "       pt1.tginitdeferred, "
+           sprintf(tables_query, "SELECT   pt.tgargs, "
+               "       pt.tgnargs, "
+               "       pt.tgdeferrable, "
+               "       pt.tginitdeferred, "
+               "       pp1.proname, "
                "       pp2.proname, "
-               "       pp3.proname, "
+               "       pc.oid, "
                "       pc1.oid, "
-               "       pc2.oid, "
-               "       pc2.relname "
-               "FROM   pg_class pc1, "
-               "       pg_class pc2, "
+               "       pc1.relname "
+               "FROM   pg_class pc, "
                "       pg_proc pp1, "
                "       pg_proc pp2, "
-               "       pg_proc pp3, "
-               "       pg_trigger pt1 "
+               "       pg_trigger pt1, "
                "       pg_trigger pt2, "
-               "       pg_trigger pt3 "
-               "WHERE  pt1.tgrelid = pc1.oid "
+               "       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.tgconstrrelid = pc1.oid "
-               "AND pp2.oid = pt2.tgfoid "
-               "AND pt3.tgfoid = pp3.oid "
-               "AND pt3.tgconstrrelid = pc1.oid "
-               "AND pc1.relname='%s' "
-               "AND pp1.proname LIKE '%%ins' "
-               "AND pp2.proname LIKE '%%upd' "
-               "AND pp3.proname LIKE '%%del' "
-               "AND pt2.tgrelid=pt1.tgconstrrelid "
-               "AND pt2.tgconstrname=pt1.tgconstrname "
-               "AND pt3.tgrelid=pt1.tgconstrrelid "
-               "AND pt3.tgconstrname=pt1.tgconstrname "
-               "AND pt1.tgconstrrelid=pc2.oid ",
+               "AND pt2.tgfoid = pp2.oid "
+               "AND pt2.tgconstrrelid = pc.oid "
+               "AND ((pc.relname='%s') "
+               "AND (pp.proname LIKE '%%ins') "
+               "AND (pp1.proname LIKE '%%upd') "
+               "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)) ",
                fk_table_needed);
 
        result = PGAPI_ExecDirect(htbl_stmt, tables_query, strlen(tables_query));
@@ -3540,7 +3571,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 3, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 3, internal_asis_type,
                         trig_deferrable, sizeof(trig_deferrable), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3550,7 +3581,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 4, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 4, internal_asis_type,
                     trig_initdeferred, sizeof(trig_initdeferred), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3560,7 +3591,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 5, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 5, internal_asis_type,
                               upd_rule, sizeof(upd_rule), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3570,7 +3601,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 6, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 6, internal_asis_type,
                               del_rule, sizeof(del_rule), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3598,7 +3629,7 @@ char      schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            PGAPI_FreeStmt(htbl_stmt, SQL_DROP);
            return SQL_ERROR;
        }
-       result = PGAPI_BindCol(htbl_stmt, 9, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 9, internal_asis_type,
                    pk_table_fetched, TABLE_NAME_STORAGE_LEN, NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3608,18 +3639,18 @@ char        schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
            return SQL_ERROR;
        }
 
-if (conn->schema_support)
-{
-       result = PGAPI_BindCol(htbl_stmt, 10, SQL_C_CHAR,
-                   schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
-       if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+       if (conn->schema_support)
        {
-           SC_error_copy(stmt, tbl_stmt);
-           SC_log_error(func, "", stmt);
-           PGAPI_FreeStmt(htbl_stmt, SQL_DROP);
-           return SQL_ERROR;
+           result = PGAPI_BindCol(htbl_stmt, 10, internal_asis_type,
+                   schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
+           if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+           {
+               SC_error_copy(stmt, tbl_stmt);
+               SC_log_error(func, "", stmt);
+               PGAPI_FreeStmt(htbl_stmt, SQL_DROP);
+               return SQL_ERROR;
+           }
        }
-}
 
        result = PGAPI_Fetch(htbl_stmt);
        if (result == SQL_NO_DATA_FOUND)
@@ -3641,7 +3672,7 @@ if (conn->schema_support)
            return SQL_ERROR;
        }
 
-       keyresult = PGAPI_BindCol(hpkey_stmt, 4, SQL_C_CHAR,
+       keyresult = PGAPI_BindCol(hpkey_stmt, 4, internal_asis_type,
                                  pkey, sizeof(pkey), NULL);
        if (keyresult != SQL_SUCCESS)
        {
@@ -3811,75 +3842,77 @@ if (conn->schema_support)
        if (conn->schema_support)
        {
            schema_strcat(schema_needed, "%.*s", szPkTableOwner, cbPkTableOwner, szPkTableName, cbPkTableName, conn);   
-           sprintf(tables_query,
-               "SELECT pt1.tgargs, "
-               "       pt1.tgnargs, "
-               "       pt1.tgdeferrable, "
-               "       pt1.tginitdeferred, "
+           sprintf(tables_query, "SELECT   pt.tgargs, "
+               "       pt.tgnargs, "
+               "       pt.tgdeferrable, "
+               "       pt.tginitdeferred, "
+               "       pp.proname, "
                "       pp1.proname, "
-               "       pp2.proname, "
+               "       pc.oid, "
                "       pc1.oid, "
-               "       pc2.oid, "
-               "       pc2.relname, "
-               "       pn2.nspname "
-               "FROM   pg_class pc1, "
+               "       pc1.relname, "
+               "       pn.nspname "
+               "FROM   pg_class pc, "
+               "       pg_class pc1, "
                "       pg_class pc2, "
-               "       pg_class pc3, "
+               "       pg_proc pp, "
                "       pg_proc pp1, "
-               "       pg_proc pp2, "
+               "       pg_trigger pt, "
                "       pg_trigger pt1, "
                "       pg_trigger pt2, "
-               "       pg_trigger pt3, "
-               "       pg_namespace pn1, "
-               "       pg_namespace pn2 "
-               "WHERE  pt1.tgconstrrelid = pc1.oid "
-               "   AND pt1.tgrelid = pc2.oid "
-               "   AND pt2.tgfoid = pp2.oid "
+               "       pg_namespace pn "
+               "       pg_namespace pn1 "
+               "WHERE  pt.tgconstrrelid = pc.oid "
+               "   AND pt.tgrelid = pc1.oid "
+               "   AND pt1.tgfoid = pp1.oid "
+               "   AND pt1.tgconstrrelid = pc1.oid "
                "   AND pt2.tgconstrrelid = pc2.oid "
-               "   AND pt3.tgconstrrelid = pc3.oid "
-               "   AND pt3.tgfoid = pp1.oid "
-               "   AND pc3.oid = pt1.tgrelid "
-               "   AND pc1.relname='%s' "
-               "   AND pn1.oid = pc1.relnamespace "
-               "   AND pn1.nspname = '%s' "
-               "   AND pp1.proname LIKE '%%upd' "
-               "   AND pp2.proname LIKE '%%del'"
-               "   AND pt2.tgrelid = pt1.tgconstrrelid "
-               "   AND pt3.tgrelid = pt1.tgconstrrelid "
-               "   AND pn2.oid = pc2.relnamespace ",
+               "   AND pt2.tgfoid = pp.oid "
+               "   AND pc2.oid = pt.tgrelid "
+               "   AND ("
+               "        (pc.relname='%s') "
+               "   AND  (pn1.oid = pc.relnamespace) "
+               "   AND  (pn1.nspname = '%s') "
+               "   AND  (pp.proname Like '%%upd') "
+               "   AND  (pp1.proname Like '%%del')"
+               "   AND  (pt1.tgrelid = pt.tgconstrrelid) "
+               "   AND  (pt2.tgrelid = pt.tgconstrrelid) "
+               "   AND (pn.oid = pc1.relnamespace) "
+               "       )",
                pk_table_needed, schema_needed);
        }
        else
-           sprintf(tables_query,
-               "SELECT pt1.tgargs, "
-               "       pt1.tgnargs, "
-               "       pt1.tgdeferrable, "
-               "       pt1.tginitdeferred, "
+           sprintf(tables_query, "SELECT   pt.tgargs, "
+               "       pt.tgnargs, "
+               "       pt.tgdeferrable, "
+               "       pt.tginitdeferred, "
+               "       pp.proname, "
                "       pp1.proname, "
-               "       pp2.proname, "
+               "       pc.oid, "
                "       pc1.oid, "
-               "       pc2.oid, "
-               "       pc2.relname "
-               "FROM   pg_class pc1, "
+               "       pc1.relname "
+               "FROM   pg_class pc, "
+               "       pg_class pc1, "
                "       pg_class pc2, "
-               "       pg_class pc3, "
+               "       pg_proc pp, "
                "       pg_proc pp1, "
-               "       pg_proc pp2, "
+               "       pg_trigger pt, "
                "       pg_trigger pt1, "
-               "       pg_trigger pt2, "
-               "       pg_trigger pt3 "
-               "WHERE  pt1.tgconstrrelid = pc1.oid "
-               "   AND pt1.tgrelid = pc2.oid "
-               "   AND pt2.tgfoid = pp2.oid "
+               "       pg_trigger pt2 "
+               "WHERE  pt.tgconstrrelid = pc.oid "
+               "   AND pt.tgrelid = pc1.oid "
+               "   AND pt1.tgfoid = pp1.oid "
+               "   AND pt1.tgconstrrelid = pc1.oid "
                "   AND pt2.tgconstrrelid = pc2.oid "
-               "   AND pt3.tgconstrrelid = pc3.oid "
-               "   AND pt3.tgfoid = pp1.oid "
-               "   AND pc3.oid = pt1.tgrelid "
-               "   AND pc1.relname='%s' "
-               "   AND pp1.proname Like '%%upd' "
-               "   AND pp2.proname Like '%%del' "
-               "   AND pt2.tgrelid = pt1.tgconstrrelid "
-               "   AND pt3.tgrelid = pt1.tgconstrrelid ",
+               "   AND pt2.tgfoid = pp.oid "
+               "   AND pc2.oid = pt.tgrelid "
+               "   AND ("
+               "        (pc.relname='%s') "
+               "   AND  (pp.proname Like '%%upd') "
+               "   AND  (pp1.proname Like '%%del')"
+               "   AND  (pt1.tgrelid = pt.tgconstrrelid) "
+               "   AND  (pt2.tgrelid = pt.tgconstrrelid) "
+               "       )",
                pk_table_needed);
 
        result = PGAPI_ExecDirect(htbl_stmt, tables_query, strlen(tables_query));
@@ -3911,7 +3944,7 @@ if (conn->schema_support)
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 3, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 3, internal_asis_type,
                         trig_deferrable, sizeof(trig_deferrable), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3921,7 +3954,7 @@ if (conn->schema_support)
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 4, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 4, internal_asis_type,
                     trig_initdeferred, sizeof(trig_initdeferred), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3931,7 +3964,7 @@ if (conn->schema_support)
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 5, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 5, internal_asis_type,
                               upd_rule, sizeof(upd_rule), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3941,7 +3974,7 @@ if (conn->schema_support)
            return SQL_ERROR;
        }
 
-       result = PGAPI_BindCol(htbl_stmt, 6, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 6, internal_asis_type,
                               del_rule, sizeof(del_rule), NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3969,7 +4002,7 @@ if (conn->schema_support)
            PGAPI_FreeStmt(htbl_stmt, SQL_DROP);
            return SQL_ERROR;
        }
-       result = PGAPI_BindCol(htbl_stmt, 9, SQL_C_CHAR,
+       result = PGAPI_BindCol(htbl_stmt, 9, internal_asis_type,
                    fk_table_fetched, TABLE_NAME_STORAGE_LEN, NULL);
        if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        {
@@ -3981,7 +4014,7 @@ if (conn->schema_support)
 
        if (conn->schema_support)
        {
-           result = PGAPI_BindCol(htbl_stmt, 10, SQL_C_CHAR,
+           result = PGAPI_BindCol(htbl_stmt, 10, internal_asis_type,
                    schema_fetched, SCHEMA_NAME_STORAGE_LEN, NULL);
            if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
            {
index 89e53934fd230e0def6eb200f9c4f84c9ee48821..c958343da2a62af4c7c0c20c8ecb9aa18b06604d 100644 (file)
@@ -13,6 +13,8 @@
  */
 
 #include "psqlodbc.h"
+
+#if (ODBCVER >= 0x0300)
 #include <stdio.h>
 #include <string.h>
 
@@ -289,3 +291,4 @@ RETCODE SQL_API SQLColAttributeW(
 
    return ret;
 }
+#endif /* ODBCVER >= 0x0300 */
index 32201ab6c668d778848991e49458255da14a1af5..fde18269275d35692a9a302a85ed6980b8770384 100644 (file)
--- a/pgtypes.c
+++ b/pgtypes.c
@@ -169,18 +169,10 @@ sqltype_to_pgtype(StatementClass *stmt, SWORD fSqlType)
            break;
 
        case SQL_LONGVARBINARY:
-           switch (conn->lobj_type)
-           {
-               case PG_TYPE_LO_UNDEFINED:
-                   if (ci->bytea_as_longvarbinary)
-                   {
-                       pgType = PG_TYPE_BYTEA;
-                       break;
-                   }
-               default:
-                   pgType = conn->lobj_type;
-                   break;
-           }
+           if (ci->bytea_as_longvarbinary)
+               pgType = PG_TYPE_BYTEA;
+           else
+               pgType = conn->lobj_type;
            break;
 
        case SQL_LONGVARCHAR:
@@ -293,13 +285,10 @@ pgtype_to_concise_type(StatementClass *stmt, Int4 type)
 #endif /* UNICODE_SUPPORT */
 
        case PG_TYPE_BYTEA:
-           switch (conn->lobj_type)
-           {
-               case PG_TYPE_LO_UNDEFINED:  
-                   if (ci->bytea_as_longvarbinary)
-                       return SQL_LONGVARBINARY;
-           }
-           return SQL_VARBINARY;
+           if (ci->bytea_as_longvarbinary)
+               return SQL_LONGVARBINARY;
+           else
+               return SQL_VARBINARY;
        case PG_TYPE_LO_UNDEFINED:
            return SQL_LONGVARBINARY;
 
@@ -469,11 +458,9 @@ pgtype_to_ctype(StatementClass *stmt, Int4 type)
        case PG_TYPE_BPCHAR:
        case PG_TYPE_VARCHAR:
        case PG_TYPE_TEXT:
-           return conn->unicode ? SQL_C_WCHAR : SQL_C_CHAR;
-           /*  The following seems worse.
-            *
+           if (conn->unicode && ! conn->ms_jet && ! stmt->manual_result)
+               return SQL_C_WCHAR;
            return SQL_C_CHAR;
-            */
 #endif /* UNICODE_SUPPORT */
 
        default:
@@ -832,6 +819,8 @@ getTimestampColumnSize(StatementClass *stmt, Int4 type, int col)
 Int4
 pgtype_column_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
 {
+   ConnectionClass *conn = SC_get_conn(stmt);
+
    switch (type)
    {
        case PG_TYPE_CHAR:
@@ -845,7 +834,6 @@ pgtype_column_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_
 
        case PG_TYPE_NAME:
            {
-               ConnectionClass *conn = SC_get_conn(stmt);
                int value = 0;
 #ifdef NAME_FIELD_SIZE
                value = NAME_FIELD_SIZE;
@@ -895,10 +883,7 @@ pgtype_column_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_
            return getTimestampColumnSize(stmt, type, col);
 
        case PG_TYPE_BOOL:
-       {
-           BOOL    true_is_minus1 = FALSE;
-           return true_is_minus1 ? 2 : 1;
-       }
+           return conn->connInfo.true_is_minus1 ? 2 : 1;
 
        case PG_TYPE_LO_UNDEFINED:
            return SQL_NO_TOTAL;
@@ -915,7 +900,7 @@ pgtype_column_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_
 }
 
 /*
- * "precision in ODBC 3.x.
+ * precision in ODBC 3.x.
  */
 Int4
 pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
@@ -1372,7 +1357,7 @@ pgtype_create_params(StatementClass *stmt, Int4 type)
 
 
 Int2
-sqltype_to_default_ctype(Int2 sqltype)
+sqltype_to_default_ctype(const ConnectionClass *conn, Int2 sqltype)
 {
    /*
     * from the table on page 623 of ODBC 2.0 Programmer's Reference
@@ -1398,6 +1383,8 @@ sqltype_to_default_ctype(Int2 sqltype)
        case SQL_WCHAR:
        case SQL_WVARCHAR:
        case SQL_WLONGVARCHAR:
+           if (conn->ms_jet || ! conn->unicode)
+               return SQL_C_CHAR;
            return SQL_C_WCHAR;
 #endif /* UNICODE_SUPPORT */
 
index 987f5935cc18ed9b15b18452e518ea67bde773d2..20e0c4e5977b3203b2bcce4ccc3ba7fee94566ec 100644 (file)
--- a/pgtypes.h
+++ b/pgtypes.h
@@ -63,6 +63,7 @@
 #define PG_TYPE_TIME_WITH_TMZONE   1266        /* since 7.1 */
 #define PG_TYPE_TIMESTAMP      1296    /* deprecated since 7.0 */
 #define PG_TYPE_NUMERIC            1700
+#define INTERNAL_ASIS_TYPE     (-9999)
 
 /* extern Int4 pgtypes_defined[]; */
 extern Int2 sqlTypes[];
@@ -99,7 +100,7 @@ char    *pgtype_literal_prefix(StatementClass *stmt, Int4 type);
 char      *pgtype_literal_suffix(StatementClass *stmt, Int4 type);
 char      *pgtype_create_params(StatementClass *stmt, Int4 type);
 
-Int2       sqltype_to_default_ctype(Int2 sqltype);
+Int2       sqltype_to_default_ctype(const ConnectionClass *stmt, Int2 sqltype);
 Int4       ctype_length(Int2 ctype);
 
 #define    USE_ZONE    FALSE