[fdo-commits] r676 - branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 22 21:08:10 EST 2007


Author: mloskot
Date: 2007-01-22 21:08:10 -0500 (Mon, 22 Jan 2007)
New Revision: 676

Modified:
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/Geometry.h
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/PostGISDriver.vcproj
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/bind.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/conn_status.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/connect.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/desc_slct.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/execute.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/fetch.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_msg.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.h
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.h
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/rdbi_init.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/run_sql.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.h
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/sql.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/stdafx.h
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.c
   branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.h
Log:
New features, fixes and types support in RDBI driver for PostGIS. TODO: not all RDBI type mappings are covered.

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/Geometry.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/Geometry.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/Geometry.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -23,9 +23,8 @@
 #pragma once
 #endif // _WIN32
 
+extern void* GeometryFromWkb (void *wkb, unsigned long size);
+extern char* WkbFromGeometry (void *geometry, int* size);
+extern void FreeGeometry (void *geometry);
 
-extern   void *GeometryFromWkb (void *wkb, unsigned long size);
-extern    void FreeGeometry (void *geometry);
-extern    char *WkbFromGeometry (void *geometry, int* size);
-
 #endif /* POSTGIS_GEOMETRY_H */

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/PostGISDriver.vcproj
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/PostGISDriver.vcproj	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/PostGISDriver.vcproj	2007-01-23 02:08:10 UTC (rev 676)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="8.00"
+	Version="8,00"
 	Name="PostGISDriver"
 	ProjectGUID="{69D1E6E5-9391-40FE-A989-B9BEBE3EE305}"
 	RootNamespace="PostGISDriver"
@@ -476,6 +476,18 @@
 				</FileConfiguration>
 			</File>
 			<File
+				RelativePath=".\get_gen_id.c"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						CompileAs="2"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
 				RelativePath=".\get_msg.c"
 				>
 				<FileConfiguration
@@ -584,6 +596,18 @@
 				</FileConfiguration>
 			</File>
 			<File
+				RelativePath=".\set_err_msg.c"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						CompileAs="2"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
 				RelativePath=".\set_schema.c"
 				>
 				<FileConfiguration
@@ -706,6 +730,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\digits.h"
+				>
+			</File>
+			<File
 				RelativePath=".\disconnect.h"
 				>
 			</File>
@@ -730,6 +758,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\get_gen_id.h"
+				>
+			</File>
+			<File
 				RelativePath=".\get_msg.h"
 				>
 			</File>
@@ -770,6 +802,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\set_err_msg.h"
+				>
+			</File>
+			<File
 				RelativePath=".\set_schema.h"
 				>
 			</File>

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/bind.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/bind.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/bind.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -1,48 +1,48 @@
-/*
- * Copyright (C) 2006 Refractions Research, Inc. 
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser
- * General Public License as published by the Free Software Foundation.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#include "stdafx.h"
-
-#include "bind.h"
-#include "local.h"
-#include "type.h"
-#include "pgconn_status.h"
-#include "pgresult_status.h"
-#include <limits.h> /* LONG_MIN, LONG_MAX */
-#include <stdlib.h> /* malloc(), free() */
-#include <string.h> /* memset() */
-
-int postgis_bind (
-    postgis_context_def *context,
-    char *cursor,
-    char *name,
-    int   datatype,
-    int   size,
-    char *address,
-    char *null_ind)
-{
-    PGconn* postgis = NULL;
-    postgis_cursor_def* curs = NULL;
-    PGSQL_BIND *binds = NULL;
-    Oid typeoid = 0;
-    int index = 0;
-    int ret = RDBI_GENERIC_ERROR;
-
+/*
+ * Copyright (C) 2006 Refractions Research, Inc. 
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "stdafx.h"
+
+#include "bind.h"
+#include "local.h"
+#include "type.h"
+#include "pgconn_status.h"
+#include "pgresult_status.h"
+#include <limits.h> /* LONG_MIN, LONG_MAX */
+#include <stdlib.h> /* malloc(), free() */
+#include <string.h> /* memset() */
+
+int postgis_bind (
+    postgis_context_def *context,
+    char *cursor,
+    char *name,
+    int   datatype,
+    int   size,
+    char *address,
+    char *null_ind)
+{
+    PGconn* postgis = NULL;
+    postgis_cursor_def* curs = NULL;
+    PGSQL_BIND *binds = NULL;
+    Oid typeoid = 0;
+    int index = 0;
+    int ret = RDBI_GENERIC_ERROR;
+
     if (-1 == context->postgis_current_connect)
         ret = RDBI_NOT_CONNECTED;
     else
@@ -50,71 +50,76 @@
         postgis = context->postgis_connections[context->postgis_current_connect];
         if (RDBI_SUCCESS != postgis_pgconn_status(postgis))
             ret = RDBI_NOT_CONNECTED;
-        else
-        {
+        else
+        {
             curs = (postgis_cursor_def*)cursor;
             if (NULL == curs)
                 ret = RDBI_GENERIC_ERROR;
-            else
-            {
-                /* TODO: need an error for bind names not supported */
-
-                /* Numeric position */
-                index = strtol(name, NULL, 10);
-                if (0 >= index || LONG_MIN == index || LONG_MAX == index)
-                {
-                    ret = RDBI_GENERIC_ERROR; /* need an error for unknown name */
-                }
-                else
-                {
-                    index--; /* Make parameter index zero -based */
-
-                    typeoid = rdbi_to_postgis_type(postgis, datatype, size, 0);
-                    if (0 >= typeoid)
-                    {
-                        ret = RDBI_INVLD_DESCR_OBJTYPE; 
-                    }
-                    else
-                    {
-                        if (index >= curs->bind_count)
-                        {
-                            binds = (PGSQL_BIND *)malloc((index + 1) * sizeof(PGSQL_BIND));
-                            if ((PGSQL_BIND*)NULL == binds)
-                            {
-                                if ((PGSQL_BIND*)NULL != curs->binds)
-                                    free (curs->binds);
-                                curs->bind_count = 0;
-                            }
-                            else
-                            {
-                                memset (binds, 0, (index + 1) * sizeof(PGSQL_BIND));
-                                if ((PGSQL_BIND*)NULL != curs->binds)
-                                {
-                                    memcpy (binds, curs->binds, curs->bind_count * sizeof(PGSQL_BIND));
-                                    free (curs->binds);
-                                }
-                                curs->bind_count = index + 1;
-                                curs->binds = binds;
-                            }
-                        }
-                        if (index >= curs->bind_count)
-                            ret = RDBI_MALLOC_FAILED;
-                        else
-                        {
-                            curs->binds[index].buffer_type = typeoid;
-                            curs->binds[index].buffer_length = size;
-                            curs->binds[index].buffer = address;
-                            if ((char*)NULL != null_ind)
-                            {
-                                curs->binds[index].is_null = null_ind;
-                            }
-                            ret = RDBI_SUCCESS;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    return (ret);
-}
+            else
+            {
+                /* TODO: need an error for bind names not supported */
+
+                /* Numeric position */
+                index = strtol(name, NULL, 10);
+                if (0 >= index || LONG_MIN == index || LONG_MAX == index)
+                {
+                    ret = RDBI_GENERIC_ERROR; /* need an error for unknown name */
+                }
+                else
+                {
+                    index--; /* Make parameter index zero -based */
+
+                    typeoid = rdbi_to_postgis_type(postgis, datatype, size, 0);
+                    if (0 >= typeoid)
+                    {
+                        ret = RDBI_INVLD_DESCR_OBJTYPE; 
+                    }
+                    else
+                    {
+                        if (index >= curs->bind_count)
+                        {
+                            binds = (PGSQL_BIND *)malloc((index + 1) * sizeof(PGSQL_BIND));
+                            if ((PGSQL_BIND*)NULL == binds)
+                            {
+                                if ((PGSQL_BIND*)NULL != curs->binds)
+                                    free (curs->binds);
+                                curs->bind_count = 0;
+                            }
+                            else
+                            {
+                                memset (binds, 0, (index + 1) * sizeof(PGSQL_BIND));
+                                if ((PGSQL_BIND*)NULL != curs->binds)
+                                {
+                                    memcpy (binds, curs->binds, curs->bind_count * sizeof(PGSQL_BIND));
+                                    free (curs->binds);
+                                }
+                                curs->bind_count = index + 1;
+                                curs->binds = binds;
+                            }
+                        }
+                        if (index >= curs->bind_count)
+                            ret = RDBI_MALLOC_FAILED;
+                        else
+                        {
+                            /*
+                             * typeoid - native PostgreSQL type is detected.
+                             * size - value passed from GDBI layer.
+                             * address - comes from GDBI too
+                             */
+                            curs->binds[index].buffer_type = typeoid;
+                            curs->binds[index].buffer_length = size;
+                            curs->binds[index].buffer = address;
+                            if ((char*)NULL != null_ind)
+                            {
+                                curs->binds[index].is_null = null_ind;
+                            }
+                            ret = RDBI_SUCCESS;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    return (ret);
+}

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/conn_status.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/conn_status.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/conn_status.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -29,36 +29,36 @@
     int index = -1;
     int ret = RDBI_GENERIC_ERROR;
     
-
-    assert(NULL != context);
-
     if (NULL != context)
     {
-        if (-1 == context->postgis_current_connect)
+        /*
+         * TODO: mloskot - Is secondary connection mandatory?
+         */
+
+        if (-1 == context->postgis_current_connect
+            || -1 == context->postgis_current_connect2)
         {
             ret = RDBI_NOT_CONNECTED;
         }
         else
         {
+            /*
+             * Check primary connection.
+             */
             index = context->postgis_current_connect;
             conn  = context->postgis_connections[index];
+ 
+            ret = postgis_pgconn_status(conn);
+            if (RDBI_SUCCESS == ret)
+            {
+                /*
+                * Check secondary connection.
+                */
+                index = context->postgis_current_connect2;
+                conn  = context->postgis_connections[index];
 
-            if (NULL != conn)
-            {
-                // Returns RDBI status code
                 ret = postgis_pgconn_status(conn);
             }
-            else
-            {
-                // TODO - mloskot: If context indicates the connection
-                // is active, but connection handle is NULL, it means
-                // undefined error, like libpq allocation failure.
-                //
-                // TODO - mloskot: Remove assertion before merging with 'trunk'
-                assert(false);
-
-                return RDBI_GENERIC_ERROR;
-            }
         }
     }
     

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/connect.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/connect.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/connect.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -19,6 +19,8 @@
 #include "stdafx.h"
 
 #include "connect.h"
+#include "set_err_msg.h"
+#include "pgconn_status.h"
 #include "Inc/ut.h"
 #include <malloc.h> /* alloca() */
 #include <stdio.h>
@@ -31,34 +33,37 @@
     char** vendor_data,
     int*   connect_id)
 {
-    /* Used in strings manipulation. */
-    char *p = NULL;
-    size_t length = 0;
+    PGconn* conn = NULL;    /* Database connection handler. */
 
-    /* Splited values of connection string. */
+    /* Properties retrieved from connection string. */
     char* dbname = NULL;
     char* pghost = NULL;
     char* pgport = DEF_PGPORT_STR;  /* default port, defined in stdafx.h */
 
+    /* Properties passed explicitly. */
     const char* pglogin = user;
     const char* pgpwd   = pswd;
-    const char* pgoptions = NULL;   /* not used */
-    const char* pgtty  = NULL;      /* not used */
+    
+    /* Properties not used in current version. */
+    const char* pgoptions = NULL;
+    const char* pgtty  = NULL;
 
-    /* Database connection handler. */
-    PGconn* conn = NULL;
+    /* Used in strings manipulation. */
+    char* pch = NULL;
+    size_t length = 0;
 
+    int conn_index = 0;
+    int max_connects = 0;
     int ret = RDBI_SUCCESS;
-    int max_connects = 0;
-    int index = 0;
-    int rows_processed = 0;
 
     assert(NULL != context);
 
     /*
-     * Split RDBI connection string to separate values.
-     * Input format: database at host:port
-     * where default host is localhost and default port is DEF_PGPORT=5432.
+     * Retrieve connection properties from the RDBI connection string.
+     * Connection string format is:
+     * - short: database
+     *          where default host is localhost and default port is 5432.
+     * - long: database at host:port
      */
     pghost = "localhost";
 
@@ -67,82 +72,83 @@
         /*
          * Database name.
          */
-        p = strchr(connect_string, '@');
-        if (NULL != p)
+        pch = strchr(connect_string, '@');
+        if (NULL != pch)
         {
-            length = p - connect_string;
+            length = pch - connect_string;
             dbname = (char*)alloca(length + 1);
             strncpy(dbname, connect_string, length);
             dbname[length] = '\0';
-            p++;
-            connect_string = p;
-        }
+            pch++;
+            connect_string = pch;
 
-        /*
-         * Host name and port.
-         */
-        p = strchr(connect_string, ':');
-        if (NULL != p)
-        {
-            length = p - connect_string;
-            pghost = (char*)alloca(length + 1);
-            strncpy(pghost, connect_string, length);
-            pghost[length] = '\0';
-            p++;
+            /*
+            * Hostname and port.
+            */
+            pch = strchr(connect_string, ':');
+            if (NULL != pch)
+            {
+                length = pch - connect_string;
+                pghost = (char*)alloca(length + 1);
+                strncpy(pghost, connect_string, length);
+                pghost[length] = '\0';
+                pch++;
 
-            pgport = p;
+                pgport = pch;
+            }
+            else
+            {
+                pghost = connect_string;
+            }
         }
         else
         {
-            pghost = connect_string;
+            dbname = connect_string;
         }
     }
 
     /*
-     * No database name provided, use 'template_postgis' as default target.
-     * with assumptions user wants to create new datastore and reconnect to it.
+    * Find an open slot and try to connect.
+    */
+    max_connects = ELEMENTS(context->postgis_connections);
+
+    /*
+     * PostgreSQL database name is required.
      */
     if (NULL == dbname)
     {
-        length = strlen(POSTGIS_TEMPLATE_DBNAME);
-        dbname = (char*)alloca(length + 1);
-        strncpy(dbname, POSTGIS_TEMPLATE_DBNAME, length + 1);
-        dbname[length] = '\0';
+
+        ret = RDBI_NOT_CONNECTED;
     }
-
-    /*
-     * TODO: Replace assertions with test-and-error-return.
-     */
-    assert(NULL != pghost);
-    assert(NULL != pgport);
-    assert(NULL != dbname);
-
-    /*
-     * Find an open slot and try to connect.
-     */
-    max_connects = ELEMENTS(context->postgis_connections);
-    if (max_connects <= context->postgis_connect_count)
+    else if (max_connects <= context->postgis_connect_count)
     {
         ret = RDBI_TOO_MANY_CONNECTS;
     }
     else
     {
-        for (index = 0; (index < max_connects) && (RDBI_SUCCESS == ret); index++)
+        assert(NULL != pghost);
+        assert(NULL != pgport);
+        assert(NULL != dbname);
+
+        for (conn_index = 0;
+            ((conn_index < max_connects) && (RDBI_SUCCESS == ret));
+            conn_index++)
         {
-            if (NULL == context->postgis_connections[index])
+            if (NULL == context->postgis_connections[conn_index])
             {
-                /* Initialize a connection */
-
-                /* PQsetdbLogin always returns non-NULL pointer. */
+                /*
+                 * Establish connection with PostgreSQL database.
+                 */
                 conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbname, pglogin, pgpwd);
-                if (CONNECTION_BAD == PQstatus(conn))
+                
+                ret = postgis_pgconn_status(conn);
+                if (RDBI_SUCCESS != ret)
                 {
-                    /* Retrieve connection error. */
-                    char* p = PQerrorMessage(conn);
-                    memset(context->postgis_last_err_msg, '\0', RDBI_MSG_SIZE);
-                    strncpy(context->postgis_last_err_msg, p, RDBI_MSG_SIZE);
-                    context->postgis_last_err_msg[RDBI_MSG_SIZE - 1] = '\0';
-                    ret = RDBI_GENERIC_ERROR;
+                    /* Retrieve connection error and
+                     * set as last error message for context.
+                     */
+                    pch = PQerrorMessage(conn);
+                    postgis_set_err_msg(context, pch);
                     
                     PQfinish(conn);
                     conn = NULL;
@@ -152,19 +158,19 @@
                     if (-1 == context->postgis_current_connect)
                     {
                         context->postgis_connect_count++;
-                        context->postgis_current_connect = index;
-                        context->postgis_connections[index] = conn;
+                        context->postgis_current_connect = conn_index;
+                        context->postgis_connections[conn_index] = conn;
 
-                        /* Return id of established connection. */
-                        *connect_id = index;
+                        /* Index is used as a connection ID. */
+                        *connect_id = conn_index;
                         
                         ret = RDBI_SUCCESS;
                     }
                     else if (-1 == context->postgis_current_connect2)
                     {
                         context->postgis_connect_count++;
-                        context->postgis_current_connect2 = index;
-                        context->postgis_connections[index] = conn;
+                        context->postgis_current_connect2 = conn_index;
+                        context->postgis_connections[conn_index] = conn;
 
                         ret = RDBI_SUCCESS;
                         break;
@@ -174,5 +180,5 @@
         } // for
     }
 
-    return (ret);
+    return ret;
 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/desc_slct.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/desc_slct.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/desc_slct.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -36,6 +36,7 @@
 #define case_insensitive_compare strcasecmp
 #endif
 
+
 int postgis_desc_slct (
     postgis_context_def *context,
     char *cursor,
@@ -114,23 +115,34 @@
 
                                 switch (type)
                                 {
-                                case RDBI_CHAR:         /* Fixed-length strings. */
+                                case RDBI_CHAR:       /* Fixed-length strings. */
                                 case RDBI_FIXED_CHAR:
-                                    fsize = postgis_get_char_length(pgres, position);
+                                    if (-1 == fsize)
+                                    {
+                                        /* Fetch size from typemod. */
+                                        fsize = postgis_get_char_length(pgres, position);
+                                    }
                                     assert(PGSQL_VAR_NOINFO != fsize);
 
                                     if (1 == fsize) /* CHAR(1) */
                                         *binary_size = fsize + 1;
-                                    else /* CHAR(N) */
+                                    else            /* CHAR(N) */
                                         *binary_size = fsize; 
                                     break;
-                                case RDBI_STRING:       /* Variable-length strings. */
-                                    fsize = postgis_get_varchar_length(pgres, position);
-                                    if (fsize > 0) /* VARCHAR(N) */
+
+                                case RDBI_STRING:   /* Variable-length strings. */
+                                    if (-1 == fsize)
+                                    {
+                                        /* Fetch size from typemod. */
+                                        fsize = postgis_get_varchar_length(pgres, position);
+                                    }
+
+                                    if (fsize > 0)  /* VARCHAR(N) */
                                         *binary_size = fsize;
-                                    else    /* TEXT */
-                                        *binary_size = 65536; /* Arbitrary value of 64 KB */
+                                    else            /* TEXT */
+                                        *binary_size = PGSQL_VARCHAR_MAX_SIZE;
                                     break;
+
                                 case RDBI_FLOAT:
                                     *binary_size = sizeof(float);
                                     break;
@@ -156,7 +168,18 @@
                                     *binary_size = sizeof(int64_t);
 #endif
                                     break;
-
+                                case RDBI_BOOLEAN:
+                                    *binary_size = PGSQL_BOOLEAN_RDBI_SIZE;
+                                    break;
+                                case RDBI_DATE:
+                                    /*
+                                     * TODO: mloskot - check size of DATE type
+                                     */
+                                    *binary_size = PGSQL_VARCHAR_MAX_SIZE;
+                                    break;
+                                case RDBI_ROWID:
+                                    assert(!"postgis_desc_slct: ROWID type is unsupported");
+                                    break;
                                 default:
                                     /*
                                      * TODO: mloskot - Unknown size?
@@ -164,7 +187,6 @@
                                     assert(!"postgis_desc_slct: Unknown field size");
 
                                     *binary_size = 0;
-                                    break;
                                 }
 
                                 /*
@@ -173,7 +195,6 @@
                                 *null_ok = 1; /* 1 is a temporary value. */
                                 
                                 ret = RDBI_SUCCESS;
-
                             }
                         }
                     }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/execute.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/execute.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/execute.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -18,15 +18,18 @@
 
 #include "stdafx.h"
 
+#include "digits.h"
+#include "errno.h"
 #include "execute.h"
-#include "Geometry.h"
-#include "errno.h"
 #include "pgconn_status.h"
 #include "pgresult_clear.h"
 #include "pgresult_error.h"
 #include "pgresult_status.h"
 
-#include <stdlib.h> /* malloc(), free() */
+#include "Geometry.h"
+
+#include <limits.h>
+#include <stdlib.h> /* malloc(), free() */
 #include <string.h> /* memset(), strcpy() */
 
 // TODO: mloskot - To be removed for release.
@@ -70,16 +73,14 @@
             {
                 assert (NULL != curs->stmt_name);
 
+                params_count = 0; /* Important, if binds is NULL. */
+
                 /*
                 * Prepare input parameters for statement.
                 */
-
-                params_count = 0; /* Important, if binds is NULL. */
-
                 if (NULL != curs->binds)
                 {
                     params_count = curs->bind_count;
-
                     param_values = (char**)malloc(sizeof(char*) * params_count);
                     if (NULL == param_values)
                         ret = RDBI_MALLOC_FAILED;
@@ -91,7 +92,7 @@
                         {
                             switch (curs->binds[i].buffer_type)
                             {
-                            case PGSQL_TYPE_CHAR:
+                            case PGSQL_TYPE_CHAR:  /* TODO: mloskot - check if not move to separate case */
                             case PGSQL_TYPE_BPCHAR:
                             case PGSQL_TYPE_VARCHAR:
                             case PGSQL_TYPE_TEXT:
@@ -101,29 +102,72 @@
                                     memset(buf, 0, buf_size);
                                     strncpy(buf, (const char*)curs->binds[i].buffer, buf_size);
 
-                                    param_values[i] = buf;
                                 }
                                 break;
+                            case PGSQL_TYPE_INT2:
+                                {
+                                    buf_size = NUMBER_OF_DIGITS10(short);
+                                    buf = (char*)malloc(buf_size);
+                                    memset(buf, 0, buf_size);
+                                    snprintf(buf, buf_size, "%d", (int)(*((short*)curs->binds[i].buffer)));
+                                }
+                                break;
+                            case PGSQL_TYPE_INT4:
+                                {
+                                    buf_size = NUMBER_OF_DIGITS10(int);
+                                    buf = (char*)malloc(buf_size);
+                                    memset(buf, 0, buf_size);
+                                    snprintf(buf, buf_size, "%d", (*((int*)curs->binds[i].buffer)));
+                                }
+                                break;
+                            case PGSQL_TYPE_INT8:
+                                {
+                                    buf_size = NUMBER_OF_DIGITS10(rdbi_int64_t);
+                                    buf = (char*)malloc(buf_size);
+                                    memset(buf, 0, buf_size);
+                                    snprintf(buf, buf_size, "%I64d", (*((rdbi_int64_t*)curs->binds[i].buffer)));
+                                }
+                                break;
+                            case PGSQL_TYPE_FLOAT:
+                                {
+                                    buf_size = NUMBER_OF_FLOAT_DIGITS;
+                                    buf = (char*)malloc(buf_size);
+                                    memset(buf, 0, buf_size);
+                                    snprintf(buf, buf_size, "%.20g", (*((float*)curs->binds[i].buffer)));
+                                }
+                                break;
+                            case PGSQL_TYPE_DOUBLE:
+                                {
+                                    buf_size = NUMBER_OF_DOUBLE_DIGITS;
+                                    buf = (char*)malloc(buf_size);
+                                    memset(buf, 0, buf_size);
+                                    snprintf(buf, buf_size, "%.20g", (*((double*)curs->binds[i].buffer)));
+                                }
+                                break;
+                            default:
+                                assert(!"execute: UNKNOWN TYPE");
                             }
+
+                            /* Assign value to input parameter. */
+                            param_values[i] = buf;
+
+                            buf = NULL;
+                            buf_size = 0;
                         }
                     }
                 }
-                
-                assert(RDBI_MALLOC_FAILED != ret); // TODO: mloskot - replace with cleanup & error return
 
                 /*
                 * Execute prepared statement.
                 */
-
-                curs->stmt_result = PQexecPrepared(postgis, curs->stmt_name,
-                                                   params_count,
-                                                   param_values,
+                curs->stmt_result = PQexecPrepared(postgis, curs->stmt_name,
+                                                   params_count, param_values,
                                                    NULL, NULL, 0);
 
                 ret = postgis_pgresult_status(curs->stmt_result);
                 if (RDBI_SUCCESS != ret)
                 {
-                    postgis_pgresult_error(curs->stmt_result, NULL);
+                    postgis_pgresult_error(context, curs->stmt_result);
                     postgis_pgresult_clear(curs->stmt_result);
                     curs->stmt_result = NULL;
                 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/fetch.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/fetch.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/fetch.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -20,20 +20,27 @@
 
 #include "fetch.h"
 #include "local.h"
-#include "pgconn_status.h"
+#include "conn_status.h"
 #include "pgresult_status.h"
 #include "Geometry.h"
 
-int postgis_fetch (
-    postgis_context_def *context,
-    char *cursor,
-    int count,
-    int do_exec,
-    int do_cancel,
-    int *rows_processed)
+#include <stdlib.h> /* strtol() */
+#include <string.h> /* memcpy(), strncpy() */
+#include <assert.h>
+
+
+int postgis_fetch (postgis_context_def *context,
+                   char *cursor,
+                   int count,
+                   int do_exec,
+                   int do_cancel,
+                   int *rows_processed)
 {
     PGconn* postgis = NULL;
-    postgis_cursor_def *curs;
+    postgis_cursor_def *curs = NULL;
+    char* buffer = NULL;
+    char* fvalue = NULL;
+    size_t fvalue_length = 0;
     int nrows = 0;
     int nfields = 0;
     int ret = RDBI_GENERIC_ERROR;
@@ -42,51 +49,145 @@
     if (NULL != rows_processed)
         *rows_processed = 0;
 
-    if (-1 == context->postgis_current_connect)
-        ret = RDBI_NOT_CONNECTED;
-    else
+    ret = postgis_conn_status(context);
+    if (RDBI_SUCCESS == ret)
     {
         postgis = context->postgis_connections[context->postgis_current_connect];
-        if (RDBI_SUCCESS != postgis_pgconn_status(postgis))
-            ret = RDBI_NOT_CONNECTED;
+        assert(NULL != postgis);
+
+        curs = (postgis_cursor_def*)cursor;
+        if (NULL == curs)
+            ret = RDBI_GENERIC_ERROR;
         else
         {
-            curs = (postgis_cursor_def*)cursor;
-            if (NULL == curs)
-                ret = RDBI_GENERIC_ERROR;
-            else
+            /*
+            * Fetch next row from query results into buffers in defines.
+            */
+            if (NULL != curs->stmt_name
+                && NULL != curs->defines
+                && PGRES_TUPLES_OK == PQresultStatus(curs->stmt_result))
             {
-                //ret = RDBI_END_OF_FETCH; // TODO: mloskot - Is there any better code to use here?
+                /* Move cursor to next row. */
+                curs->current_row++;
 
-                if (NULL != curs->stmt_name && PGRES_TUPLES_OK == PQresultStatus(curs->stmt_result))
+                nrows = PQntuples(curs->stmt_result);
+                if (curs->current_row >= nrows)
                 {
-                    /* Move cursor to next row. */
-                    curs->current_row++;
+                    /* End of query result. */
+                    curs->current_row = -1;
+                    ret = RDBI_END_OF_FETCH;
+                }
+                else
+                {
+                    /* Fetch data into buffers in defines. */
+                    const int nfields = PQnfields(curs->stmt_result);
 
-                    nrows = PQntuples(curs->stmt_result);
-                    if (curs->current_row >= nrows)
+                    /* Pre-condition assures the state of RDBI machinery. */
+                    assert(nfields == curs->define_count);
+
+                    for (int i = 0; i < nfields; ++i)
                     {
-                        /* End of query result. */
-                        ret = RDBI_END_OF_FETCH;
-                    }
-                    else
-                    {
-                        /* Fetch data into buffers in defines. */
-                        nfields = PQnfields(curs->stmt_result);
-                        for (int i = 0; i < nfields; ++i)
+                        /* Read field value */
+                        fvalue = PQgetvalue(curs->stmt_result, curs->current_row, i);
+                        assert(NULL != curs->defines[i].buffer);
+
+                        /* Convert value type and safe to define buffer. */
+                        switch(curs->defines[i].buffer_type)
                         {
-                            printf("F %d: %s\n", i, PQgetvalue(curs->stmt_result, curs->current_row, i));
+                        case PGSQL_TYPE_CHAR:
+                        case PGSQL_TYPE_BPCHAR:
+                        case PGSQL_TYPE_VARCHAR:
+                        case PGSQL_TYPE_TEXT:
+                        case PGSQL_TYPE_NAME:
+                            {
+                                assert((strlen(fvalue) + 1) <= curs->defines[i].buffer_length);
+
+                                fvalue_length = strlen(fvalue);
+                                buffer = (char*)curs->defines[i].buffer;
+                                strncpy(buffer, fvalue, fvalue_length);
+                                buffer[fvalue_length] = '\0';
+                                break;
+                            }
+                        case PGSQL_TYPE_INT2:
+                            {
+                                assert(sizeof(short) == curs->defines[i].buffer_length);
+
+                                short val = (short)strtol(fvalue, NULL, 10);
+                                memcpy(curs->defines[i].buffer, &val, sizeof(short));
+                            }
+                            break;
+                        case PGSQL_TYPE_INT4:
+                            {
+                                assert(sizeof(int) == curs->defines[i].buffer_length);
+
+                                int val = (int)strtol(fvalue, NULL, 10);
+                                memcpy(curs->defines[i].buffer, &val, sizeof(int));
+                            }
+                            break;
+                        case PGSQL_TYPE_INT8:
+                            {
+                                assert(sizeof(rdbi_int64_t) == curs->defines[i].buffer_length);
+
+                                rdbi_int64_t val = (rdbi_int64_t)strtol(fvalue, NULL, 10);
+                                size_t type_size = sizeof(rdbi_int64_t);
+                                memcpy(curs->defines[i].buffer, &val, type_size);
+                            }
+                            break;
+                        case PGSQL_TYPE_FLOAT:
+                            {
+                                assert(sizeof(float) == curs->defines[i].buffer_length);
+
+                                float val = (float)strtod(fvalue, NULL);
+                                memcpy(curs->defines[i].buffer, &val, sizeof(float));
+                            }
+                            break;
+                        case PGSQL_TYPE_DOUBLE:
+                            {
+                                assert(sizeof(double) == curs->defines[i].buffer_length);
+
+                                double val = (double)strtod(fvalue, NULL);
+                                memcpy(curs->defines[i].buffer, &val, sizeof(double));
+                            }
+                            break;
+                        case PGSQL_TYPE_DECIMAL:
+                            {
+                                assert(sizeof(double) == curs->defines[i].buffer_length);
+
+                                double val = (double)strtod(fvalue, NULL);
+                                memcpy(curs->defines[i].buffer, &val, sizeof(double));
+                            }
+                            break;
+
+                        default:
+                            assert(!"fetch: NOT IMPLEMENTED TYPE");
                         }
 
-                        if (NULL != rows_processed)
-                            *rows_processed = 1;
+                        buffer = NULL;
+                        fvalue_length = 0;
+                    }
 
-                        ret = RDBI_SUCCESS;
-                    }
+                    if (NULL != rows_processed)
+                        *rows_processed = 1;
+
+                    ret = RDBI_SUCCESS;
                 }
             }
+            else if (NULL != curs->stmt_name
+                     && PGRES_COMMAND_OK == PQresultStatus(curs->stmt_result))
+            {
+                // TODO: mloskot - Test empty result set
+
+                curs->current_row = -1;
+                ret = RDBI_END_OF_FETCH;
+            }
+            else
+            {
+                // TODO: mloskot - Find better error code.
+                assert(false);
+                ret = RDBI_GENERIC_ERROR;
+            }
         }
     }
 
-    return (ret);
+    return ret;
 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_msg.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_msg.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/get_msg.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -29,19 +29,20 @@
     const char* msg = NULL;
     int ret = RDBI_GENERIC_ERROR;
 
+    assert(NULL != buffer);
     memset(buffer, '\0', RDBI_MSG_SIZE);
 
     if (-1 == context->postgis_current_connect)
     {
         strncpy (buffer, context->postgis_last_err_msg, RDBI_MSG_SIZE);
         buffer[RDBI_MSG_SIZE - 1] = '\0'; 
-        ret = RDBI_NOT_CONNECTED;
+        ret = RDBI_SUCCESS;
     }
     else if (0 != context->postgis_last_err_msg[0])
     {
         strncpy (buffer, context->postgis_last_err_msg, RDBI_MSG_SIZE);
         buffer[RDBI_MSG_SIZE - 1] = '\0';
-        ret = RDBI_GENERIC_ERROR;
+        ret = RDBI_SUCCESS;
     }
     else
     {
@@ -58,7 +59,7 @@
         ret = RDBI_SUCCESS;
     }
 
-    return (ret);
+    return ret;
 }
 
 int postgis_get_msgW (postgis_context_def *context, wchar_t *buffer)
@@ -67,21 +68,24 @@
     const char* msg = NULL;
     int ret = RDBI_GENERIC_ERROR;
 
+    assert(NULL != buffer);
     memset(buffer, '\0', RDBI_MSG_SIZE);
 
     /*
      * TODO: mloskot - last_err_msg store Unicode
      */
 
+    assert(!"postgis_get_msgW() - Not Implemented");
+
     if (-1 == context->postgis_current_connect)
     {
         //wcscpy (buffer, context->postgis_last_err_msg);
-        ret = RDBI_NOT_CONNECTED;
+        ret = RDBI_SUCCESS;
     }
     else if ( 0 != context->postgis_last_err_msg[0] ) 
     {
         //wcscpy (buffer, context->postgis_last_err_msg);
-        ret = RDBI_GENERIC_ERROR;
+        ret = RDBI_SUCCESS;
     }
     else
     {
@@ -96,5 +100,5 @@
         ret = RDBI_SUCCESS;
     }
 
-    return (ret);
+    return ret;
 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -29,11 +29,9 @@
 
     if (NULL != conn)
     {
-        // Connection status tests
-
         if (CONNECTION_OK != PQstatus(conn))
         {
-            // Try error recovery if a working connection is lost.
+            /* Try error recovery if a working connection is lost. */
             ret = RDBI_SUCCESS;
             PQreset(conn);
 
@@ -47,23 +45,6 @@
             ret = RDBI_SUCCESS;
         }
     }
-    else
-    {
-        // TODO - mloskot: This assumption is not 100% correct.
-        // If libpq connection function return NULL, that means
-        // internal libpq error occured, so it's good to return 
-        // real error code here.
-        // So, I decided to use assert for debug testing.
 
-        assert(false);
-
-        ret = RDBI_NOT_CONNECTED;
-    }
-
-
-    assert(RDBI_SUCCESS == ret
-           || RDBI_NOT_CONNECTED == ret
-           || RDBI_GENERIC_ERROR == ret);
-
     return ret;
 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgconn_status.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -31,6 +31,6 @@
  * @return Returns RDBI_SUCCESS if context connection is established,
  * RDBI_NOT_CONNECTED otherwise or RDBI_GENERIC_ERROR if error occured.
  */
-int postgis_pgconn_status (PGconn* context);
+int postgis_pgconn_status (PGconn* conn);
 
 #endif /* POSTGIS_PGCONN_STATUS_H */

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -17,25 +17,34 @@
 */
 
 #include "stdafx.h"
-
 #include "pgresult_error.h"
+#include "set_err_msg.h"
+#include <string.h>
 
-void postgis_pgresult_error (const PGresult* result, const char *msg)
+void postgis_pgresult_error (
+    postgis_context_def *context,
+    const PGresult* pgresult
+)
 {
     ExecStatusType status;
 
-    if (NULL != result)
+    if (NULL != context)
     {
-        status = PQresultStatus(result);
-        if (PGRES_COMMAND_OK != status)
+        /* Reset last error message. */
+        memset(context->postgis_last_err_msg, 0, RDBI_MSG_SIZE);
+
+        if (NULL != pgresult)
         {
-            printf("\n[%s] %s\n",
-                PQresStatus(status),
-                PQresultErrorMessage(result));
+            status = PQresultStatus(pgresult);
+            if ((PGRES_EMPTY_QUERY != status)
+                && (PGRES_COMMAND_OK != status)
+                && (PGRES_TUPLES_OK != status))
+            {
+                sprintf(context->postgis_last_err_msg,
+                        "[%s] %s",
+                        PQresStatus(status),
+                        PQresultErrorMessage(pgresult));
+            }
         }
     }
-    else if (NULL != msg)
-    {
-        fprintf(stderr, " [PostgreSQL] %s\n", msg);
-    }
 }
\ No newline at end of file

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/pgresult_error.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -18,13 +18,17 @@
 #ifndef POSTGIS_PGRESULT_ERROR_H
 #define POSTGIS_PGRESULT_ERROR_H
 
-#ifdef _WIN32
-#pragma once
-#endif // _WIN32
+#include "local.h"
 
 /**
- * Prints error message for PGresult status.
+ * Sets PGresult status error message to as current context last error.
+ * @param context [out] - pointer to current PostGIS session context.
+ *  The function updates passed context by setting last error message.
+ * @param pgresult [in] - pointer to last PostgreSQL command result.
  */
-void postgis_pgresult_error (const PGresult* result, const char *msg);
+void postgis_pgresult_error (
+    postgis_context_def *context,
+    const PGresult* pgresult
+);
 
 #endif /* POSTGIS_PGRESULT_ERROR_H */
\ No newline at end of file

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/rdbi_init.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/rdbi_init.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/rdbi_init.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -18,6 +18,7 @@
 
 #include "stdafx.h"
 
+#include "rdbi_init.h"
 #include "bind.h"
 #include "commit.h"
 #include "connect.h"
@@ -29,18 +30,15 @@
 #include "execute.h"
 #include "fetch.h"
 #include "fre_cursor.h"
-/*
 #include "get_gen_id.h"
-*/
 #include "get_msg.h"
 #include "null.h"
-#include "rdbi_init.h"
 #include "run_sql.h"
 #include "set_schema.h"
 #include "sql.h"
 #include "term.h"
+#include "vndr_info.h"
 #include "vndr_name.h"
-#include "vndr_info.h"
 
 #include <string.h> // memset()
 #include <assert.h>
@@ -81,7 +79,7 @@
         methods->bind       = (int (*)(void*, char*, char*, int, int, char*, void*))postgis_bind;
         methods->fetch      = (int (*)(void*, char*, int, int, int, int*))postgis_fetch;
         methods->get_msg    = (void (*)(void*, char*))postgis_get_msg;
-        methods->get_msgW   = NULL; // (void (*)(void*, wchar_t*))mysql_get_msgW;
+        methods->get_msgW   = (void (*)(void*, wchar_t*))postgis_get_msgW;
         methods->alcnullind = (int (*)(void*, int, char**))postgis_alloc_null_ind; 
         methods->set_null   = (void (*)(void*, void*, int, int))postgis_set_null;
         methods->set_nnull  = (void (*)(void*, void*, int, int))postgis_set_not_null;
@@ -97,15 +95,15 @@
         methods->objects_act  = NULL;
         methods->objects_get  = NULL;
         methods->objects_deac = NULL;
-        methods->users_act   = NULL;
-        methods->users_get   = NULL;
-        methods->users_deac  = NULL;
-        methods->usr_exists  = NULL;
-        methods->get_con_var = NULL;
-        methods->do_break    = NULL;
-        methods->set_schema  = (int (*)(void*, const char*))postgis_set_schema;
-        methods->set_schemaW = NULL;
-        methods->vndr_info   = (int (*)(void*, rdbi_vndr_info_def*))postgis_vndr_info;
+        methods->users_act    = NULL;
+        methods->users_get    = NULL;
+        methods->users_deac   = NULL;
+        methods->usr_exists   = NULL;
+        methods->get_con_var  = NULL;
+        methods->do_break     = NULL;
+        methods->set_schema   = (int (*)(void*, const char*))postgis_set_schema;
+        methods->set_schemaW  = NULL;
+        methods->vndr_info    = (int (*)(void*, rdbi_vndr_info_def*))postgis_vndr_info;
         methods->geom_srid_set   = NULL;
         methods->geom_dimens_set = NULL;
         methods->get_geoms_ext   = NULL;
@@ -125,12 +123,16 @@
         methods->capabilities.supports_autoincrement = 1;
         methods->capabilities.supports_unicode       = 0;
         methods->capabilities.supports_int64_binding = 1;
-        methods->get_gen_id = NULL; //(int (*)(void*, char*, int*))postgis_get_gen_id;
 
+        methods->get_gen_id = (int (*)(void*, const char*, const char*, int*))postgis_get_gen_id;
+
         *contextp = context;
         ret = RDBI_SUCCESS;
     }
 
+    /*
+     * TODO: mloskot - Remove before release
+     */
     assert(NULL != context);
 
     return (ret);

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/run_sql.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/run_sql.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/run_sql.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -1,103 +1,101 @@
-/*
- * Copyright (C) 2006 Refractions Research, Inc. 
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser
- * General Public License as published by the Free Software Foundation.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#include "stdafx.h"
-
-#include "run_sql.h"
-#include "pgconn_status.h"
-#include "pgresult_status.h"
-#include "pgresult_clear.h"
-#include <stdlib.h> /* strtol */
-#include <assert.h>
-#include <errno.h>
-
-int postgis_run_sql(
-    postgis_context_def *context,
-    char* sql,
-	int isddl,
-    int* rows_processed
-)
-{
-    PGconn* postgis = NULL;
-    PGresult* pgresult = NULL;
-    char* buf = NULL;
-    long  rows = 0;
-    int ret = RDBI_GENERIC_ERROR;
-
-    assert(NULL != context);
-    assert(NULL != sql);
-
-    if (-1 == context->postgis_current_connect)
-    {
-        ret = RDBI_NOT_CONNECTED;
-    }
-    else
-    {
-		if (isddl > 0)
-        {
-			postgis = context->postgis_connections[context->postgis_current_connect2];
-        }
-		else
-        {
-			postgis = context->postgis_connections[context->postgis_current_connect];
-        }
-
-        ret = postgis_pgconn_status(postgis);
-        if (RDBI_SUCCESS == ret)
-        {
-            // SQL statement execution
-            pgresult = PQexec(postgis, sql);
-
-            ret = postgis_pgresult_status(pgresult);
-            if (RDBI_SUCCESS == ret)
-            {
-                if (NULL != rows_processed)
-                {
-                    rows = 0;
-                    if (PGRES_TUPLES_OK == PQresultStatus(pgresult))
-                    {
-                        buf = PQcmdTuples(pgresult);
-                        rows = strtol(buf, NULL, 10);
-                        assert(ERANGE != errno && EINVAL != errno);
-                    }
-
-                    (*rows_processed) = (int)rows;
-                }
-            }
-            else
-            {
-                /* Retrieve error message associated with last command. */
-                char* p = PQresultErrorMessage(pgresult);
-
-                memset(context->postgis_last_err_msg, '\0', RDBI_MSG_SIZE);
-                strncpy(context->postgis_last_err_msg, p, RDBI_MSG_SIZE);
-                context->postgis_last_err_msg[RDBI_MSG_SIZE - 1] = '\0';
-
-                /*
-                * TODO: mloskot - Find better error code or map PgSQL error codes to RDBI.
-                */
-                ret = RDBI_RESOURCE_LOCK;
-            }
-
-            /* Clear PostgreSQL resources. */
-            postgis_pgresult_clear(pgresult);
-        }
-    }
-
-    return (ret);
-}
+/*
+ * Copyright (C) 2006 Refractions Research, Inc. 
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "stdafx.h"
+
+#include "run_sql.h"
+#include "conn_status.h"
+#include "pgconn_status.h"
+#include "pgresult_status.h"
+#include "pgresult_clear.h"
+#include "set_err_msg.h"
+
+#include <stdlib.h> /* strtol */
+#include <errno.h>  /* ERANGE, EINVAL */
+#include <assert.h>
+
+int postgis_run_sql(
+    postgis_context_def *context,
+    char* sql,
+	int isddl,
+    int* rows_processed
+)
+{
+    PGconn* postgis = NULL;
+    PGresult* pgresult = NULL;
+    char* buf = NULL;
+    long conn_index = 0;
+    long rows = 0;
+    int ret = RDBI_GENERIC_ERROR;
+
+    assert(NULL != context);
+    assert(NULL != sql);
+
+    ret = postgis_conn_status(context);
+    if (RDBI_SUCCESS == ret)
+    {
+		if (isddl > 0)
+            conn_index = context->postgis_current_connect2;
+		else
+			conn_index = context->postgis_current_connect;
+
+        postgis = context->postgis_connections[conn_index];
+        assert(NULL != postgis);
+
+        ret = postgis_pgconn_status(postgis);
+        if (RDBI_SUCCESS == ret)
+        {
+            /* SQL statement execution */
+            pgresult = PQexec(postgis, sql);
+
+            ret = postgis_pgresult_status(pgresult);
+            if (RDBI_SUCCESS == ret)
+            {
+                if (NULL != rows_processed)
+                {
+                    rows = 0;
+                    if (PGRES_TUPLES_OK == PQresultStatus(pgresult))
+                    {
+                        buf = PQcmdTuples(pgresult);
+                        rows = strtol(buf, NULL, 10);
+                        assert(ERANGE != errno && EINVAL != errno);
+                    }
+
+                    (*rows_processed) = (int)rows;
+                }
+            }
+            else
+            {
+                /* Retrieve error message associated with last command. */
+                buf = PQresultErrorMessage(pgresult);
+
+                postgis_set_err_msg(context, buf);
+
+                /*
+                 * TODO: mloskot - Find better error code or map PgSQL error codes to RDBI.
+                 */
+                ret = RDBI_RESOURCE_LOCK;
+            }
+
+            /* Clear PostgreSQL resources. */
+            postgis_pgresult_clear(pgresult);
+        }
+    }
+
+    return (ret);
+}

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -22,118 +22,61 @@
 #include "connect.h"
 #include "disconnect.h"
 #include "conn_status.h"
-#include <string.h> /* strncpy() */
-#include <malloc.h> /* alloca() */
+#include "pgresult_clear.h"
+#include "pgresult_error.h"
+#include "pgresult_status.h"
+#include <string.h> /* memset(), strlen(), strncpy() */
+#include <malloc.h>
 #include <assert.h>
 
-int postgis_set_schema(postgis_context_def *context, char* schema_name)
+int postgis_set_schema(postgis_context_def *context, const char* schema_name)
 {
     PGconn* postgis = NULL;
-    int conn_index = 0;
+    PGresult* pgresult = NULL;
+    long conn_index = 0;
     int ret = RDBI_GENERIC_ERROR;
 
-    char* pgdb = NULL;
-    char* pghost = NULL;
-    char* pgport = DEF_PGPORT_STR;  /* Default port for PostgreSQL */
+    char* sql = NULL;
+    size_t sql_len = 0;
+    const size_t sql_part_len = 20;
 
-    char* pglogin = NULL;
-    char* pgpwd = NULL;
-
-    /* Connection string - need to be freed */
-    char* connstr = NULL;
-    size_t connstr_len = 0;
-
     /* Strings manipulation helpers */
-    char* buf = NULL;
-    size_t buf_len = 0;
     
     assert(NULL != context);
     assert(NULL != schema_name);
 
-    if (RDBI_SUCCESS == postgis_conn_status(context))
+    ret = postgis_conn_status(context);
+    if (RDBI_SUCCESS == ret)
     {
         conn_index = context->postgis_current_connect;
         postgis  = context->postgis_connections[conn_index];
-        if (NULL != postgis)
-        {
-            /*
-             * Collect connection string elements.
-             */
+        assert(NULL != postgis);
 
-            /* database + @ */
-            connstr_len = strlen(schema_name) + 1;
+        /*
+         * SET search_path TO <new_schema_name>
+         */
 
-            buf = PQhost(postgis);
-            buf_len = strlen(buf) + 1;
-            pghost = (char*)alloca(buf_len);
-            strncpy(pghost, buf, buf_len);
+        sql_len = strlen(schema_name) + sql_part_len;
+        sql = (char*)malloc(sql_len);
+        if (NULL == sql)
+            ret = RDBI_MALLOC_FAILED;
+        else
+        {
+            memset(sql, 0, sql_len);
+            sprintf(sql, "SET search_path TO %s", schema_name);
 
-            /* database + @ + host + : */
-            connstr_len = connstr_len + buf_len;
-
-            buf = PQport(postgis);
-            buf_len = strlen(buf) + 1;
-            pgport = (char*)alloca(buf_len);
-            strncpy(pgport, buf, buf_len);
-
-            /* database + @ + host + : + port */
-            connstr_len = connstr_len + buf_len;
-
-            /*
-             * Collect authorization parameters.
-             */
-
-            buf = PQuser(postgis);
-            buf_len = strlen(buf) + 1;
-            pglogin = (char*)malloc(buf_len);
-            memset(pglogin, '\0', buf_len);
-            strncpy(pglogin, buf, buf_len);
-
-            buf = PQpass(postgis);
-            buf_len = strlen(buf) + 1;
-            pgpwd = (char*)malloc(buf_len);
-            memset(pgpwd, '\0', buf_len);
-            strncpy(pgpwd, buf, buf_len);
-
-            /*
-             * Disconnect from current schema (database).
-             */
-            ret = postgis_disconnect(context);
-            if (RDBI_SUCCESS == ret)
+            pgresult = PQexec(postgis, sql);
+            ret = postgis_pgresult_status(pgresult);
+            if (RDBI_SUCCESS != ret)
             {
-                /*
-                 * Make new connection string: database at host:port
-                 */
-                connstr_len = connstr_len + 1;
-                connstr = (char*)malloc(connstr_len);
-                if (NULL == connstr)
-                {
-                    return RDBI_MALLOC_FAILED;
-                }
-
-                memset(connstr, '\0', connstr_len);
-                strncpy(connstr, schema_name, strlen(schema_name)); /* Excluding null */
-                strncat(connstr, "@", 1);
-                strncat(connstr, pghost, strlen(pghost));
-                strncat(connstr, ":", 1);
-                strncat(connstr, pgport, strlen(pgport));
-
-                assert(strlen(connstr) <= connstr_len);
-
-                /*
-                * Re-connect using new schema name.
-                */
-
-                // TODO - mloskot: Confirm if disconnect-connect chain will 
-                // keep the same previously assigned connection ID (index).
-                ret = postgis_connect(context, connstr, pglogin, pgpwd, NULL, &conn_index);
-
-                free(connstr);
-                free(pgpwd);
-                free(pglogin);
+                postgis_pgresult_error(context, pgresult);
             }
 
-        } /* if (NULL != postgis) */
+            postgis_pgresult_clear(pgresult);
+        }
+
+        free(sql);
+        sql = NULL;
     }
 
     return (ret);

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/set_schema.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -23,16 +23,12 @@
 
 /**
  * Change schema for current session.
- * Current schema is changed in following sequence of operations:
- * - disconnect of current database
- * - alter connection parameters with new schema name (database)
- * - connect using new parametres
  *
  * @param context [in] - pointer to PostGIS session context.
- * @param schema_name [in] - name of new schema (database) to set
- *  for current session.
+ * @param schema_name [in] - name of PostgreSQL schema being switched to
+ *  for the current session.
  * @return RDBI_SUCCESS on success, error code otherwise.
  */
-int postgis_set_schema(postgis_context_def *context, char* schema_name);
+int postgis_set_schema(postgis_context_def *context, const char* schema_name);
 
 #endif /* POSTGIS_SET_SCHEMA_H */
\ No newline at end of file

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/sql.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/sql.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/sql.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -20,83 +20,75 @@
 
 #include "fre_cursor.h"
 #include "sql.h"
-#include "pgconn_status.h"
+#include "conn_status.h"
 #include "pgresult_clear.h"
 #include "pgresult_error.h"
+#include "pgresult_status.h"
+#include "set_err_msg.h"
 
 // TODO: mloskot - To be removed for release.
 #include <assert.h>
 
-int postgis_sql (
-    postgis_context_def *context,
-    char *cursor,
-    char *sql,
-    int defer, /* not used */
-    char *verb,
-    void *ptree, /* dbi_prse_tree_def - not used */
-    char *cursor_coc) /* not used */
+int postgis_sql (postgis_context_def *context,
+                 char *cursor,
+                 char *sql,
+                 int defer,         /* not used */
+                 char *verb,        /* not used */
+                 void *ptree,       /* not used */
+                 char *cursor_coc)  /* not used */
 {
     postgis_cursor_def* curs = NULL;
     PGconn* postgis = NULL;
     PGresult* pgresult = NULL;
-    ExecStatusType pgstatus;
-    int result = 0;
     int ret = RDBI_GENERIC_ERROR;
 
-    if (-1 == context->postgis_current_connect)
+    assert(NULL != context);
+
+    ret = postgis_conn_status(context);
+    if (RDBI_SUCCESS == ret)
     {
-        ret = RDBI_NOT_CONNECTED;
-    }
-    else
-    {
         postgis = context->postgis_connections[context->postgis_current_connect];
-        if (RDBI_SUCCESS != postgis_pgconn_status(postgis))
-            ret = RDBI_NOT_CONNECTED;
+        assert(NULL != postgis);
+
+        curs = (postgis_cursor_def*)cursor;
+        if (NULL == curs)
+            ret = RDBI_GENERIC_ERROR;
         else
         {
-            curs = (postgis_cursor_def*)cursor;
-            if (NULL == curs)
-                ret = RDBI_GENERIC_ERROR;
-            else
-            {
-                // TODO - mloskot: Finish process of cursor allocation.
+            // TODO - mloskot: Finish process of cursor allocation.
 
-                assert(NULL != curs->stmt_name);
+            assert(NULL != curs->stmt_name);
 
-                postgis_fre_binds (curs);
+            postgis_fre_binds (curs);
 
-                pgresult = PQprepare(postgis, curs->stmt_name,
-                                     sql, curs->bind_count, NULL);
-                if (NULL != pgresult)
+            pgresult = PQprepare(postgis, curs->stmt_name,
+                sql, curs->bind_count, NULL);
+            if (NULL != pgresult)
+            {
+                ret = postgis_pgresult_status(pgresult);
+                if (RDBI_SUCCESS != ret)
                 {
-                    // TODO - mloskot: Change to common status function
-                    pgstatus = PQresultStatus(pgresult);
-                    if (PGRES_COMMAND_OK != pgstatus)
-                    {
-                        postgis_pgresult_error (pgresult, "prepare failed");
-                        ret = RDBI_GENERIC_ERROR;
-                    }
-                    else
-                    {
-                        // Successfully prepared statement
-                        ret = RDBI_SUCCESS;
-                    }
+                    postgis_pgresult_error(context, pgresult);
+                    ret = RDBI_GENERIC_ERROR;
                 }
-                else
-                {
-                    /*
-                     * NULL indicates out-of-memory or inability to send the command at all.
-                     */
-                    postgis_pgresult_error (pgresult, "prepare failed");
-                    ret = RDBI_MALLOC_FAILED;
-                }
+            }
+            else
+            {
+                /*
+                * NULL indicates a fatal error like out-of-memory or
+                * inability to send the command at all.
+                */
+                postgis_set_err_msg(context, PQerrorMessage(postgis));
+                ret = RDBI_MALLOC_FAILED;
+            }
 
-                // Release PostgreSQL resources for query result
-                postgis_pgresult_clear(pgresult);
+            /*
+            * Release PostgreSQL resources for query result.
+            */
+            postgis_pgresult_clear(pgresult);
 
-            }
         }
     }
- 
-    return (ret);
+
+    return ret;
 }

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/stdafx.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/stdafx.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/stdafx.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -1,72 +1,86 @@
-/*
- * Copyright (C) 2006 Refractions Research, Inc. 
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser
- * General Public License as published by the Free Software Foundation.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifndef POSTGIS_DRIVER_STDAFX_H
-#define POSTGIS_DRIVER_STDAFX_H
-
-#ifdef _WIN32
-/* Exclude rarely-used stuff from Windows headers. */
-# define WIN32_LEAN_AND_MEAN 
-# include <windows.h>
-#endif /* _WIN32 */
-
-/* Standard library */
-#include <stdio.h>
-#include <string.h>
-
-/* RDBI interface */
-#include <Inc/rdbi.h>
-
-/* PostgreSQL client library */
-#include <libpq-fe.h>
-
-/*
- * POSTGISDR_CALL
- *
- * The following macro allowis various calling conventions
- * on the RDBI PostGIS API driver.
- */
-#ifdef _WIN32
-# define POSTGISDR_CALL   __declspec(dllexport)
-#else
-# define POSTGISDR_CALL
-#endif /* _WIN32 */
-
-
-/*
- * Helper macro that determines the number of elements
- * in a statically-sized array.
- * NOTE: This doesn't work for dynamically-sized arrays.
- */
-#define ELEMENTS(x) (sizeof(x)/sizeof(x[0]))
-
-
-/*
- * DEF_PGPORT
- *
- * NOTE: This macro has been copied directly from pg_config.h file,
- * from PostgreSQL sources.
- *
- * Define to the default TCP port number on which the server listens and to
- * which clients will try to connect.
- */
-#define DEF_PGPORT 5432
-#define DEF_PGPORT_STR "5432"
-
-
-#endif /* POSTGIS_DRIVER_STDAFX_H */
+/*
+ * Copyright (C) 2006 Refractions Research, Inc. 
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef POSTGIS_DRIVER_STDAFX_H
+#define POSTGIS_DRIVER_STDAFX_H
+
+#ifdef _WIN32
+/* Exclude rarely-used stuff from Windows headers. */
+# define WIN32_LEAN_AND_MEAN 
+# include <windows.h>
+#endif /* _WIN32 */
+
+/* Standard library */
+#include <stdio.h>  /* snprintf() */
+#include <string.h>
+
+/* RDBI interface */
+#include <Inc/rdbi.h>
+
+/* PostgreSQL client library */
+#include <libpq-fe.h>
+
+/*
+ * POSTGISDR_CALL
+ *
+ * The following macro allowis various calling conventions
+ * on the RDBI PostGIS API driver.
+ */
+#ifdef _WIN32
+# define POSTGISDR_CALL   __declspec(dllexport)
+#else
+# define POSTGISDR_CALL
+#endif /* _WIN32 */
+
+
+/*
+ * Helper macro that determines the number of elements
+ * in a statically-sized array.
+ * NOTE: This doesn't work for dynamically-sized arrays.
+ */
+#define ELEMENTS(x) (sizeof(x)/sizeof(x[0]))
+
+
+/*
+ * DEF_PGPORT
+ *
+ * NOTE: This macro has been copied directly from pg_config.h file,
+ * from PostgreSQL sources.
+ *
+ * Define to the default TCP port number on which the server listens and to
+ * which clients will try to connect.
+ */
+#define DEF_PGPORT 5432
+#define DEF_PGPORT_STR "5432"
+
+/*
+ * C/POSIX prototypes
+ */
+
+#ifdef _WIN32
+#define snprintf _snprintf
+#endif
+
+#ifdef _WIN32
+    typedef __int64 rdbi_int64_t;
+#else
+    typedef long long rdbi_int64_t;
+#endif /* _WIN32 */
+
+
+#endif /* POSTGIS_DRIVER_STDAFX_H */

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.c
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.c	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.c	2007-01-23 02:08:10 UTC (rev 676)
@@ -82,6 +82,10 @@
         /*
         * Type not recognized.
         */
+
+        // TODO: mloskot - Should we use OID of UNKNOWN type - 705 - or return Zero?
+        ret = PGSQL_TYPE_UNKNOWN;
+
         ret = 0;
     }
 
@@ -152,17 +156,25 @@
         case PGSQL_TYPE_VARCHAR:
             length = (typemod - PGSQL_VAR_HDRSZ);
             if (length > 0)
-                ret = RDBI_FIXED_CHAR; /* character varying WITH a length specifier. */
+                // TODO: mloskot - Find a better type for VARCHAR(N)
+                ret = RDBI_STRING; /* character varying WITH a length specifier. */
             else
                 ret = RDBI_STRING; /* character varying WITHOUT a length specifier. */
             break;
 
+        case PGSQL_TYPE_NAME:       /* default maximum length is 64 characters. */
+            ret = RDBI_FIXED_CHAR; 
+            break;
         case PGSQL_TYPE_TEXT:
             ret = RDBI_STRING;
             break;
         case PGSQL_TYPE_BLOB:
             ret = RDBI_BLOB;
             break;
+        case PGSQL_TYPE_UNKNOWN:
+            // TODO: mloskot - Should we cast to STRING?
+            ret = -1;
+            break;
         default:
             /* Type not recognized or identifies PostGIS geometry, see below */
             ret = -1;
@@ -216,6 +228,42 @@
     return oid;
 }
 
+int postgis_get_name_length(PGconn* conn)
+{
+    PGresult* pgresult = NULL; 
+    int length = 0;
+    const char* query = "SELECT typlen FROM pg_type WHERE typname = 'name'";
+
+    assert(NULL != conn);
+
+    pgresult = PQexec(conn, query);
+    if (NULL != pgresult)
+    {
+        if (PGRES_TUPLES_OK == PQresultStatus(pgresult) && PQntuples(pgresult) > 0)
+        {
+            length = strtol(PQgetvalue(pgresult, 0, 0), NULL, 10);
+
+            if (LONG_MIN == length || LONG_MAX == length || 0 == length)
+            {
+                /* Report if value overflow occured or no conversion was performed */
+                length = -1;
+
+                /*
+                 * TODO - print error
+                 */
+                assert(!"strtol value overflow");
+            }
+        }
+    }
+
+    PQclear(pgresult);
+
+    /*
+     * 0 - failure
+     */
+    return length;
+}
+
 int postgis_get_numeric_precision(const PGresult* pqres, int column_number)
 {
     int precision = PGSQL_VAR_NOINFO; /* No information available */
@@ -261,7 +309,8 @@
     {
         /* Check if given column is of type of fixed-length CHARACTER */
         if (PGSQL_TYPE_CHAR == PQftype(pqres, column_number)
-            || PGSQL_TYPE_BPCHAR == PQftype(pqres, column_number))
+            || PGSQL_TYPE_BPCHAR == PQftype(pqres, column_number)
+            || PGSQL_TYPE_NAME == PQftype(pqres, column_number))
         {
             fmod = PQfmod(pqres, column_number);
             if (PGSQL_VAR_NOINFO != fmod)
@@ -280,7 +329,8 @@
     if (NULL != pqres)
     {
         /* Check if given column is of character varying type */
-        if (PGSQL_TYPE_VARCHAR == PQftype(pqres, column_number))
+        if (PGSQL_TYPE_VARCHAR == PQftype(pqres, column_number)
+            || PGSQL_TYPE_NAME == PQftype(pqres, column_number))
         {
             fmod = PQfmod(pqres, column_number);
             if (PGSQL_VAR_NOINFO != fmod)

Modified: branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.h
===================================================================
--- branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.h	2007-01-23 02:06:35 UTC (rev 675)
+++ branches/fdordbms-postgis/Providers/GenericRdbms/Src/PostGIS/Driver/type.h	2007-01-23 02:08:10 UTC (rev 676)
@@ -31,15 +31,31 @@
 enum enum_varlena_details
 {
     PGSQL_VAR_NOINFO = -1, /**< No information is available */
-    PGSQL_VAR_HDRSZ  = 4   /**< Represented as sizeof(int) */
+    PGSQL_VAR_HDRSZ  = 4,   /**< Represented as sizeof(int) */
+
+    /* Max size of variable unlimited length text is
+     * arbitrarily assumed as 64 KB
+     */
+    PGSQL_VARCHAR_MAX_SIZE = 65536  
 };
 
+/*
+ * Definition of characteristics of boolean type.
+ */
+enum enum_boolean_details
+{
+    PGSQL_BOOLEAN_SIZE = 1,
+    PGSQL_BOOLEAN_RDBI_SIZE = 2
+};
+
 /**
  * This enum maps PostgreSQL OIDs to types enumeration.
  * Enumerators are assigned with values from PostgreSQL 'pg_type' table.
  */
 enum enum_field_types
 {
+    PGSQL_TYPE_UNKNOWN = 705, // UNKNOWN
+
     PGSQL_TYPE_BOOL = 16, // bool
 
     PGSQL_TYPE_INT2 = 21, // int2, smallint
@@ -62,6 +78,7 @@
     PGSQL_TYPE_BPCHAR      = 1042, // bpchar, the same as char
     PGSQL_TYPE_VARCHAR     = 1043, // varchar
     PGSQL_TYPE_TEXT        = 25, // text 
+    PGSQL_TYPE_NAME        = 19, // name, length 64 characters
 
     PGSQL_TYPE_BLOB        = 17, // bytea
 
@@ -103,6 +120,16 @@
 Oid postgis_get_geometry_oid(PGconn* conn);
 
 /**
+ * Retrieves default maximum length of NAME type.
+ * NAME type is used internally by PostgreSQL, in pg_catalog tables and views.
+ * Default length is set in compile time using NAMEDATALEN constant.
+ *
+ * @param conn - connection to PostgreSQL database.
+ * @return Value of maximum length for NAME type.
+ */
+int postgis_get_name_length(PGconn* conn);
+
+/**
  * Retrieves precision component for type of given column.
  * The precision is decoded form value returned by PQfmod() function.
  *



More information about the fdo-commits mailing list