[mapguide-commits] r6643 - trunk/MgDev/Server/src/Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu May 10 21:41:17 EDT 2012


Author: hubu
Date: 2012-05-10 18:41:17 -0700 (Thu, 10 May 2012)
New Revision: 6643

Modified:
   trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h
   trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp
   trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h
Log:
On behalf of Andy Zhang
Fix ticket #1996: ReadNext method loops when using SqLite database.

When call ReadNext() from web-tier side, it actually doesn?\226?\128?\153t send a ReadNext() operation request to Map Server. Instead, it sends a GetRows operation request to get a lot of records, then cache the records. If the GetRows operation returns an empty collection, then we think we have reached the end of the reader. 
But there is no specification in the FDO API about what we should do in case an application calls again ReadNext? after reader is depleted. In SQLite, the sqlite engine resets the statement automatically and start it over again. Therefore, the GetRows method will never return an empty collection for Sqlite database. Then the ReadNext() method in the web app would be an endless loop. 
This submission fixes ServerDataReader and ServerSqlDataReader to make IM Server runs correctly when using SQLite database. 

Files updated:
Server/src/Services/Feature/ServerDataReader.cpp
Server/src/Services/Feature/ServerDataReader.h 
Server/src/Services/Feature/ServerSqlDataReader.cpp 
Server/src/Services/Feature/ServerSqlDataReader.h 



Modified: trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp	2012-05-10 15:48:38 UTC (rev 6642)
+++ trunk/MgDev/Server/src/Services/Feature/ServerDataReader.cpp	2012-05-11 01:41:17 UTC (rev 6643)
@@ -33,6 +33,7 @@
     m_dataReader = FDO_SAFE_ADDREF(dataReader);
     m_providerName = providerName;
     m_removeFromPoolOnDestruction = false;
+    m_readerDepleted = false;
 
     // The reader takes ownership of the FDO connection
     m_connection->OwnReader();
@@ -48,6 +49,7 @@
     m_dataReader = NULL;
     m_providerName = L"";
     m_removeFromPoolOnDestruction = false;
+    m_readerDepleted = false;
 }
 
 MgServerDataReader::~MgServerDataReader()
@@ -72,6 +74,9 @@
 {
     CHECKNULL(m_dataReader, L"MgServerDataReader.ReadNext");
 
+    if (m_readerDepleted)
+        return false;
+
     bool retVal = false;
 
     MG_FEATURE_SERVICE_TRY()
@@ -80,6 +85,9 @@
 
     MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgServerDataReader.ReadNext")
 
+    if (!retVal)
+        m_readerDepleted = true;
+
     return retVal;
 }
 
@@ -1545,6 +1553,7 @@
         {
             break;
         }
+        name = L"";
     }
 
     return name;
@@ -1690,6 +1699,9 @@
 {
     CHECKNULL((MgBatchPropertyCollection*)m_bpCol, L"MgServerDataReader.AddRows");
 
+    if (m_readerDepleted)
+        return;
+
     INT32 desiredFeatures = 0;
 
     bool found = false;
@@ -1737,6 +1749,9 @@
             found = false;
         }
     }
+
+    if (!found)
+        m_readerDepleted = true;
 }
 
 void MgServerDataReader::AddCurrentRow()

Modified: trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h	2012-05-10 15:48:38 UTC (rev 6642)
+++ trunk/MgDev/Server/src/Services/Feature/ServerDataReader.h	2012-05-11 01:41:17 UTC (rev 6643)
@@ -482,6 +482,7 @@
     Ptr<MgBatchPropertyCollection>       m_bpCol;
     Ptr<MgPropertyDefinitionCollection>  m_propDefCol;
     void AddCurrentRow();
+    FdoBoolean m_readerDepleted;
 
 CLASS_ID:
     static const INT32 m_cls_id = PlatformBase_FeatureService_DataReader;

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp	2012-05-10 15:48:38 UTC (rev 6642)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.cpp	2012-05-11 01:41:17 UTC (rev 6643)
@@ -31,6 +31,7 @@
     m_connection = SAFE_ADDREF(connection);
     m_sqlReader = FDO_SAFE_ADDREF(sqlReader);
     m_providerName = providerName;
+    m_readerDepleted = false;
 
     // The reader takes ownership of the FDO connection
     m_connection->OwnReader();
@@ -45,6 +46,7 @@
     m_connection = NULL;
     m_sqlReader = NULL;
     m_providerName = L"";
+    m_readerDepleted = false;
 }
 
 MgServerSqlDataReader::~MgServerSqlDataReader()
@@ -69,6 +71,9 @@
 {
     CHECKNULL(m_sqlReader, L"MgServerSqlDataReader.ReadNext");
 
+    if (m_readerDepleted)
+        return false;
+
     bool retVal = false;
 
     MG_FEATURE_SERVICE_TRY()
@@ -77,6 +82,9 @@
 
     MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgServerSqlDataReader.ReadNext")
 
+    if (!retVal)
+        m_readerDepleted = true;
+
     return retVal;
 }
 
@@ -1493,8 +1501,12 @@
     CHECKNULL((MgServerSqlDataReader*)m_sqlReader, L"MgServerSqlDataReader.AddRows");
     CHECKNULL((MgBatchPropertyCollection*)m_bpCol, L"MgServerSqlDataReader.AddRows");
 
+    if (m_readerDepleted)
+        return;
+
     INT32 desiredFeatures = 0;
-
+    bool readAtEnd = true;
+    
     while (m_sqlReader->ReadNext())
     {
         AddCurrentRow();
@@ -1503,6 +1515,7 @@
             desiredFeatures++;
             if (desiredFeatures == count) // Collected required features therefore do not process more
             {
+                readAtEnd = false;
                 break;
             }
         }
@@ -1511,6 +1524,9 @@
             continue;
         }
     }
+    
+    if (readAtEnd)
+        m_readerDepleted = true;
 }
 
 void MgServerSqlDataReader::AddCurrentRow()

Modified: trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h	2012-05-10 15:48:38 UTC (rev 6642)
+++ trunk/MgDev/Server/src/Services/Feature/ServerSqlDataReader.h	2012-05-11 01:41:17 UTC (rev 6643)
@@ -454,6 +454,7 @@
     Ptr<MgBatchPropertyCollection>       m_bpCol;
     Ptr<MgPropertyDefinitionCollection>  m_propDefCol;
     void AddCurrentRow();
+    FdoBoolean m_readerDepleted;
 
 CLASS_ID:
     static const INT32 m_cls_id = PlatformBase_FeatureService_SqlDataReader;



More information about the mapguide-commits mailing list