[fdo-commits] r640 - branches/3.2.x/Providers/GenericRdbms/Src/MySQL/Driver

svn_fdo at osgeo.org svn_fdo at osgeo.org
Wed Jan 17 11:13:14 EST 2007


Author: danstoica
Date: 2007-01-17 11:13:14 -0500 (Wed, 17 Jan 2007)
New Revision: 640

Modified:
   branches/3.2.x/Providers/GenericRdbms/Src/MySQL/Driver/fetch.c
Log:
MySql - TEXT columns are not correctly retrieved

Modified: branches/3.2.x/Providers/GenericRdbms/Src/MySQL/Driver/fetch.c
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/MySQL/Driver/fetch.c	2007-01-16 20:35:36 UTC (rev 639)
+++ branches/3.2.x/Providers/GenericRdbms/Src/MySQL/Driver/fetch.c	2007-01-17 16:13:14 UTC (rev 640)
@@ -80,16 +80,28 @@
 				*rows_processed = 0;
                 result = mysql_stmt_fetch (curs->statement);
                 ret = mysql_xlt_status(context, result, mysql, (MYSQL_STMT*) NULL);
-				if (ret == RDBI_DATA_TRUNCATED)
+
+				// Post-process BLOB columns
+				for (int i=0; i<curs->define_count; i++)
 				{
-					for (int i=0; i<curs->define_count; i++)
+					if (curs->defines[i].buffer_type != MYSQL_TYPE_BLOB)
+						continue;
+
+					// avoid datatruncation error on BLOBs
+					if (ret == RDBI_DATA_TRUNCATED && curs->defines[i].error)
+						ret = RDBI_SUCCESS;
+					else
 					{
-						if (curs->defines[i].error && (curs->defines[i].buffer_type == MYSQL_TYPE_BLOB))
-						// ignore data truncation error on BLOBs
-							ret = RDBI_SUCCESS;
+						// MySql doesn't clean up the internal buffer which is copied into the user's buffer.
+						// Therefore consider the returned length of the BLOB. By inserting a null terminator 
+						// helps the caller to handle the TEXT columns.
+						unsigned long	*size = curs->defines[i].length;
+						char			*address = (char *)curs->defines[i].buffer;
+						address[*size] = '\0';
 					}
 				}
-                if (ret == RDBI_SUCCESS)
+
+				if (ret == RDBI_SUCCESS)
                 {
 					// mysql_stmt_affected_rows returns inconsistent values for select
                     //rows  = mysql_stmt_affected_rows (curs->statement);



More information about the fdo-commits mailing list