[fdo-commits] r668 - in trunk/Providers/GenericRdbms: Inc/Rdbi Src/Fdo/Pvc Src/Gdbi Src/MySQL/Driver Src/MySQL/SchemaMgr Src/MySQL/SchemaMgr/Ph Src/ODBCDriver Src/Rdbi Src/UnitTest/MySql

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 22 17:00:15 EST 2007


Author: barbarazoladek
Date: 2007-01-22 17:00:15 -0500 (Mon, 22 Jan 2007)
New Revision: 668

Added:
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.c
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.h
   trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.cpp
Modified:
   trunk/Providers/GenericRdbms/Inc/Rdbi/methods.h
   trunk/Providers/GenericRdbms/Inc/Rdbi/proto.h
   trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcInsertHandler.cpp
   trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcUpdateHandler.cpp
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.cpp
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.h
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.cpp
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.h
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.c
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.h
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/Makefile.am
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/MySqlDriver.vcproj
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/bind.c
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/execute.c
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/local.h
   trunk/Providers/GenericRdbms/Src/MySQL/Driver/rdbi_init.c
   trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/MySqlSchemaMgr.vcproj
   trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.h
   trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/Makefile.am
   trunk/Providers/GenericRdbms/Src/ODBCDriver/geom.c
   trunk/Providers/GenericRdbms/Src/Rdbi/geom_srid.c
   trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.cpp
   trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.h
Log:
MySql Provider: Set SRID value for geometry columns

Modified: trunk/Providers/GenericRdbms/Inc/Rdbi/methods.h
===================================================================
--- trunk/Providers/GenericRdbms/Inc/Rdbi/methods.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Inc/Rdbi/methods.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -130,7 +130,7 @@
     int  (*set_schema)(void*,const char*);
     int  (*set_schemaW)(void*,const wchar_t*);
     int  (*vndr_info)(void*, rdbi_vndr_info_def *);
-    int  (*geom_srid_set)(void*,char*,long);
+    int  (*geom_srid_set)(void*,char*,char*,long);
     int  (*geom_dimens_set)(void*,char*,int);
     int  (*get_geoms_ext)( void *, char *, char *,  pIGeometry_def *);
     int  (*lob_create_ref)(void*,char*,void**);

Modified: trunk/Providers/GenericRdbms/Inc/Rdbi/proto.h
===================================================================
--- trunk/Providers/GenericRdbms/Inc/Rdbi/proto.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Inc/Rdbi/proto.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -413,6 +413,7 @@
 int rdbi_geom_srid_set (
         rdbi_context_def *context,
         int sqlid,
+		char *col_name,
         long srid );
 
 int rdbi_geom_dimens_set (

Modified: trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcInsertHandler.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcInsertHandler.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcInsertHandler.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -1185,6 +1185,10 @@
                         mConnection->GetGdbiCommands()->bind(gid, temp, RDBI_GEOMETRY, bind[bind_no].len,
                                             (char *)&bind[bind_no].value.strvalue, &bind[bind_no].null_ind);
                         bind_no++;
+						const FdoSmPhColumnP gColumn = ((FdoSmLpSimplePropertyDefinition*)geomProp)->GetColumn();
+						FdoSmPhColumnGeomP geomCol = gColumn.p->SmartCast<FdoSmPhColumnGeom>();
+						if (geomCol)
+							mConnection->GetGdbiCommands()->geom_srid_set(gid, temp, (long)geomCol->GetSRID());
                     }
                     break;
                 case FdoSmOvGeometricColumnType_Double:

Modified: trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcUpdateHandler.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcUpdateHandler.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Fdo/Pvc/FdoRdbmsPvcUpdateHandler.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -686,6 +686,11 @@
 
 							if( geom != NULL )
 							{
+								// Set SRID for the geometry column
+								const FdoSmPhColumnP gColumn = ((FdoSmLpSimplePropertyDefinition*)geomPropDef)->GetColumn();
+								FdoSmPhColumnGeomP geomCol = gColumn.p->SmartCast<FdoSmPhColumnGeom>();
+								if (geomCol)
+									statement->geom_srid_set(bindIndex-1, (long)geomCol->GetSRID());
 								FdoStringsP geomSiKeys;
 								
 								const FdoSmPhColumn *columnSi1 = geomPropDef->RefColumnSi1();

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -19,6 +19,9 @@
 #include "stdafx.h"
 #include "GdbiCommands.h"
 #include "FdoCommonOSUtil.h"
+#ifdef HAVE_GEOM_INFO_TYPE
+#include <inc/geometry/fgf/AllGeometry_c.h>
+#endif
 
 GdbiCommands::GdbiCommands( rdbi_context_def* rdbi_context ):
 m_pRdbiContext( rdbi_context )
@@ -614,3 +617,29 @@
 
 	return autoCmt;
 }
+int GdbiCommands::geom_to_fgf ( 
+    int             sqlid,
+    void *          rdbmsGeometryInfo_I,
+    void **         fgfGeometryByteArray_O )
+{
+#ifdef HAVE_GEOM_INFO_TYPE
+    RdbmsGeometryValueInfo * geomInfo2 = (RdbmsGeometryValueInfo *) rdbmsGeometryInfo_I;
+
+    int rc = ::rdbi_geom_to_fgf(m_pRdbiContext, sqlid, geomInfo2, (pByteArray_def *)fgfGeometryByteArray_O);
+
+    return rc;
+#else
+    return FALSE;
+#endif
+}
+int GdbiCommands::geom_srid_set(
+	int				sqlid,
+	char			*geom_col_name,
+	long			srid)
+{
+	int rc = ::rdbi_geom_srid_set(m_pRdbiContext, sqlid, geom_col_name, srid);
+	if (rc == RDBI_SUCCESS)
+		return rc;
+
+	return RDBI_GENERIC_ERROR;
+}
\ No newline at end of file

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiCommands.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -231,6 +231,15 @@
 	int lob_create_ref(int sqlid, void **lob_ref);
 	int lob_destroy_ref(int sqlid, void *lob_ref);
 
+    int geom_to_fgf ( 
+            int             sqlid,
+            void *          rdbmsGeometryInfo_I,
+            void **         fgfGeometryByteArray_O );
+
+	int geom_srid_set(
+			int				sqlid,
+			char			*geom_col_name,
+			long			srid );
 };
 
 #endif // _GDBICOMMANDS_

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -147,3 +147,13 @@
 	}
 	throw new GdbiException(L"Not a valid query");
 }
+
+int GdbiStatement::geom_srid_set(
+				int		parmIndex,
+				long	srid
+				)
+{
+	return m_pGdbiCommands->geom_srid_set(m_QueryId->GetQueryId(), 
+		                                  FdoCommonOSUtil::itoa(parmIndex, buffer),
+										  srid);
+}

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiStatement.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -81,6 +81,10 @@
 	bool SupportsInt64Binding();
 
 	int set_array_size(int arraySize);
+
+	int geom_srid_set(
+			int				parmIndex,
+			long			srid );
 };
 
 #endif //_GDBISTATEMENT_

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -48,12 +48,11 @@
     FDO_SAFE_RELEASE(g);
 }
 
-char *WkbFromGeometry (void *geometry, int *size)
+char *WkbFromGeometry (void *geometry, int *size, int srid)
 {
     FdoPtr<FdoFgfGeometryFactory> factory;
     FdoPtr<FdoByteArray> array;
     void *ret = NULL;
-	
 	*size = 0;
 
     if ( geometry == NULL )
@@ -66,6 +65,7 @@
         *size = array->GetCount () + 4;
         ret = malloc (*size);
         memset (ret, 0, *size);
+		memcpy(ret, (void *)&srid, 4);
         memmove (((char*)ret) + 4, array->GetData (), *size - 4);
     }
     catch (...)

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/Geometry.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -26,6 +26,6 @@
 
 extern   void *GeometryFromWkb (void *wkb, unsigned long size);
 extern    void FreeGeometry (void *geometry);
-extern    char *WkbFromGeometry (void *geometry, int* size);
+extern    char *WkbFromGeometry (void *geometry, int* size, int srid);
 
 #endif // GEOMETRY_H

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/Makefile.am
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/Makefile.am	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/Makefile.am	2007-01-22 22:00:15 UTC (rev 668)
@@ -33,6 +33,7 @@
   execute.c \
   fetch.c \
   fre_cursor.c \
+  geom_srid.c	\
   get_gen_id.c \
   get_msg.c \
   init.c \
@@ -64,6 +65,7 @@
   fetch.h \
   fre_cursor.h \
   Geometry.h \
+  geom_srid.h	\
   get_gen_id.h \
   get_msg.h \
   init.h \

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/MySqlDriver.vcproj
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/MySqlDriver.vcproj	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/MySqlDriver.vcproj	2007-01-22 22:00:15 UTC (rev 668)
@@ -524,6 +524,26 @@
 				</FileConfiguration>
 			</File>
 			<File
+				RelativePath=".\geom_srid.c"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						CompileAs="2"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						CompileAs="2"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
 				RelativePath=".\Geometry.c"
 				>
 				<FileConfiguration

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/bind.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/bind.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/bind.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -36,6 +36,7 @@
     int index;
     int type;
     MYSQL_BIND *binds;
+	int		*srids;
     int ret;
 
     if (-1 == context->mysql_current_connect)
@@ -70,22 +71,29 @@
                             if (index >= curs->bind_count)
                             {
                                 binds = (MYSQL_BIND *)malloc ((index + 1) * sizeof (MYSQL_BIND));
-                                if ((MYSQL_BIND*)NULL == binds)
+								srids = (int*)malloc((index + 1) * sizeof(int));
+                                if ((MYSQL_BIND*)NULL == binds || (int*)NULL == srids)
                                 {
                                     if ((MYSQL_BIND*)NULL != curs->binds)
                                         free (curs->binds);
+									if ((int*)NULL != curs->srids)
+										free (curs->srids);
                                     curs->bind_count = 0;
                                 }
                                 else
                                 {
                                     memset (binds, 0, (index + 1) * sizeof (MYSQL_BIND));
+									memset (srids, 0, (index + 1) * sizeof (int));
                                     if ((MYSQL_BIND*)NULL != curs->binds)
                                     {
                                         memcpy (binds, curs->binds, curs->bind_count * sizeof (MYSQL_BIND));
-                                        free (curs->binds);
+										free (curs->binds);
+										memcpy (srids, curs->srids, curs->bind_count * sizeof (int));
+										free (curs->srids);
                                     }
                                     curs->bind_count = index + 1;
                                     curs->binds = binds;
+									curs->srids = srids;
                                 }
                             }
                             if (index >= curs->bind_count)

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/execute.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/execute.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/execute.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -134,7 +134,7 @@
                     cursor->rebinds[i].original = cursor->binds[i].buffer;
 
                 // get bound geometry value set by caller 
-				buffer = WkbFromGeometry (*((void**)(cursor->rebinds[i].original)), &size);
+				buffer = WkbFromGeometry (*((void**)(cursor->rebinds[i].original)), &size, cursor->srids[i]);
 
                 // Set up substitute bind buffer, containing geometry in WKB blob form.
                 if (NULL != cursor->rebinds[i].substitution)

Added: trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2004-2006  Autodesk, 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 "local.h"
+
+int mysql_geom_srid_set ( 
+	mysql_context_def	*context,
+    char   *cursor,                     /* cursor associated with SQL stmnt */
+	char	*geom_col_name,
+    long srid ) 
+{
+    mysql_cursor_def    *curs;
+	int index;
+    int                 rc = RDBI_SUCCESS;
+
+	if (context->mysql_current_connect == -1)
+        rc = RDBI_NOT_CONNECTED;
+    else
+    {
+        curs = (mysql_cursor_def*)cursor;
+        if (curs != (mysql_cursor_def*)NULL)
+		{
+			index = atoi (geom_col_name); /* numeric position */
+            /* need an error if columns have not been bound yet */
+            if (index <= 0 || curs->bind_count < index)
+                rc = RDBI_GENERIC_ERROR; /* need an error for unknown name */
+            else
+            {
+                index--; /* make it zero based */
+				if (curs->srids != (int*)NULL)
+					curs->srids[index] = (int)srid;
+			}
+		}
+	}
+    
+    return rc;
+}
\ No newline at end of file

Added: trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/geom_srid.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2004-2006  Autodesk, 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 GEOM_SRID_H
+#define GEOM_SRID_H
+
+#ifdef _WIN32
+#pragma once
+#endif // _WIN32
+
+#include "local.h"
+
+int mysql_geom_srid_set ( 
+	mysql_context_def	*context,
+    char   *cursor,                     /* cursor associated with SQL stmnt */
+	char	*geom_col_name,
+    long srid ) ;
+
+#endif // GEOM_SRID_H
\ No newline at end of file

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/local.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/local.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/local.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -56,6 +56,7 @@
     MYSQL_BIND *binds;
     mysql_define_def *redefines; /* array of size define_count, NULL entries for non-geometries */
     mysql_define_def *rebinds; /* array of size bind_count, NULL entries for non-geometries */
+	int	  *srids; /* array of SRIDs, 0 if not explicitly set and for non-geometries */
 } mysql_cursor_def;
 
 #endif // LOCAL_H

Modified: trunk/Providers/GenericRdbms/Src/MySQL/Driver/rdbi_init.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/Driver/rdbi_init.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/Driver/rdbi_init.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -39,6 +39,7 @@
 #include "run_sql.h"
 #include "get_gen_id.h"
 #include "null.h"
+#include "geom_srid.h"
 
 int mysql_rdbi_init (void **contextp, rdbi_methods methods)
 {
@@ -102,7 +103,7 @@
             methods->set_schema = (int (*)(void*, const char*))mysql_set_schema;
             methods->set_schemaW = NULL;
             methods->vndr_info  = (int (*)(void*, rdbi_vndr_info_def*))mysql_vndr_info;
-            methods->geom_srid_set = NULL;
+            methods->geom_srid_set = (int  (*)(void*,char*,char*, long))mysql_geom_srid_set;
             methods->geom_dimens_set = NULL;
             methods->get_geoms_ext = NULL;
             methods->lob_create_ref = NULL;

Modified: trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/MySqlSchemaMgr.vcproj
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/MySqlSchemaMgr.vcproj	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/MySqlSchemaMgr.vcproj	2007-01-22 22:00:15 UTC (rev 668)
@@ -456,6 +456,10 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Ph\ColumnGeom.cpp"
+					>
+				</File>
+				<File
 					RelativePath="Ph\ColumnGeom.h"
 					>
 				</File>

Added: trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2004-2006  Autodesk, 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 "Mgr.h"
+#include "ColumnGeom.h"
+
+FdoInt64 FdoSmPhMySqlColumnGeom::GetSRID()
+{
+	if (mSRID == -1)
+	{
+		FdoSmPhDbObjectP dbObject = this->GetContainingDbObject();
+		FdoStringP sqlStmt = FdoStringP::Format(
+			L"select SRID(%ls) as srid from %ls", (FdoString*)this->GetDbName(), (FdoString*)dbObject->GetDbName());
+		FdoSmPhMySqlMgrP mgr = this->GetManager()->SmartCast<FdoSmPhMySqlMgr>();
+		GdbiConnection* gdbiConn = mgr->GetGdbiConnection();
+		GdbiQueryResult *gdbiResult = gdbiConn->ExecuteQuery((const char*)sqlStmt);
+		// SRID is 0 if table is empty or geometry column has not been populated yet
+		mSRID = 0;
+		if (gdbiResult->ReadNext())
+		{
+			if (!gdbiResult->GetIsNull(L"srid"))
+				mSRID = gdbiResult->GetInt64(L"srid", NULL, NULL);
+		}
+		gdbiResult->End();
+	}
+	return mSRID;
+}

Modified: trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/ColumnGeom.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -20,6 +20,8 @@
 
 #include <Inc/rdbi.h>
 #include <Sm/Ph/ColumnGeom.h>
+#include "Rd/ColumnReader.h"
+#include "Column.h"
 
 // Represents a MySql geometric type column.
 class FdoSmPhMySqlColumnGeom :
@@ -43,6 +45,7 @@
     {
         m_FdoGeomType = FdoGeometricType_Point | FdoGeometricType_Curve | FdoGeometricType_Surface;
         m_FdoGeometryType = FdoCommonGeometryUtil::GetAllGeometryTypesCode();
+		mSRID = -1;
         if (NULL != reader)
         {
             try
@@ -75,10 +78,12 @@
     {
         return FdoStringP::Format(L"%d", m_FdoGeometryType);
     }
+	virtual FdoInt64 GetSRID();
 
 protected:
     long m_FdoGeomType;
     long m_FdoGeometryType;
+	FdoInt64 mSRID;
 
     virtual void PostFinalize()
     {

Modified: trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/Makefile.am
===================================================================
--- trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/Makefile.am	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/MySQL/SchemaMgr/Ph/Makefile.am	2007-01-22 22:00:15 UTC (rev 668)
@@ -28,6 +28,7 @@
   Collation.cpp \
   ColTypeMapper.cpp \
   ColumnChar.cpp \
+  ColumnGeom.cpp	\
   Column.cpp \
   ColumnDecimal.cpp \
   Database.cpp \

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/geom.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/geom.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/geom.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -163,6 +163,7 @@
 int odbcdr_geom_srid_set ( 
 	odbcdr_context_def	*context,
     char   *cursor,                     /* cursor associated with SQL stmnt */
+	char	*col_name,
     long srid ) 
 {
     odbcdr_cursor_def    *c;

Modified: trunk/Providers/GenericRdbms/Src/Rdbi/geom_srid.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/Rdbi/geom_srid.c	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/Rdbi/geom_srid.c	2007-01-22 22:00:15 UTC (rev 668)
@@ -41,7 +41,7 @@
 #include <Inc/Rdbi/cursor.h>   
 #include	<Inc/Rdbi/context.h>
 
-int rdbi_geom_srid_set ( rdbi_context_def *context, int sqlid, long srid ) 
+int rdbi_geom_srid_set ( rdbi_context_def *context, int sqlid, char *col_name, long srid ) 
 {
     rdbi_cursor_def *cursor;        /* for convenience          */
     int     rc = FALSE;
@@ -50,7 +50,7 @@
 
     cursor = context->rdbi_cursor_ptrs[sqlid];
      
-    rc = (*(context->dispatch.geom_srid_set))( context->drvr, cursor->vendor_data, srid );
+    rc = (*(context->dispatch.geom_srid_set))( context->drvr, cursor->vendor_data, col_name, srid );
 
     debug_return(NULL, rc );
 }

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.cpp	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.cpp	2007-01-22 22:00:15 UTC (rev 668)
@@ -57,6 +57,17 @@
 		L"create table device_tbl (id decimal(20), string varchar(64), install_date datetime, int32 integer(5), constraint device_tbl_pk primary key (id, string, install_date))");
 	UnitTestUtil::Sql2Db(sqlStmt, connection);
 
+	sqlStmt = FdoStringP::Format(
+		L"create table point (entityid bigint not null auto_increment, geometry1 point, geometry2 point, pname varchar(64), geometry3 point, constraint point_pk primary key (entityid))");
+	UnitTestUtil::Sql2Db(sqlStmt, connection);
+	// insert one row with non 0 SRIDS
+	sqlStmt = FdoStringP::Format(
+		L"insert into point( pname, geometry1, geometry2, geometry3) values \n"
+		L"('Toronto', GeomFromText('POINT(20 30)', 101),\n"
+		L"GeomFromText('POINT(120 130)', 102),\n"
+		L"GeomFromText('POINT(220 230)', 103))");
+	UnitTestUtil::Sql2Db(sqlStmt, connection);
+
 	connection->Close();
 }
 void MySqlFdoForeignSchemaTest::insert()
@@ -126,3 +137,188 @@
 	}
 }
 
+void MySqlFdoForeignSchemaTest::insertSRID ()
+{
+    try
+    {
+        FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(DB_NAME_SUFFIX, false);
+
+        try
+        {
+
+            FdoPtr<FdoPropertyValue> propertyValue;
+
+            FdoPtr<FdoIInsert> insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert);
+            insertCommand->SetFeatureClassName(L"point");
+            FdoPtr<FdoPropertyValueCollection> propertyValues = insertCommand->GetPropertyValues();
+			FdoPtr<FdoDataValue> dataValue;
+			dataValue = FdoDataValue::Create(L"Ottawa");
+            propertyValue = AddNewProperty( propertyValues, L"pname");
+            propertyValue->SetValue(dataValue);
+
+            FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
+			FdoPtr<FdoIDirectPosition> pos = gf->CreatePositionXY(50, 60);
+
+			// first geometry column
+            propertyValue = FdoPropertyValue::Create();
+			propertyValue->SetName(L"geometry1");
+			propertyValues->Add( propertyValue );
+		
+            FdoPtr<FdoIPoint> point1 = gf->CreatePoint(pos);
+            FdoPtr<FdoByteArray> byteArray = gf->GetFgf(point1);
+
+            FdoPtr<FdoGeometryValue> geometryValue = FdoGeometryValue::Create(byteArray);
+            propertyValue->SetValue(geometryValue);
+			
+			// second geometry column
+			pos = gf->CreatePositionXY(20, 90);
+			propertyValue = FdoPropertyValue::Create();
+			propertyValue->SetName(L"geometry2");
+			propertyValues->Add( propertyValue );
+		
+            point1 = gf->CreatePoint(pos);
+            byteArray = gf->GetFgf(point1);
+
+            geometryValue = FdoGeometryValue::Create(byteArray);
+            propertyValue->SetValue(geometryValue);
+
+			// third geometry column
+			pos = gf->CreatePositionXY(20, 70);
+			propertyValue = FdoPropertyValue::Create();
+			propertyValue->SetName(L"geometry3");
+			propertyValues->Add( propertyValue );
+		
+            point1 = gf->CreatePoint(pos);
+            byteArray = gf->GetFgf(point1);
+
+            geometryValue = FdoGeometryValue::Create(byteArray);
+            propertyValue->SetValue(geometryValue);
+
+			FdoPtr<FdoIFeatureReader> featureReader = insertCommand->Execute();
+			CPPUNIT_ASSERT(featureReader != NULL);
+			if (featureReader->ReadNext())
+				CPPUNIT_ASSERT(!featureReader->IsNull(L"entityid"));
+			FdoInt64 id = featureReader->GetInt64(L"entityid");;
+			featureReader->Close();
+			// verify SRIDs
+			FdoPtr<FdoISQLCommand> selCmd = (FdoISQLCommand*)connection->CreateCommand( FdoCommandType_SQLCommand );
+            FdoStringP sql = FdoStringP::Format(L"select srid(geometry1) as srid1, srid(geometry2) as srid2, srid(geometry3) as srid3 from point where entityid = %ld", id);
+
+            selCmd->SetSQLStatement( (FdoString *)sql );
+            FdoPtr<FdoISQLDataReader> myReader = selCmd->ExecuteReader();
+            if( myReader != NULL  )
+            {
+				//valid values for SRID are
+				// srid1 = 101
+				// srid2 = 102
+				// srid3 = 103
+				if (myReader->ReadNext())
+				{
+					if (!myReader->IsNull(L"srid1"))
+					{
+						CPPUNIT_ASSERT(myReader->GetInt64(L"srid1") == 101);
+						CPPUNIT_ASSERT(myReader->GetInt64(L"srid2") == 102);
+						CPPUNIT_ASSERT(myReader->GetInt64(L"srid3") == 103);
+					}
+				}
+			}
+                
+			myReader->Close();
+			connection->Close();
+        }
+        catch (...)
+        {
+            if (connection)
+                connection->Close ();
+            throw;
+        }
+        if (connection)
+            connection->Close();
+    }
+    catch (FdoCommandException *ex)
+    {
+        UnitTestUtil::FailOnException(ex);
+    }
+    catch (FdoException *ex)
+    {
+        UnitTestUtil::FailOnException(ex);
+    }
+}
+void MySqlFdoForeignSchemaTest::updateGeomWithSRID()
+{
+	try
+    {
+        FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(DB_NAME_SUFFIX, false);
+
+        try
+        {
+			FdoInt64 id;
+            FdoPtr<FdoPropertyValue> propertyValue;
+
+			// find entityid of the row to update
+			FdoPtr<FdoISQLCommand> selCmd = (FdoISQLCommand*)connection->CreateCommand( FdoCommandType_SQLCommand );
+            FdoStringP sql = FdoStringP::Format(L"select entityid as id from point");
+
+            selCmd->SetSQLStatement( (FdoString *)sql );
+            FdoPtr<FdoISQLDataReader> myReader = selCmd->ExecuteReader();
+			CPPUNIT_ASSERT(myReader != NULL);
+			if (myReader->ReadNext())
+				id = myReader->GetInt64(L"id");
+			myReader->Close();
+
+			FdoPtr<FdoIUpdate> updCmd = (FdoIUpdate *) connection->CreateCommand(FdoCommandType_Update);
+            updCmd->SetFeatureClassName(L"point");
+			FdoPtr<FdoFilter>   filter = FdoComparisonCondition::Create(
+                FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"entityid") ),
+                FdoComparisonOperations_EqualTo,
+                FdoPtr<FdoDataValue>(FdoDataValue::Create(id) ) );
+			updCmd->SetFilter( filter );
+            FdoPtr<FdoPropertyValueCollection> propertyValues = updCmd->GetPropertyValues();
+			
+            FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
+			FdoPtr<FdoIDirectPosition> pos = gf->CreatePositionXY(150, 160);
+
+			// first geometry column
+            propertyValue = FdoPropertyValue::Create();
+			propertyValue->SetName(L"geometry1");
+			propertyValues->Add( propertyValue );
+
+			FdoPtr<FdoIPoint> point1 = gf->CreatePoint(pos);
+            FdoPtr<FdoByteArray> byteArray = gf->GetFgf(point1);
+
+            FdoPtr<FdoGeometryValue> geometryValue = FdoGeometryValue::Create(byteArray);
+            propertyValue->SetValue(geometryValue);
+
+			int numRows = updCmd->Execute();
+			// check srid, it should be 101
+			sql = FdoStringP::Format(L"select srid(geometry1) as srid1 from point where entityid = %ld", id);
+
+            selCmd->SetSQLStatement( (FdoString *)sql );
+            myReader = selCmd->ExecuteReader();
+			CPPUNIT_ASSERT(myReader != NULL);
+			if (myReader->ReadNext())
+			{
+				if (!myReader->IsNull(L"srid1"))
+					CPPUNIT_ASSERT(myReader->GetInt64(L"srid1") == 101);
+			}
+			myReader->Close();
+			connection->Close();
+		}
+		catch (...)
+        {
+            if (connection)
+                connection->Close ();
+            throw;
+        }
+        if (connection)
+            connection->Close();
+    }
+    catch (FdoCommandException *ex)
+    {
+        UnitTestUtil::FailOnException(ex);
+    }
+    catch (FdoException *ex)
+    {
+        UnitTestUtil::FailOnException(ex);
+	}
+}
\ No newline at end of file

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.h	2007-01-22 21:11:17 UTC (rev 667)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/MySql/MySqlFdoForeignSchemaTest.h	2007-01-22 22:00:15 UTC (rev 668)
@@ -24,11 +24,15 @@
 class MySqlFdoForeignSchemaTest : public FdoForeignSchemaTest
 {
     CPPUNIT_TEST_SUB_SUITE (MySqlFdoForeignSchemaTest, FdoForeignSchemaTest);
+	CPPUNIT_TEST( insertSRID );
+	CPPUNIT_TEST( updateGeomWithSRID );
     CPPUNIT_TEST_SUITE_END ();
 
     void  set_provider();
 	void  create_foreign_datastore();
 	void  insert();
+	void insertSRID();
+	void updateGeomWithSRID();
 };
 
 #endif // MYSQL_FDOFOREIGNSCHEMATEST_H



More information about the fdo-commits mailing list