SQLStatistics() sets 'D' for the collation column when an reverse index is used.
authorHiroshi Inoue <inoue@tpf.co.jp>
Sat, 15 Oct 2011 03:20:29 +0000 (03:20 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Sat, 15 Oct 2011 03:20:29 +0000 (03:20 +0000)
info.c
version.h

diff --git a/info.c b/info.c
index 7cd50d73b1ef02fbb5c6b56af3e389eee89ce124..00ef932ee82a3508ff78d5d4a786bacf8a853c29 100644 (file)
--- a/info.c
+++ b/info.c
@@ -2989,6 +2989,7 @@ cleanup:
 }
 
 
+#define INDOPTION_DESC     0x0001  /* values are in reverse order */
 RETCODE        SQL_API
 PGAPI_Statistics(
            HSTMT hstmt,
@@ -3011,6 +3012,7 @@ PGAPI_Statistics(
    char        *escSchemaName = NULL, *table_name = NULL, *escTableName = NULL;
    char        index_name[MAX_INFO_STRING];
    short       fields_vector[INDEX_KEYS_STORAGE_COUNT + 1];
+   short       indopt_vector[INDEX_KEYS_STORAGE_COUNT + 1];
    char        isunique[10],
                isclustered[10],
                ishash[MAX_INFO_STRING];
@@ -3199,7 +3201,7 @@ PGAPI_Statistics(
        escSchemaName = simpleCatalogEscape(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"
+           ", 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"
@@ -3210,11 +3212,12 @@ PGAPI_Statistics(
            " 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"
+           ", 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"
@@ -3316,6 +3319,17 @@ PGAPI_Statistics(
        goto cleanup;
    }
 
+   /* bind the vector column */
+   result = PGAPI_BindCol(hindx_stmt, 10, SQL_C_DEFAULT,
+           indopt_vector, sizeof(fields_vector), &fields_vector_len);
+   if (!SQL_SUCCEEDED(result))
+   {
+       SC_error_copy(stmt, indx_stmt, TRUE); /* "Couldn't bind column 
+                        * in SQLStatistics."; */
+       goto cleanup;
+
+   }
+
    relhasrules[0] = '0';
    result = PGAPI_Fetch(hindx_stmt);
    /* fake index of OID */
@@ -3436,7 +3450,11 @@ PGAPI_Statistics(
                    }
                }
 
-               set_tuplefield_string(&tuple[STATS_COLLATION], "A");
+               if (i <= indopt_vector[0] &&
+                   (indopt_vector[i] & INDOPTION_DESC) != 0)
+                   set_tuplefield_string(&tuple[STATS_COLLATION], "D");
+               else
+                   set_tuplefield_string(&tuple[STATS_COLLATION], "A");
                set_tuplefield_null(&tuple[STATS_CARDINALITY]);
                set_tuplefield_null(&tuple[STATS_PAGES]);
                set_tuplefield_null(&tuple[STATS_FILTER_CONDITION]);
index 44e225fafb8f8876d368e5c59c21e5a8d8509e30..c7164d5f21a7b9e5391acbc0658ebb4315b9895e 100644 (file)
--- a/version.h
+++ b/version.h
@@ -9,9 +9,9 @@
 #ifndef __VERSION_H__
 #define __VERSION_H__
 
-#define POSTGRESDRIVERVERSION      "09.00.0310"
-#define POSTGRES_RESOURCE_VERSION  "09.00.0310\0"
-#define PG_DRVFILE_VERSION     9,0,03,10
-#define PG_BUILD_VERSION       "201107030001"
+#define POSTGRESDRIVERVERSION      "09.00.0311"
+#define POSTGRES_RESOURCE_VERSION  "09.00.0311\0"
+#define PG_DRVFILE_VERSION     9,0,03,11
+#define PG_BUILD_VERSION       "201110150001"
 
 #endif