[mapguide-commits] r4331 - in trunk/MgDev: Common/MapGuideCommon Common/MapGuideCommon/Services Common/MapGuideCommon/System Server/src/Services/Feature

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Nov 5 22:06:50 EST 2009


Author: leaf
Date: 2009-11-05 22:06:50 -0500 (Thu, 05 Nov 2009)
New Revision: 4331

Added:
   trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.h
Modified:
   trunk/MgDev/Common/MapGuideCommon/Makefile.am
   trunk/MgDev/Common/MapGuideCommon/MapGuideCommon.vcproj
   trunk/MgDev/Common/MapGuideCommon/MapGuideCommonBuild.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp
   trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonClassId.h
   trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonFactory.cpp
   trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlNonQuery.cpp
   trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp
Log:
Submit on behalf of Aleck Sun
Ticket 1141

This Defect is because the "params" argument of ExecuteSqlQuery and 
ExecuteSqlNonQuery method will be used for return value, if the a parameter is 
set as OUTPUT. However, current server structure does not allow out parameters.

Therefore, the solution is to create an intermediate object MgSqlResult which 
contains a rowUpdated integer, an MgParameterCollection and an MgSqlDataReader 
object. Once the ExecuteSqlQuery or ExecuteSqlNonQuery operation is finished, 
the intermediate MgSqlResult object will be serialized. The ProxyFeatureService 
will deserialize the MgSqlResult and process the value of out parameters.

Modified: trunk/MgDev/Common/MapGuideCommon/Makefile.am
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Makefile.am	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/Makefile.am	2009-11-06 03:06:50 UTC (rev 4331)
@@ -119,6 +119,7 @@
   Services/TileDefs.cpp \
   Services/TileService.cpp \
   Services/UnitType.cpp \
+  Services/SqlResult.cpp \
   System/ConfigProperties.cpp \
   System/MapGuideCommonFactory.cpp \
   System/MapGuideStream.cpp \
@@ -240,6 +241,7 @@
   Services/TileDefs.h \
   Services/TileService.h \
   Services/UnitType.h \
+  Services/SqlResult.h \
   System/ConfigProperties.h \
   System/MapGuideCommonClassId.h \
   System/MapGuideStream.h \

Modified: trunk/MgDev/Common/MapGuideCommon/MapGuideCommon.vcproj
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapGuideCommon.vcproj	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/MapGuideCommon.vcproj	2009-11-06 03:06:50 UTC (rev 4331)
@@ -4677,6 +4677,46 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Services\SqlResult.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|x64"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|x64"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\Services\SqlResult.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Services\TileDefs.cpp"
 				>
 				<FileConfiguration

Modified: trunk/MgDev/Common/MapGuideCommon/MapGuideCommonBuild.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapGuideCommonBuild.cpp	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/MapGuideCommonBuild.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -126,9 +126,11 @@
 #include  "Services/TileDefs.cpp"
 #include  "Services/TileService.cpp"
 #include  "Services/UnitType.cpp"
+#include  "Services/SqlResult.cpp"
 #include  "System/ConfigProperties.cpp"
 #include  "System/MapGuideCommonFactory.cpp"
 #include  "System/MapGuideStream.cpp"
 #include  "System/UserInformation.cpp"
 #include  "System/CryptographyManager.cpp"
 #include  "Util/IpUtil.cpp"
+

Modified: trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/Services/ProxyFeatureService.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -22,6 +22,7 @@
 #include "ProxyDataReader.h"
 #include "ProxyFeatureTransaction.h"
 #include "Command.h"
+#include "Services/SqlResult.h"
 
 static const int Feature_Service = (int)MgPacketParser::msiFeature;
 
@@ -1039,7 +1040,20 @@
 
     SetWarning(cmd.GetWarningObject());
 
-    Ptr<MgProxySqlDataReader> sqlReader = (MgProxySqlDataReader*)cmd.GetReturnValue().val.m_obj;
+    MgSqlResult * pResult = (MgSqlResult *)cmd.GetReturnValue().val.m_obj; 
+    if(params != NULL)
+    {
+        Ptr<MgParameterCollection> retParams = pResult->GetParameters();
+        for(int i = 0; i < retParams->GetCount(); i++)
+        {
+            Ptr<MgParameter> para = params->GetItem(i);
+            Ptr<MgParameter> newpara = retParams->GetItem(i);
+            Ptr<MgNullableProperty> prop = newpara->GetProperty();
+            para->SetProperty(prop);
+        }
+    }
+
+    Ptr<MgProxySqlDataReader> sqlReader = (MgProxySqlDataReader *)pResult->GetReader();
     if (sqlReader != NULL)
         sqlReader->SetService(this); // Feature reader on proxy side would store proxy service to call GetFeatures()
 
@@ -1124,7 +1138,7 @@
 
     MgCommand cmd;
     cmd.ExecuteCommand(m_connProp,                                  // Connection
-        MgCommand::knInt32,                                         // Return type expected
+        MgCommand::knObject,                                         // Return type expected
         MgFeatureServiceOpId::ExecuteSqlNonQueryWithTransaction_Id, // Command Code
         4,                                                          // No of arguments
         Feature_Service,                                            // Service Id
@@ -1137,7 +1151,20 @@
 
     SetWarning(cmd.GetWarningObject());
 
-    return cmd.GetReturnValue().val.m_i32;
+    MgSqlResult * pResult = (MgSqlResult *)cmd.GetReturnValue().val.m_obj; 
+    if(params != NULL)
+    {
+        Ptr<MgParameterCollection> retParams = pResult->GetParameters();
+        for(int i = 0; i < retParams->GetCount(); i++)
+        {
+            Ptr<MgParameter> para = params->GetItem(i);
+            Ptr<MgParameter> newpara = retParams->GetItem(i);
+            Ptr<MgNullableProperty> prop = newpara->GetProperty();
+            para->SetProperty(prop);
+        }
+    }
+
+    return pResult->GetRowAffected();
 }
 
 

Added: trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.cpp	                        (rev 0)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -0,0 +1,72 @@
+//
+//  Copyright (C) 2004-2009 by 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
+
+
+#include "SqlResult.h"
+
+MG_IMPL_DYNCREATE(MgSqlResult);
+
+MgSqlResult::MgSqlResult()
+{
+}
+
+MgSqlResult::MgSqlResult(int rowAffected, MgParameterCollection * parameters, MgSqlDataReader * reader)
+: m_rowAffected(rowAffected), m_parameters(parameters), m_reader(reader)
+{
+    if(parameters)
+        SAFE_ADDREF(parameters);
+
+    if(reader)
+        SAFE_ADDREF(reader);
+}
+
+MgSqlResult::~MgSqlResult()
+{
+}
+
+int MgSqlResult::GetRowAffected()
+{
+    return m_rowAffected;
+}
+
+MgParameterCollection * MgSqlResult::GetParameters()
+{
+    return SAFE_ADDREF((MgParameterCollection *)m_parameters);
+}
+
+MgSqlDataReader * MgSqlResult::GetReader()
+{
+    return SAFE_ADDREF((MgSqlDataReader *)m_reader);
+}
+
+void MgSqlResult::Serialize(MgStream *stream)
+{
+    stream->WriteInt32(m_rowAffected);
+    stream->WriteObject(m_parameters);
+    stream->WriteObject(m_reader);
+}
+
+void MgSqlResult::Deserialize(MgStream* stream)
+{
+    stream->GetInt32(m_rowAffected);
+    m_parameters = (MgParameterCollection *)stream->GetObject();
+    m_reader = (MgSqlDataReader *)stream->GetObject();
+}
+
+INT32 MgSqlResult::GetClassId()
+{
+    return m_cls_id;
+}
\ No newline at end of file

Added: trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.h	                        (rev 0)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SqlResult.h	2009-11-06 03:06:50 UTC (rev 4331)
@@ -0,0 +1,80 @@
+//
+//  Copyright (C) 2004-2009 by 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 _MG_SERVER_SQL_QUERY_RESULT_H_
+#define _MG_SERVER_SQL_QUERY_RESULT_H_
+
+class MgStream;
+class MgByteReader;
+
+/////////////////////////////////////////////////////////////////
+/// <summary>
+/// The SqlReader interface provides a forward-only, read-only
+/// iterator for reading relational table data.
+/// The initial position of the SqlReader interface is prior to the first item.
+/// Thus, you must call ReadNext to begin accessing any data..
+/// </summary>
+
+class MG_MAPGUIDE_API  MgSqlResult : public MgSerializable
+{
+MG_DECL_DYNCREATE();
+DECLARE_CLASSNAME(MgSqlResult)
+
+public:
+    MgSqlResult();
+    MgSqlResult(int rowAffected, MgParameterCollection * parameters, MgSqlDataReader * reader);
+    ~MgSqlResult();
+
+    virtual int GetRowAffected();
+
+    virtual MgParameterCollection * GetParameters();
+
+    virtual MgSqlDataReader * GetReader();
+
+    //////////////////////////////////////////////////////////////////
+    /// <summary>
+    /// Serializes all features into an XML.
+    /// XML is serialized from the current position of feature reader in the order
+    /// data are retrieved.
+    /// <returns>MgByteReader holding XML.</returns>
+    MgByteReader* ToXml();
+
+    virtual INT32 GetClassId();
+
+protected:
+
+    virtual void Dispose()
+    {
+        delete this;
+    }
+
+    
+    void Deserialize(MgStream* stream);
+    void Serialize(MgStream* stream);
+
+private:
+
+    int                         m_rowAffected;
+    Ptr<MgParameterCollection>  m_parameters;
+    Ptr<MgSqlDataReader>        m_reader;
+
+CLASS_ID:
+    static const INT32 m_cls_id = MapGuide_Service_SqlResult;
+
+};
+
+#endif

Modified: trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonClassId.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonClassId.h	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonClassId.h	2009-11-06 03:06:50 UTC (rev 4331)
@@ -109,6 +109,7 @@
 #define MapGuide_Service_UserInformation                MAPGUIDE_SERVICE_ID+6
 #define MapGuide_Service_ServerAdmin                    MAPGUIDE_SERVICE_ID+7
 #define MapGuide_Service_SiteInfo                       MAPGUIDE_SERVICE_ID+8
+#define MapGuide_Service_SqlResult                      MAPGUIDE_SERVICE_ID+9
 
 // Drawing Service
 #define MapGuide_DrawingService_DrawingService          MAPGUIDE_DRAWINGSERVICE_ID+0

Modified: trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonFactory.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonFactory.cpp	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Common/MapGuideCommon/System/MapGuideCommonFactory.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -110,7 +110,9 @@
     fact->Register(MapGuide_RenderingService_FeatureInformation, MgFeatureInformation::CreateObject);
     fact->Register(MapGuide_RenderingService_RenderingOptions, MgRenderingOptions::CreateObject);
     fact->Register(PlatformBase_FeatureService_FeatureTransaction, MgProxyFeatureTransaction::CreateObject);
+    fact->Register(MapGuide_Service_SqlResult, MgSqlResult::CreateObject);
 
+
     MgServiceRegistry* registry = MgServiceRegistry::GetInstance();
     registry->RegisterService(MgServiceType::DrawingService, MgProxyDrawingService::CreateService, sctRemoteServerToServer);
     registry->RegisterService(MgServiceType::MappingService, MgProxyMappingService::CreateService, sctRemoteServerToServer);

Modified: trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlNonQuery.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlNonQuery.cpp	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlNonQuery.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -20,6 +20,7 @@
 #include "ServerFeatureService.h"
 #include "LogManager.h"
 #include "ServerFeatureTransactionPool.h"
+#include "Services/SqlResult.h"
 
 
 ///----------------------------------------------------------------------------
@@ -128,7 +129,8 @@
         INT32 rowsUpdated = m_service->ExecuteSqlNonQuery(resource, sqlNonSelectStatement, parameters, (MgTransaction*)transaction.p);
 
         // Write the response
-        EndExecution(rowsUpdated);
+        MgSqlResult result(rowsUpdated, parameters, NULL);
+        EndExecution(&result);
     }
     else
     {

Modified: trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp	2009-11-05 19:59:40 UTC (rev 4330)
+++ trunk/MgDev/Server/src/Services/Feature/OpExecuteSqlQuery.cpp	2009-11-06 03:06:50 UTC (rev 4331)
@@ -19,6 +19,7 @@
 #include "OpExecuteSqlQuery.h"
 #include "ServerFeatureService.h"
 #include "LogManager.h"
+#include "Services/SqlResult.h"
 
 
 ///----------------------------------------------------------------------------
@@ -174,8 +175,10 @@
         // Execute the operation
         Ptr<MgSqlDataReader> sqlReader = m_service->ExecuteSqlQuery(resource, sqlStatement, parameters, (MgTransaction*)transaction.p, fetchSize);
 
+        MgSqlResult result(0, parameters, sqlReader);
+
         // Write the response
-        EndExecution((MgSqlDataReader*)sqlReader);
+        EndExecution(&result);
     }
     else
     {



More information about the mapguide-commits mailing list