[fdo-commits] r699 - in trunk/Providers/GenericRdbms/Src: Gdbi ODBCDriver

svn_fdo at osgeo.org svn_fdo at osgeo.org
Mon Jan 29 13:47:41 EST 2007


Author: danstoica
Date: 2007-01-29 13:47:41 -0500 (Mon, 29 Jan 2007)
New Revision: 699

Modified:
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.h
   trunk/Providers/GenericRdbms/Src/ODBCDriver/bind.c
   trunk/Providers/GenericRdbms/Src/ODBCDriver/constants.h
   trunk/Providers/GenericRdbms/Src/ODBCDriver/define.c
   trunk/Providers/GenericRdbms/Src/ODBCDriver/desc_slct.c
   trunk/Providers/GenericRdbms/Src/ODBCDriver/execute.c
   trunk/Providers/GenericRdbms/Src/ODBCDriver/fetch.c
   trunk/Providers/GenericRdbms/Src/ODBCDriver/vndr_info.c
Log:
Merge branch 3.2.x to Trunk

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp	2007-01-29 18:47:41 UTC (rev 699)
@@ -25,6 +25,9 @@
 #endif
 #include "FdoCommonOSUtil.h"
 #include "GdbiQueryIdentifier.h"
+#ifdef HAVE_GEOM_INFO_TYPE
+#include <inc/geometry/fgf/AllGeometry_c.h>
+#endif
 
 // Arbitrary size which should be more than enough for the 
 // the ASCII or UNICODE representation of any numeric value.
@@ -66,6 +69,7 @@
 {
 	m_QueryId = new GdbiQueryIdentifier(command, qid);
 	define_exec();
+	m_missed=0;
 }
 GdbiQueryResult::GdbiQueryResult(GdbiCommands* command, GdbiQueryIdentifier *queryObj):
 m_pGdbiCommands( command ),
@@ -79,29 +83,45 @@
 {
 	m_QueryId = FDO_SAFE_ADDREF(queryObj);
 	define_exec();
+	m_missed=0;
 }
 
 
 void GdbiQueryResult::define_exec()
 {
-    GdbiColumnInfoType*      colInfo = new GdbiColumnInfoType;
     char        buffer[16];
-    int name_length = GDBI_COLUMN_SIZE;
-    wchar_t colName[GDBI_COLUMN_SIZE];
-    mColMap = new std::map<std::wstring,GdbiColumnInfoType*>();
+    int			name_length = GDBI_COLUMN_SIZE;
+    wchar_t		colName[GDBI_COLUMN_SIZE];
+    int			colType;
+    int			colSize;
+	int			colNullAllowed;
+
+
+	mColList = new std::vector<GdbiColumnInfoType*>();
+
     int  idx = 1;
 	bool status = false;
 
-    while( m_pGdbiCommands->desc_slct( m_QueryId->GetQueryId(), idx++, name_length, colName, &colInfo->type, &colInfo->size, &colInfo->null_allowed) == RDBI_SUCCESS )
+    while( m_pGdbiCommands->desc_slct( m_QueryId->GetQueryId(), idx++, name_length, colName, &colType, &colSize, &colNullAllowed) == RDBI_SUCCESS )
     {
 
         FdoStringP  upperName = FdoStringP(colName).Upper();
         const wchar_t* name = (const wchar_t*)upperName;
-        if (mColMap->find (name) != mColMap->end())
-            continue; // TODO: throw new GdbiException(FdoCommonNlsUtil::NLSGetMessage( FDORDBMS_495, "Duplicate columns of name '%1$ls' found in query result.", fdordbms_cat, name));
-        mColMap->insert( std::pair<std::wstring,GdbiColumnInfoType*> ( name, colInfo ) );
+
+		GdbiColumnInfoType*      colInfo = new GdbiColumnInfoType;
+		
+        mColList->push_back( colInfo );
+		
+		// Copy info
+		colInfo->name = new wchar_t[wcslen(name) + 1];
+		wcscpy(colInfo->name, name );
+
+		colInfo->type = colType;
+		colInfo->size = colSize;
+		colInfo->null_allowed = colNullAllowed;
+
         colInfo->original_type = colInfo->type;
-        colInfo->index = idx-1;
+        colInfo->index = idx - 1;
 
 		m_pGdbiCommands->alcnullind(m_pGdbiCommands->get_array_size(), &(colInfo->isNull));
 
@@ -110,7 +130,7 @@
 			colInfo->type = RDBI_STRING;
 		else
 		{
-			if (colInfo->type == RDBI_FIXED_CHAR || colInfo->type == RDBI_STRING)
+			if (colInfo->type == RDBI_FIXED_CHAR || colInfo->type == RDBI_STRING || colInfo->type == RDBI_WSTRING)
 				// allocate space for null indicator
 				colInfo->size++;
 		}
@@ -151,11 +171,8 @@
 
 			m_pGdbiCommands->define( m_QueryId->GetQueryId(), FdoCommonOSUtil::itoa(colInfo->index, buffer), colInfo->type, colInfo->size, (colInfo->type == RDBI_BLOB_REF) ? (char *)&(colInfo->value) : (char*)colInfo->value, colInfo->isNull );
 		
-		}
-        
-        colInfo = new GdbiColumnInfoType;
+		}   
     }
-    delete colInfo;
 
     m_pGdbiCommands->execute( m_QueryId->GetQueryId(), 0, 0 );
 }
@@ -167,11 +184,12 @@
         m_pGdbiCommands->end_select( m_QueryId->GetQueryId());
     }
 
-    if( mColMap )
+    if( mColList )
     {
-        for (std::map <std::wstring,GdbiColumnInfoType*>::iterator i = mColMap->begin(); i != mColMap->end(); ++i )
+        for (size_t i = 0; i < mColList->size(); i++ )
         {
-            GdbiColumnInfoType *colInfo = i->second;
+            GdbiColumnInfoType *colInfo = mColList->at(i);
+
 			if( colInfo->value && colInfo->type == RDBI_BLOB_REF )
 			{
 				if (m_QueryId)
@@ -189,9 +207,13 @@
 
 			if( colInfo->isNull )
 				free( (void*)colInfo->isNull );
+
+			if ( colInfo->name )
+				delete [] colInfo->name;
+
             delete colInfo;
         }
-        delete mColMap;
+        delete mColList;
     }
 	FDO_SAFE_RELEASE(m_QueryId);
 
@@ -248,25 +270,22 @@
 
 int GdbiQueryResult::GetColumnCount( )
 {
-    if( mColMap )
-        return (int)mColMap->size();
+    if( mColList )
+        return (int)mColList->size();
 
     return 0;
 }
 
 int GdbiQueryResult::GetColumnDesc( int colIdx, GdbiColumnDesc &desc )
 {
-    int idx = colIdx;
-    std::map <std::wstring,GdbiColumnInfoType*>::iterator iter = mColMap->begin();
-    for( iter = mColMap->begin(); iter != mColMap->end(); iter++ )
-        if( idx == iter->second->index )
-            break;
+    int idx = colIdx; // 1 based
 
-    if( iter == mColMap->end() )  // error
-        return false;
+	if ( colIdx > (int)mColList->size() ) // error
+		return false; 
 
-    GdbiColumnInfoType *colInfo = iter->second;
-    strncpy( desc.column, (const char*)FdoStringP(iter->first.c_str(),true), sizeof(desc.column) - 1);
+	GdbiColumnInfoType *colInfo = mColList->at(idx-1);
+
+	strncpy( desc.column, (const char*)FdoStringP(colInfo->name), sizeof(desc.column) - 1);
     desc.column[sizeof(desc.column)-1]=0;
     desc.datatype = colInfo->original_type;
 	desc.size = (colInfo->type == RDBI_CHAR || colInfo->type == RDBI_FIXED_CHAR || colInfo->type == RDBI_STRING) ? colInfo->size-1 : colInfo->size;
@@ -277,122 +296,104 @@
 
 int GdbiQueryResult::GetBinaryValue( const wchar_t *colName, int length, char *address, bool *null_ind, int *ccode )
 {
-    std::map <std::wstring,GdbiColumnInfoType*>::iterator iter;
-	bool isNull;
-    FdoStringP  upperName = FdoStringP(colName).Upper();
-    const wchar_t* name = (const wchar_t*)upperName;
-    iter = mColMap->find( StripTable(name) );
-    if( iter != mColMap->end() )
-    {
-        GdbiColumnInfoType *colInfo = iter->second;
-		isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
-		if (isNull == false)
+	GdbiColumnInfoType *colInfo = FindColumnCache(colName);
+
+	bool isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
+
+	if (isNull == false)
+	{
+		if (colInfo->type == RDBI_CHAR || colInfo->type == RDBI_BOOLEAN)
 		{
-			if (colInfo->type == RDBI_CHAR || colInfo->type == RDBI_BOOLEAN)
-			{
-				memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, 1);
-				if (length != 1)
-					address[1] = '\0';
-			}
-			else
-			{
-				int  size = ( length > colInfo->size )? colInfo->size : length;
-				memcpy(address, ((char*)colInfo->value) + mArrayPos*colInfo->size, size );
-			}
+			memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, 1);
+			if (length != 1)
+				address[1] = '\0';
 		}
-        if( null_ind )
-            *null_ind = isNull;
+		else
+		{
+			int  size = ( length > colInfo->size )? colInfo->size : length;
+			memcpy(address, ((char*)colInfo->value) + mArrayPos*colInfo->size, size );
+		}
+	}
+    if( null_ind )
+        *null_ind = isNull;
 
-        if( ccode )
-            *ccode = RDBI_SUCCESS;
+    if( ccode )
+        *ccode = RDBI_SUCCESS;
 
-        return RDBI_SUCCESS;
-    }
+    return RDBI_SUCCESS;
+ }
 
-    throw new GdbiException(L"Column X not selected");
-}
-
-int GdbiQueryResult::GetAsciiValue( const wchar_t *colName, int length, char *address, bool *null_ind, int *ccode )
+int GdbiQueryResult::GetAsciiValue( GdbiColumnInfoType *colInfo, int length, char *address, bool *null_ind, int *ccode )
 {
-    std::map <std::wstring,GdbiColumnInfoType*>::iterator iter;
     char    tmpDblBuffer[60];
 	char	lascii[200];
 	int		lccode = RDBI_SUCCESS;
-    FdoStringP  upperName = FdoStringP(colName).Upper();
-    const wchar_t* name = (const wchar_t*)upperName;
-    iter = mColMap->find( StripTable(name) );
-	bool isNull;
-    if( iter != mColMap->end() )
-    {
-        GdbiColumnInfoType *colInfo = iter->second;
-		isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
-		if (isNull == false)
+
+	bool isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
+	if (isNull == false)
+	{
+		int  size = ( length > colInfo->size )? colInfo->size : length;
+
+		switch (colInfo->type)
 		{
-			int  size = ( length > colInfo->size )? colInfo->size : length;
-
-			switch (colInfo->type)
-			{
-			case RDBI_SHORT:
-				sprintf(lascii, "%d", (*(short *)((char*)colInfo->value + mArrayPos*colInfo->size)));
-				do_copy(lascii, address, length, &lccode); 
-				break;
-			case RDBI_INT:
-			case RDBI_LONG:
-				sprintf(lascii, "%ld", (*(long *)((char*)colInfo->value + mArrayPos*colInfo->size)));
-				do_copy(lascii, address, length, &lccode); 
-				break;
-			case RDBI_LONGLONG:
+		case RDBI_SHORT:
+			sprintf(lascii, "%d", (*(short *)((char*)colInfo->value + mArrayPos*colInfo->size)));
+			do_copy(lascii, address, length, &lccode); 
+			break;
+		case RDBI_INT:
+		case RDBI_LONG:
+			sprintf(lascii, "%ld", (*(long *)((char*)colInfo->value + mArrayPos*colInfo->size)));
+			do_copy(lascii, address, length, &lccode); 
+			break;
+		case RDBI_LONGLONG:
 #ifdef _WIN32
-				sprintf(lascii, "%I64d", (*(FdoInt64 *)((char*)colInfo->value + mArrayPos*colInfo->size)));
+			sprintf(lascii, "%I64d", (*(FdoInt64 *)((char*)colInfo->value + mArrayPos*colInfo->size)));
 #else
-				sprintf(lascii, "%lld", (*(FdoInt64 *)((char*)colInfo->value + mArrayPos*colInfo->size)));
+			sprintf(lascii, "%lld", (*(FdoInt64 *)((char*)colInfo->value + mArrayPos*colInfo->size)));
 #endif
-				do_copy(lascii, address, length, &lccode); 
-				break;
-			case RDBI_FLOAT:
-				sprintf(lascii, "%s", ut_dtoa( (double) (*(float *)((char*)colInfo->value + mArrayPos*colInfo->size)), tmpDblBuffer) );
-				do_copy(lascii, address, length, &lccode);
-				break;
-			case RDBI_DOUBLE:
-				sprintf(lascii, "%s", ut_dtoa( (*(double *)((char*)colInfo->value + mArrayPos*colInfo->size)), tmpDblBuffer ) );
-				do_copy(lascii, address, length, &lccode);
-				break;
-			default:
-				if (colInfo->type == RDBI_CHAR)
-				{
-					// Oracle and MySQL do not put null indicators
-					memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, colInfo->size);
-					if (length != 1)
-						address[1] = '\0';
-				}
-				else
-					memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, size); 
-				
-                if (size < colInfo->size)
-                {
-                    address[size-1] = '\0';
-                    lccode = RDBI_DATA_TRUNCATED;
-                }
-				break;
+			do_copy(lascii, address, length, &lccode); 
+			break;
+		case RDBI_FLOAT:
+			sprintf(lascii, "%s", ut_dtoa( (double) (*(float *)((char*)colInfo->value + mArrayPos*colInfo->size)), tmpDblBuffer) );
+			do_copy(lascii, address, length, &lccode);
+			break;
+		case RDBI_DOUBLE:
+			sprintf(lascii, "%s", ut_dtoa( (*(double *)((char*)colInfo->value + mArrayPos*colInfo->size)), tmpDblBuffer ) );
+			do_copy(lascii, address, length, &lccode);
+			break;
+		default:
+			if (colInfo->type == RDBI_CHAR)
+			{
+				// Oracle and MySQL do not put null indicators
+				memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, colInfo->size);
+				if (length != 1)
+					address[1] = '\0';
 			}
+			else
+				memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, size); 
+			
+            if (size < colInfo->size)
+            {
+                address[size-1] = '\0';
+                lccode = RDBI_DATA_TRUNCATED;
+            }
+			break;
 		}
-        if( null_ind )
-            *null_ind = isNull;
+	}
+    if( null_ind )
+        *null_ind = isNull;
 
-        if( ccode )
-            *ccode = lccode;
+    if( ccode )
+        *ccode = lccode;
 
-        return RDBI_SUCCESS;
-    }
+    return RDBI_SUCCESS;
+ }
 
-    throw new GdbiException(L"Column X not selected");
-}
-
 template<typename T> T GdbiQueryResult::GetNumber(
-        const wchar_t *colName,
-        bool *null_ind,
+		const wchar_t *colName,
+		bool *null_ind,
         int *ccode
-        )
+	)
 {
 	T val = 0;
 	short  shortVal;
@@ -402,83 +403,75 @@
 	double doubleVal;
 	FdoInt64  int64Val;
 
-	std::map <std::wstring,GdbiColumnInfoType*>::iterator iter;
-    FdoStringP  upperName = FdoStringP(colName).Upper();
-    const wchar_t* name = (const wchar_t*)upperName;
-    iter = mColMap->find( StripTable(name) );
-	bool isNull;
-    if( iter != mColMap->end() )
-    {
-        GdbiColumnInfoType *colInfo = iter->second;
-		isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
-		
-		if( null_ind )
-            *null_ind = isNull;
+	GdbiColumnInfoType *colInfo = FindColumnCache(colName);
 
- 		if( ccode )
-			*ccode = RDBI_SUCCESS;
+	bool isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
+	
+	if( null_ind )
+        *null_ind = isNull;
 
-		if (isNull == false)
+	if( ccode )
+		*ccode = RDBI_SUCCESS;
+
+	if (isNull == false)
+	{
+		switch (colInfo->type)
 		{
-			switch (colInfo->type)
-			{
-				case RDBI_SHORT:
-					memcpy(&shortVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(short) );
-					val = (T)shortVal;
-					break;
+			case RDBI_SHORT:
+				memcpy(&shortVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(short) );
+				val = (T)shortVal;
+				break;
 
-				case RDBI_INT:
-					memcpy(&intVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(int) );
-					val = (T)intVal;
-					break;
+			case RDBI_INT:
+				memcpy(&intVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(int) );
+				val = (T)intVal;
+				break;
 
-				case RDBI_LONG:
-					memcpy(&longVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(long) );
-					val = (T)longVal;
-					break;
+			case RDBI_LONG:
+				memcpy(&longVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(long) );
+				val = (T)longVal;
+				break;
 
-				case RDBI_LONGLONG:
-					memcpy(&int64Val, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(FdoInt64) );
-					val = (T)int64Val;
-					break;
+			case RDBI_LONGLONG:
+				memcpy(&int64Val, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(FdoInt64) );
+				val = (T)int64Val;
+				break;
 
-				case RDBI_FLOAT:
-					memcpy(&floatVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(float) );
-					val = (T)floatVal;
-					break;
+			case RDBI_FLOAT:
+				memcpy(&floatVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(float) );
+				val = (T)floatVal;
+				break;
 
-				case RDBI_DOUBLE:
-					memcpy(&doubleVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(double) );
-					val = (T)doubleVal;
+			case RDBI_DOUBLE:
+				memcpy(&doubleVal, ((char*)colInfo->value) + mArrayPos*colInfo->size, sizeof(double) );
+				val = (T)doubleVal;
+				break;
+
+			case RDBI_STRING:
+				if( sizeof(T) == sizeof(FdoInt64) )
+				{
+					// Sql server workaround
+					sscanf((char*)colInfo->value+ mArrayPos*colInfo->size,"%lld", &int64Val);
+					val = (T)int64Val;
 					break;
+				}
 
-				case RDBI_STRING:
-					if( sizeof(T) == sizeof(FdoInt64) )
-					{
-						// Sql server workaround
-						sscanf((char*)colInfo->value+ mArrayPos*colInfo->size,"%lld", &int64Val);
-						val = (T)int64Val;
-						break;
-					}
-
-				case RDBI_WSTRING:
-					if( sizeof(T) == sizeof(FdoInt64) )
-					{
-						// Sql server workaround
-						swscanf((wchar_t*)colInfo->value+ mArrayPos*colInfo->size/sizeof(wchar_t),L"%lld", &int64Val);
-						val = (T)int64Val;
-						break;
-					}
-				default:
-					(void)GetBinaryValue(colName, sizeof(T), (char*)&val, null_ind, ccode );
+			case RDBI_WSTRING:
+				if( sizeof(T) == sizeof(FdoInt64) )
+				{
+					// Sql server workaround
+					swscanf((wchar_t*)colInfo->value+ mArrayPos*colInfo->size/sizeof(wchar_t),L"%lld", &int64Val);
+					val = (T)int64Val;
 					break;
+				}
+			default:
+				(void)GetBinaryValue(colInfo->name, sizeof(T), (char*)&val, null_ind, NULL );
+				break;
 
-			}
 		}
+	}
 
-        return val;
-    }
-    throw new GdbiException(L"Column X not selected");
+    return val;
 }
 
 FdoDouble GdbiQueryResult::GetDouble( const wchar_t *ColName, bool *isnull, int *ccode )
@@ -506,92 +499,72 @@
     return GetNumber<FdoInt64>(ColName, isnull, ccode);
 }
 
-FdoFloat GdbiQueryResult::GetFloat( const wchar_t *ColName, bool *isnull, int *ccode )
+FdoFloat GdbiQueryResult::GetFloat( const wchar_t *ColName, bool *isnull, int *ccode)
 {
     return GetNumber<float>(ColName, isnull, ccode);
 }
 
-
 // Return a const wchar_t that must be copied ASP
-FdoString* GdbiQueryResult::GetString( const wchar_t *colName, bool *isnull, int *ccode )
+FdoString* GdbiQueryResult::GetString( const wchar_t *colName, bool *isnull, int *ccode)
 {
-    std::map <std::wstring,GdbiColumnInfoType*>::iterator iter;
+	GdbiColumnInfoType *colInfo = FindColumnCache(colName);
 
-    FdoStringP  upperName = FdoStringP(colName).Upper();
-    const wchar_t* name = (const wchar_t*)upperName;
-    iter = mColMap->find( StripTable(name) );
-    if( iter != mColMap->end() )
+	if( isnull )
+		*isnull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
+
+    bool isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
+    if (isNull == false)
     {
-        GdbiColumnInfoType *colInfo = iter->second;
+		if( ( m_pGdbiCommands->SupportsUnicode() && colInfo->original_type == RDBI_STRING ) || 
+			colInfo->original_type == RDBI_WSTRING  )
+		{	
+			if( ccode )
+				*ccode = RDBI_SUCCESS;
+			return (const wchar_t*)(((char*)colInfo->value) + mArrayPos*colInfo->size);
+		}
 
-		if( isnull )
-			*isnull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
-
-        bool isNull = (m_pGdbiCommands->is_null(colInfo->isNull, mArrayPos) == 1);
-        if (isNull == false)
+        if ((mAsciiValBuffer != NULL) && (mAsciiValBufferSize <= colInfo->size))
         {
-			if( ( m_pGdbiCommands->SupportsUnicode() && colInfo->original_type == RDBI_STRING ) || 
-				colInfo->original_type == RDBI_WSTRING  )
-			{	
-				if( ccode )
-					*ccode = RDBI_SUCCESS;
-				return (const wchar_t*)(((char*)colInfo->value) + mArrayPos*colInfo->size);
-			}
-
-            if ((mAsciiValBuffer != NULL) && (mAsciiValBufferSize <= colInfo->size))
-            {
-                delete [] mAsciiValBuffer;
-                mAsciiValBuffer = NULL;
-            }
-            if (mAsciiValBuffer == NULL)
-            {
-                mAsciiValBufferSize = (colInfo->size < GDBI_MIN_STRING_BUFFER_SIZE) ? GDBI_MIN_STRING_BUFFER_SIZE : colInfo->size;
-                mAsciiValBuffer = new char[mAsciiValBufferSize];
-            }
-        
-            if (GetAsciiValue( name, mAsciiValBufferSize, mAsciiValBuffer, NULL, NULL) != RDBI_SUCCESS)
-                return NULL;
+            delete [] mAsciiValBuffer;
+            mAsciiValBuffer = NULL;
+        }
+        if (mAsciiValBuffer == NULL)
+        {
+            mAsciiValBufferSize = (colInfo->size < GDBI_MIN_STRING_BUFFER_SIZE) ? GDBI_MIN_STRING_BUFFER_SIZE : colInfo->size;
+            mAsciiValBuffer = new char[mAsciiValBufferSize];
+        }
     
-            if ((mUnicodeBuffer != NULL) && (mUnicodeBufferSize < mAsciiValBufferSize)) 
-            {
-                delete[] mUnicodeBuffer;
-                mUnicodeBuffer = NULL;
-            }
-            if( mUnicodeBuffer == NULL )
-            {
-                mUnicodeBufferSize = mAsciiValBufferSize;
-                mUnicodeBuffer = new wchar_t[mUnicodeBufferSize];
-            }
+        if (GetAsciiValue( colInfo, mAsciiValBufferSize, mAsciiValBuffer, NULL, NULL ) != RDBI_SUCCESS)
+            return NULL;
 
-			if( mAsciiValBuffer[0] == '\0' )
-				mUnicodeBuffer[0] = '\0';
-            else if( ! ut_utf8_to_unicode( mAsciiValBuffer, mUnicodeBuffer,  mUnicodeBufferSize ) )
-                throw GdbiException::Create(NlsMsgGet(FDORDBMS_47, "UTF8 conversion failed"));
+        if ((mUnicodeBuffer != NULL) && (mUnicodeBufferSize < mAsciiValBufferSize)) 
+        {
+            delete[] mUnicodeBuffer;
+            mUnicodeBuffer = NULL;
         }
+        if( mUnicodeBuffer == NULL )
+        {
+            mUnicodeBufferSize = mAsciiValBufferSize;
+            mUnicodeBuffer = new wchar_t[mUnicodeBufferSize];
+        }
 
-        if( ccode )
-            *ccode = RDBI_SUCCESS;
-
-        return mUnicodeBuffer;
+		if( mAsciiValBuffer[0] == '\0' )
+			mUnicodeBuffer[0] = '\0';
+        else if( ! ut_utf8_to_unicode( mAsciiValBuffer, mUnicodeBuffer,  mUnicodeBufferSize ) )
+            throw GdbiException::Create(NlsMsgGet(FDORDBMS_47, "UTF8 conversion failed"));
     }
 
-    throw new GdbiException(L"Column X not selected");
-}
+    if( ccode )
+        *ccode = RDBI_SUCCESS;
 
-FdoString* GdbiQueryResult::GetString( int index, bool *isnull, int *ccode )
+    return mUnicodeBuffer;
+ }
+
+FdoString* GdbiQueryResult::GetString(int index, bool *isnull, int *ccode)
 {
-   if( mColMap )
-    {
-        for (std::map <std::wstring,GdbiColumnInfoType*>::iterator i = mColMap->begin(); i != mColMap->end(); ++i )
-        {
-            GdbiColumnInfoType *colInfo = i->second;
-            if( colInfo->index == index )
-			{
-				return GetString( i->first.c_str() , isnull, ccode );
-			}
-        }
-    }
-   throw new GdbiException(L"Column X not selected");
+	FdoStringP	colName = FdoStringP::Format(L"%ld", index );
+
+	return GetString( (const wchar_t *)colName, isnull, ccode);
 }
 
 FdoBoolean GdbiQueryResult::GetBoolean( const wchar_t *ColName, bool *isnull, int *ccode )
@@ -605,19 +578,11 @@
 
 bool GdbiQueryResult::GetIsNull( const wchar_t *colName )
 {
-    std::map <std::wstring,GdbiColumnInfoType*>::iterator iter;
+	GdbiColumnInfoType *colInfo = FindColumnCache(colName );
 
-    FdoStringP  upperName = FdoStringP(colName).Upper();
-    const wchar_t* name = (const wchar_t*)upperName;
-    iter = mColMap->find( StripTable(name) );
-    if( iter != mColMap->end() )
-    {
-        GdbiColumnInfoType *colInfo = iter->second;
+    return ( m_pGdbiCommands->is_null( colInfo->isNull, mArrayPos ) == 1 );
+}
 
-        return ( m_pGdbiCommands->is_null( colInfo->isNull, mArrayPos ) == 1 );
-    }
-    throw new GdbiException(L"Column X not selected");
-}
 void GdbiQueryResult::do_copy(char *ascii_I, char *ascii_O, int len, int *ccode)
 {
 	int	llen = (int)strlen(ascii_I);
@@ -677,3 +642,55 @@
 {
 	return GetIsNull( (const wchar_t*) FdoStringP( ColName ) );
 }
+
+FdoByteArray * GdbiQueryResult::GetFgfFromGeomInfo( char * geomInfo )
+{
+#ifdef HAVE_GEOM_INFO_TYPE
+    FdoByteArray * byteArray = NULL;
+    (void) m_pGdbiCommands->geom_to_fgf( m_QueryId->GetQueryId(), geomInfo, (void **)(&byteArray) );
+    return byteArray;
+#else
+    return NULL;
+#endif
+}
+
+int	GdbiQueryResult::GetColumnIndex( const wchar_t *colName )
+{
+	GdbiColumnInfoType *colInfoCached = FindColumnCache( colName );
+
+	return colInfoCached->index; // 1 - based
+}
+
+GdbiColumnInfoType *GdbiQueryResult::FindColumnCache( const wchar_t *colName )
+{
+	GdbiColumnInfoType *colInfo = NULL;
+	bool				found = false;
+
+	int		colIndex = FdoCommonOSUtil::wtoi( colName );
+
+	// Number ?
+	if ( colIndex > 0 )
+	{
+		if( mColList && colIndex <= (int)mColList->size())
+		{
+			colInfo = mColList->at( colIndex - 1);
+			found = true;
+		}
+	}
+	else
+	{
+		FdoStringP  upperName = FdoStringP(colName).Upper();
+		const wchar_t* name = StripTable(upperName);
+
+		for ( size_t i = 0; !found && i < mColList->size(); i++ )
+		{
+			colInfo = mColList->at(i);
+			found = ( wcscmp( colInfo->name, name ) == 0 );
+		}
+	}
+
+	if ( !found )
+		throw FdoCommandException::Create(NlsMsgGet1(FDORDBMS_42, "Column %1$ls not found", colName));
+
+	return colInfo;
+}

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.h	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.h	2007-01-29 18:47:41 UTC (rev 699)
@@ -32,6 +32,7 @@
 #define GDBI_COLUMN_SIZE   255
 
 typedef struct _col_type_ {
+	wchar_t	*name;
     int     original_type;
     int     type;
     int     size;
@@ -51,12 +52,13 @@
 	int				  mArrayTCount; // total number of fetched rows
 	int				  mArrayCCount; // number of fetched rows in a sngle fetch;
 	int				  mArrayPos; // position within array of fetched rows
-    std::map<std::wstring,GdbiColumnInfoType*> *mColMap;
+	std::vector<GdbiColumnInfoType*> *mColList;
     wchar_t           *mUnicodeBuffer;   // Used to return wchar string that should be copied
     int               mUnicodeBufferSize;
     char              *mAsciiValBuffer;
     int               mAsciiValBufferSize;
 	GdbiQueryIdentifier	*m_QueryId;
+	int				  m_missed;
 
 private:
     GdbiQueryResult( GdbiCommands* command, int qid, bool ownsQid = true  );
@@ -66,7 +68,7 @@
 	void define_exec();
 
    int GetAsciiValue(
-        const wchar_t *ColName,
+        GdbiColumnInfoType *colInfo,
         int length,
         char *ascii,
         bool *isnull,
@@ -79,6 +81,8 @@
         int *ccode
         );
 
+	GdbiColumnInfoType *FindColumnCache(const wchar_t *colName );
+
 public:
     ~GdbiQueryResult(void);
 
@@ -90,8 +94,7 @@
             int *ccode
             );
 
- 
-
+	/// By char Name
     FdoDouble GetDouble( const char *ColName, bool *isnull, int *ccode );
 
     FdoInt32 GetInt32( const char *ColName, bool *isnull, int *ccode );
@@ -110,6 +113,7 @@
 
     bool GetIsNull( const char *ColName );
 
+	/// By wchar Name
 	FdoDouble GetDouble( const wchar_t *ColName, bool *isnull, int *ccode );
 
     FdoInt32 GetInt32( const wchar_t *ColName, bool *isnull, int *ccode );
@@ -126,10 +130,14 @@
 
     FdoBoolean GetBoolean( const wchar_t *ColName, bool *isnull, int *ccode );
 
-	FdoString* GetString( int index, bool *isnull, int *ccode );
-
     bool GetIsNull( const wchar_t *ColName );
 
+	// Gets the column index (1 based) into the cached column list.
+	// Can be used in the getters as column position instead of column name.
+	int		GetColumnIndex( const wchar_t *colName );
+
+    FdoString* GetString( int colIndex, bool *isnull, int *ccode );
+
     int ReadNext();
 
     void Close();
@@ -139,6 +147,8 @@
     int GetColumnCount( );
 
     int GetColumnDesc( int colIdx, GdbiColumnDesc &desc );
+
+    FdoByteArray * GetFgfFromGeomInfo( char * geomInfo );
 };
 
 #endif

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/bind.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/bind.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/bind.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -199,7 +199,7 @@
 
         ODBCDR_RDBI_ERR( odbcdr_geom_bindColumn( context, c, bindnum, address ) );
 
-        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows( context, c, ODBCDR_MAX_GEOM_ROWS ) );
+        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows( context, c, ODBCDR_MAX_ARRAY_SIZE) );
 
         /* 
         ** For geometries, pass the parameter number in ParameterValuePtr 

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/constants.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/constants.h	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/constants.h	2007-01-29 18:47:41 UTC (rev 699)
@@ -49,19 +49,8 @@
 ** for the buffers. An estimate of array size is used because you do not know
 ** the actual array size until execute time. 
 */
-#define ODBCDR_MAX_ARRAY_SIZE 500
+#define ODBCDR_MAX_ARRAY_SIZE 150//500
 
-/* Limit on maximum number of rows with SqlServer geometries.
- * We buffer geometries for translation on-the-fly and won't 
- * generally know the correct buffer size
- * until after the bind/define operations.  Thus, the buffers are
- * always pre-allocated to the maximum size in order to avoid
- * studying the consequences of re-bind/define operations.
- * The maximum should be at least the maximum size given by the 
- * client code expected to be using our geometries).
- */
-#define ODBCDR_MAX_GEOM_ROWS         (150)
-
 /* SQLBindParameter requires the size of data, although data is inserted
  * using SQLPutData() and teoretically this will be redundant.
  */

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/define.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/define.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/define.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -142,7 +142,7 @@
 
         ODBCDR_RDBI_ERR( odbcdr_geom_defineColumn(context, c, position, address));
 
-        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows(context, c, ODBCDR_MAX_GEOM_ROWS));
+        ODBCDR_RDBI_ERR( odbcdr_geom_setNumRows(context, c, ODBCDR_MAX_ARRAY_SIZE));
 
         ODBCDR_RDBI_ERR( odbcdr_geom_getSqlServerBuffAddr(
 											context,

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/desc_slct.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/desc_slct.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/desc_slct.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -170,6 +170,10 @@
             }
 
             break;
+		case SQL_WCHAR :
+            *rdbi_type	= RDBI_WSTRING;
+            *binary_size = odbc_precision;
+            break;
         case SQL_BIT:
             /* Handle much like a CHAR. */
             *rdbi_type = RDBI_BOOLEAN;

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/execute.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/execute.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/execute.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -185,7 +185,7 @@
 
     if ( rc == SQL_NEED_DATA && c->bound_geometries != NULL )
     {
-        assert(count <= ODBCDR_MAX_GEOM_ROWS);
+        assert(count <= ODBCDR_MAX_ARRAY_SIZE);
 
         /* Free any Oracle objects from previous executions/fetches. */
         ODBCDR_RDBI_ERR( odbcdr_geom_freeSqlServerGeometries( context, c ) );

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/fetch.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/fetch.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/fetch.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -226,10 +226,10 @@
     /* Translate geometry columns from SqlServer . */
     if ( c->defined_geometries != NULL && rows_in_last_fetch > 0 )
     {
-        if ( rows_in_last_fetch > ODBCDR_MAX_GEOM_ROWS )
+        if ( rows_in_last_fetch > ODBCDR_MAX_ARRAY_SIZE )
         {
 	//		char buffer[256];
-	//		sprintf(buffer, "TOO MANY GEOMETRY ROWS: %d (max is %d)", rows_in_last_fetch, ODBCDR_MAX_GEOM_ROWS);
+	//		sprintf(buffer, "TOO MANY GEOMETRY ROWS: %d (max is %d)", rows_in_last_fetch, ODBCDR_MAX_ARRAY_SIZE);
 	//		msg_issue(buffer, 'e');
             goto the_exit;
         }

Modified: trunk/Providers/GenericRdbms/Src/ODBCDriver/vndr_info.c
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBCDriver/vndr_info.c	2007-01-29 18:08:55 UTC (rev 698)
+++ trunk/Providers/GenericRdbms/Src/ODBCDriver/vndr_info.c	2007-01-29 18:47:41 UTC (rev 699)
@@ -71,8 +71,7 @@
 	vndr_info->minStrLen = 1;
 	vndr_info->maxStrLen = 8000;
     vndr_info->dbversion = ODBCVER; 
-	/* cannot fetch more than an array of 10 rows with Geometry */
-	vndr_info->maxFetchSize = 10;
+	vndr_info->maxFetchSize = ODBCDR_MAX_ARRAY_SIZE;
 
     // Initialize the dbversion with a more precise value
     if( context->odbcdr_conns[0] != NULL )



More information about the fdo-commits mailing list