Changes between Initial Version and Version 1 of MapGuideRfc80


Ignore:
Timestamp:
Aug 6, 2009, 5:30:02 PM (15 years ago)
Author:
leaf
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideRfc80

    v1 v1  
     1= !MapGuide RFC 80 - Parameter Binding =
     2
     3This page contains an change request (RFC) for the !MapGuide Open Source project.
     4More !MapGuide RFCs can be found on the [wiki:MapGuideRfcs RFCs] page.
     5
     6
     7== Status ==
     8
     9||RFC Template Version||(1.0)||
     10||Submission Date||Aug 07, 2009||
     11||Last Modified||Leaf Li [[Timestamp]]||
     12||Author||Leaf Li||
     13||RFC Status||draft||
     14||Implementation Status||under development||
     15||Proposed Milestone||2.2||
     16||Assigned PSC guide(s)||Bruce Dechant||
     17||'''Voting History'''||July 27, 2009||
     18||+1||Tom, Jason, Kenneth, Trevor, Paul, Andy||
     19||+0||||
     20||-0||||
     21||-1||
     22||no vote||Bruce, Harris, Bob ||
     23
     24== Overview ==
     25
     26This proposal is to extend MapGuide Feature Service to support parameter binding when executing an SQL statement against a feature source.
     27
     28== Motivation ==
     29
     30Currently FDO interface supports parameter binding when executing an FdoISQLCommand. Method GetParameterValues() returns a parameters value collection and users can set value for each named parameter. However, MapGuide Feature Service doesn’t provide this capability. This RFC will add two methods into Feature Service API to eliminate this limitation. 
     31
     32== Proposed Solution ==
     33
     34==== Parameter Direction ====
     35
     36The !MgParameterDirection defines integer constants used to signify the direction in which command will utilize the parameter upon execution. Parameter direction values are typically Input, Output, InputOutput and Return, with the default value is typically Input.
     37
     38{{{
     39///////////////////////////////////////////////
     40/// \brief
     41/// The MgParameterDirection defines integer constants used to signify the
     42/// direction in which a Parameter value will be used within the context of a
     43/// FDO Command.
     44class MgParameterDirection
     45{
     46PUBLISHED_API:
     47    /// \brief
     48    /// Specifies that the parameter is an input parameter.
     49    ///
     50    static const INT32 Input = 1;
     51
     52    /// \brief
     53    /// Specifies that the parameter is an output parameter.
     54    ///
     55    static const INT32 Output = 2;
     56
     57    /// \brief
     58    /// Specifies that the parameter is an input & output parameter.
     59    ///
     60    static const INT32 InputOutput = 3;
     61
     62    /// \brief
     63    /// Specifies that the parameter is a return parameter.
     64    ///
     65    static const INT32 Return = 4;
     66};
     67}}}
     68
     69==== Parameter Value ====
     70
     71The MgParameter class specifies a value for a particular parameter.  Instances of this class are used to specify a value to bind to a parameter when a command is executed. Typically, it is used to bind parameters to the SQL command.
     72
     73{{{
     74/// \brief
     75/// The MgParameter class specifies a value for a particular parameter.
     76/// Instances of this class are used to specify a value to bind to a parameter
     77/// when a command is executed. Typically, it is used to bind parameters to
     78/// the SQL command.
     79class MgParameter : public MgNamedSerializable
     80{
     81PUBLISHED_API:
     82    /// \brief
     83    /// Constructs an MgParameter object with null parameter value.
     84    ///
     85    /// \param name (String/string)
     86    /// The name of the parameter
     87    ///
     88    MgParameter (CREFSTRING name);
     89 
     90   /// \brief
     91    /// Constructs an MgParameter object with a boolean vlaue.
     92    ///
     93    /// \param name (String/string)
     94    /// The name of the parameter
     95    /// \param value (boolean/bool)
     96    /// The value of the parameter
     97    ///
     98    MgParameter (CREFSTRING name, bool value);
     99
     100    /// \brief
     101    /// Constructs an MgParameter object with a byte vlaue.
     102    ///
     103    /// \param name (String/string)
     104    /// The name of the parameter
     105    /// \param value (signed char/unsigned char/string)
     106    /// The value of the parameter
     107    ///
     108    MgParameter (CREFSTRING name, BYTE value);
     109
     110    /// \brief
     111    /// Constructs an MgParameter object with an MgDateTime instance.
     112    ///
     113    /// \param name (String/string)
     114    /// The name of the parameter
     115    /// \param value (MgDateTime)
     116    /// The value of the parameter
     117    ///
     118    MgParameter (CREFSTRING name, MgDateTime* value);
     119
     120    /// \brief
     121    /// Constructs an MgParameter object with a float value.
     122    ///
     123    /// \param name (String/string)
     124    /// The name of the parameter
     125    /// \param value (float)
     126    /// The value of the parameter
     127    ///
     128    MgParameter (CREFSTRING name, float value);
     129
     130    /// \brief
     131    /// Constructs an MgParameter object with a double value.
     132    ///
     133    /// \param name (String/string)
     134    /// The name of the parameter
     135    /// \param value (double)
     136    /// The value of the parameter
     137    ///
     138    MgParameter (CREFSTRING name, double value);
     139
     140    /// \brief
     141    /// Constructs an MgParameter object with a 16 bits integer.
     142    ///
     143    /// \param name (String/string)
     144    /// The name of the parameter
     145    /// \param value (short/int)
     146    /// The value of the parameter
     147    ///
     148    MgParameter (CREFSTRING name, INT16 value);
     149
     150    /// \brief
     151    /// Constructs an MgParameter object with a 32 bits integer.
     152    ///
     153    /// \param name (String/string)
     154    /// The name of the parameter
     155    /// \param value (int)
     156    /// The value of the parameter
     157    ///
     158    MgParameter (CREFSTRING name, INT32 value);
     159
     160    /// \brief
     161    /// Constructs an MgParameter object with a 64 bits integer.
     162    ///
     163    /// \param name (String/string)
     164    /// The name of the parameter
     165    /// \param value (long/string)
     166    /// The value of the parameter
     167    ///
     168    MgParameter (CREFSTRING name, INT64 value);
     169
     170    /// \brief
     171    /// Constructs an MgParameter object with a string.
     172    ///
     173    /// \param name (String/string)
     174    /// The name of the parameter
     175    /// \param value (String/string)
     176    /// The value of the parameter
     177    ///
     178    MgParameter (CREFSTRING name, CREFSTRING value);
     179
     180    /// \brief
     181    /// Constructs an MgParameter object with an MgGeometry instance.
     182    ///
     183    /// \param name (String/string)
     184    /// The name of the parameter
     185    /// \param value
     186    /// The value of the parameter
     187    ///
     188    MgParameter (CREFSTRING name, MgGeometry* value);
     189
     190    /// \brief
     191    /// Constructs an MgParameter object with an MgByteReader instance.
     192    ///
     193    /// \param name (String/string)
     194    /// The name of the parameter
     195    /// \param value
     196    /// The value of the parameter
     197    /// \param valueType
     198    /// The type of parameter value. It can be one of MgPropertyType::Blob,
     199    /// MgPropertyType::Clob or MgPropertyType::Geometry.
     200    ///
     201    MgParameter (CREFSTRING name, MgByteReader* value, INT32 valueType);
     202
     203    /// \brief
     204    /// Gets the parameter name.
     205    ///
     206    /// \return
     207    /// Returns the parameter name.
     208    ///
     209    STRING GetName();  /// __get, __set
     210    ///////////////////////////////////////////////////
     211    /// \brief
     212    /// Gets the parameter type.
     213    ///
     214    /// \return
     215    /// Returns the parameter type. See MgPropertyType.
     216    ///
     217    INT32 GetType() = 0;  /// __get
     218
     219    /// \brief
     220    /// Test whether the parameter value is null.
     221    ///
     222    /// \return
     223    /// True if the parameter value is null, false Otherwise.
     224    ///
     225    bool IsNull();
     226
     227    /// \brief
     228    /// Gets the boolean value of the parameter.
     229    ///
     230    /// \remarks
     231    /// No conversion is performed. Therefore, the parameter must be
     232    /// of type MgPropertyType::Boolean or an
     233    /// MgInvalidPropertyTypeException is thrown.
     234    ///
     235    /// \return
     236    /// Returns the boolean value.
     237    ///
     238    /// \exception MgInvalidPropertyTypeException.
     239    ///
     240    bool GetBoolean();
     241
     242    /// \brief
     243    /// Gets the byte value of the parameter.
     244    ///
     245    /// \remarks
     246    /// No conversion is performed. Therefore, the parameter must be
     247    /// of type MgPropertyType::Byte or an
     248    /// MgInvalidPropertyTypeException is thrown.
     249    ///
     250    /// \return
     251    /// Returns the byte value.
     252    ///
     253    /// \exception MgInvalidPropertyTypeException.
     254    ///
     255    BYTE GetByte() = 0;
     256
     257    /// \brief
     258    /// Gets the MgDateTime value of the parameter.
     259    ///
     260    /// \remarks
     261    /// No conversion is performed. Therefore, the parameter must be
     262    /// of type MgPropertyType::DateTime or an
     263    /// MgInvalidPropertyTypeException is thrown.
     264    ///
     265    /// \return
     266    /// Returns an MgDateTime object.
     267    ///
     268    /// \exception MgInvalidPropertyTypeException.
     269    ///
     270    MgDateTime* GetDateTime();
     271
     272    /// \brief
     273    /// Gets the float value of the parameter.
     274    ///
     275    /// \remarks
     276    /// No conversion is performed. Therefore, the parameter must be a
     277    /// of type MgPropertyType::Single or an
     278    /// MgInvalidPropertyTypeException is thrown.
     279    ///
     280    /// \return
     281    /// Returns the float value.
     282    ///
     283    /// \exception MgInvalidPropertyTypeException.
     284    ///
     285    float GetSingle() = 0;
     286
     287    /// \brief
     288    /// Gets the double value of the parameter.
     289    ///
     290    /// \remarks
     291    /// No conversion is performed. Therefore, the parameter must be a
     292    /// of type MgPropertyType::Double or an
     293    /// MgInvalidPropertyTypeException is thrown.
     294    ///
     295    /// \return
     296    /// Returns the double value.
     297    ///
     298    /// \exception MgInvalidPropertyTypeException.
     299    ///
     300    double GetDouble() = 0;
     301
     302    /// \brief
     303    /// Gets the 16 bits integer value of the parameter.
     304    ///
     305    /// \remarks
     306    /// No conversion is performed. Therefore the parameter must be a
     307    /// of type MgPropertyType::Int16 or an
     308    /// MgInvalidPropertyTypeException is thrown.
     309    ///
     310    /// \return
     311    /// Returns the 16 bits integer value.
     312    ///
     313    /// \exception MgInvalidPropertyTypeException
     314    ///
     315    INT16 GetInt16();
     316
     317    /// \brief
     318    /// Gets the 32 bits integer value of the parameter.
     319    ///
     320    /// \remarks
     321    /// No conversion is performed. Therefore, the parameter must be a
     322    /// of type MgPropertyType::Int32 or an
     323    /// MgInvalidPropertyTypeException is thrown.
     324    ///
     325    /// \return
     326    /// Returns the 32 bits integer value.
     327    ///
     328    /// \exception MgInvalidPropertyTypeException.
     329    ///
     330    INT32 GetInt32();
     331
     332    /// \brief
     333    /// Gets the 64 bits integer value of the parameter.
     334    ///
     335    /// \remarks
     336    /// No conversion is performed. Therefore, the parameter must be a
     337    /// of type MgPropertyType::Int64 or an
     338    /// MgInvalidPropertyTypeException is thrown.
     339    ///
     340    /// \return
     341    /// Returns the 64 bits integer value.
     342    ///
     343    /// \exception MgInvalidPropertyTypeException.
     344    ///
     345    INT64 GetInt64();
     346
     347    /// \brief
     348    /// Gets the string value of the parameter.
     349    ///
     350    /// \remarks
     351    /// No conversion is performed. Therefore, the parameter must be a
     352    /// of type MgPropertyType::String or an
     353    /// MgInvalidPropertyTypeException is thrown.
     354    ///
     355    /// \return
     356    /// Returns the string value.
     357    ///
     358    /// \exception MgInvalidPropertyTypeException.
     359    ///
     360    STRING GetString();
     361
     362    /// \brief
     363    /// Gets the geometry value of the parameter.
     364    ///
     365    /// \remarks
     366    /// No conversion is performed. Therefore, the parameter must be a
     367    /// of type MgPropertyType::Geometry or an
     368    /// MgInvalidPropertyTypeException is thrown.
     369    ///
     370    /// \return
     371    /// Returns the geometry value.
     372    ///
     373    /// \exception MgInvalidPropertyTypeException.
     374    ///
     375MgGeometry* GetGeometry();
     376
     377    /// \brief
     378    /// Gets the byte reader value of the parameter.
     379    ///
     380    /// \remarks
     381    /// No conversion is performed. Therefore, the parameter must be a
     382    /// of type MgPropertyType::Blob, MgPropertyType::Clob or
     383    /// MgPropertyType::Geometry. Otherwise, an
     384    /// MgInvalidPropertyTypeException is thrown.
     385    ///
     386    /// \return
     387    /// Returns the byte reader value.
     388    ///
     389    /// \exception MgInvalidPropertyTypeException.
     390    ///
     391    MgByteReader* GetByteReader();
     392
     393    /// \brief
     394    /// Sets the function direction of the parameter value, which
     395    /// is defined in MgParameterDirection.
     396    ///
     397    /// \param value
     398    /// Input the direction value
     399    ///
     400    /// \return
     401    /// Returns nothing
     402    ///
     403    void SetDirection(INT32 value);
     404
     405    /// \brief
     406    /// Gets the function direction value of the the command parameter, which
     407    /// is defined in MgParameterDirection.
     408    ///
     409    /// \return
     410    /// Returns the direction value defined in MgParameterDirection.
     411    ///
     412    INT32 GetDirection();
     413};
     414}}}
     415
     416==== Parameter Collection ====
     417
     418MgParameterCollection represents a collection of MgParameter.
     419
     420{{{
     421/// \brief
     422/// MgParameterCollection represents a collection of parameters.
     423/// All parameters contained in an instance of a parameter
     424/// collection are objects whose base class is MgParameter.
     425/// A call to a parameter object's GetType() method returns one
     426/// of the integer constants defined in class MgPropertyType.
     427/// This collection does not allow duplicate key names.
     428class MgParameterCollection : public MgCollection
     429{
     430PUBLISHED_API:
     431    /// \brief
     432    /// Constructs an MgParameterCollection. The collection is initially empty.
     433    ///
     434    MgParameterCollection();
     435
     436    /// \brief
     437    /// Sets the item in the collection at the specified index to
     438    /// the specified value.
     439    ///
     440    /// \param index (int)
     441    /// Input index
     442    /// \param value (MgParameter)
     443    /// Input value
     444    ///
     445    /// \return
     446    /// Returns nothing.
     447    ///
     448    /// \exception MgIndexOutOfRangeException if the index is out of range.
     449    /// \exception MgDuplicateObjectException if it is a duplicate.
     450    ///
     451    virtual void SetItem(INT32 index, MgParameter* value);
     452
     453    /// \brief
     454    /// Adds the specified item to the end of the collection.
     455    ///
     456    /// \param value (MgParameter)
     457    /// Input value
     458    ///
     459    /// \return
     460    /// Returns nothing.
     461    ///
     462    /// \exception MgDuplicateObjectException if the index is a duplicate.
     463    ///
     464    virtual void Add(MgParameter* value);
     465
     466    /// \brief
     467    /// Inserts the specified item at the specified index within the collection.
     468    /// Items following the insertion point are moved down to accommodate
     469    /// the new item.
     470    ///
     471    /// \param index (int)
     472    /// Input index
     473    /// \param value (MgParameter)
     474    /// Input value
     475    ///
     476    /// \return
     477    /// Returns nothing.
     478    ///
     479    /// \exception MgIndexOutOfRangeException if the index is out of range.
     480    /// \exception MgDuplicateObjectException if it is a duplicate.
     481    ///
     482    virtual void Insert(INT32 index, MgParameter* value);
     483
     484    /// \brief
     485    /// Removes the specified item from the collection.
     486    ///
     487    /// \param value (MgParameter)
     488    /// Input value
     489    ///
     490    /// \return
     491    /// Returns true if removal was successful.
     492    ///
     493    virtual bool Remove(MgParameter* value);
     494
     495    /// \brief
     496    /// Gets the item in the collection at the specified index.
     497    ///
     498    /// \param index (int)
     499    /// Input index
     500    ///
     501    /// \return
     502    /// Returns the item in the collection at the specified index.
     503    ///
     504    /// \exception MgIndexOutOfRangeException if the index is out of range.
     505    ///
     506    virtual MgParameter* GetItem(INT32 index) const;
     507
     508    /// \brief
     509    /// Gets the item in the collection with the specified name.
     510    ///
     511    /// \param name (String/string)
     512    /// Input item name
     513    ///
     514    /// \return
     515    /// Returns the item in the collection with the specified name.
     516    ///
     517    /// \exception MgObjectNotFoundException if the item does not exist
     518    /// within the collection.
     519    ///
     520    virtual MgParameter* GetItem(CREFSTRING name);
     521
     522    /// \brief
     523    /// Gets the number of items in the collection.
     524    ///
     525    /// \return
     526    /// Returns the number of items in the collection.
     527    ///
     528    virtual INT32 GetCount() const;
     529
     530    /// \brief
     531    /// Removes all items from the collection.
     532    ///
     533    /// \return
     534    /// Returns nothing.
     535    ///
     536    virtual void Clear();
     537
     538    /// \brief
     539    /// Removes the specified item from the collection.
     540    ///
     541    /// \param index (int)
     542    /// Input index
     543    ///
     544    /// \return
     545    /// Returns nothing.
     546    ///
     547    /// \exception MgIndexOutOfRangeException
     548    ///
     549    virtual void RemoveAt(INT32 index);
     550
     551    /// \brief
     552    /// Returns true if the collection contains the specified item,
     553    /// false otherwise.
     554    ///
     555    /// \param value (MgParameter)
     556    /// Input value
     557    ///
     558    /// \return
     559    /// Returns true if the collection contains the specified item,
     560    /// false otherwise.
     561    ///
     562    virtual bool Contains(const MgParameter* value);
     563
     564    /// \brief
     565    /// Returns true if the collection contains the specified item,
     566    /// false otherwise.
     567    ///
     568    /// \param name (String/string)
     569    /// Input the item name
     570    ///
     571    /// \return
     572    /// Returns true if the collection contains the specified item,
     573    /// false otherwise.
     574    ///
     575    virtual bool Contains(CREFSTRING name);
     576
     577    /// \brief
     578    /// Returns the index of the specified item in the collection or -1
     579    /// if the item does not exist.
     580    ///
     581    /// \param value (MgParameter)
     582    /// Input value
     583    ///
     584    /// \return
     585    /// Returns the index of the specified item in the collection or -1
     586    /// if the item does not exist.
     587    ///
     588    virtual INT32 IndexOf(const MgParameter* value) const;
     589
     590    /// \brief
     591    /// Returns the index of the specified item (by name) in the collection
     592    /// or -1 if the item does not exist.
     593    ///
     594    /// \param name (String/string)
     595    /// Input the item name
     596    ///
     597    /// \return
     598    /// Returns the index of the specified item in the collection or -1
     599    /// if the item does not exist.
     600    ///
     601    virtual INT32 IndexOf(CREFSTRING name) const;
     602};
     603}}}
     604
     605==== Parameter Collection ====
     606
     607Feature Service will be extended to add two methods to support parameter binding when executing an SQL statement against a feature source.
     608
     609{{{
     610class MgFeatureService : public MgService
     611{
     612PUBLISHED_API:
     613    //////////////////////////////////////////////////////////////
     614    /// \brief
     615    /// Executes the SQL SELECT statement with the specified parameters
     616    /// on the specified feature source.
     617    ///
     618    /// \param resource (MgResourceIdentifier)
     619    /// A resource identifier referring to a feature source.
     620    /// \param sqlStatement (String/string)
     621    /// The SQL SELECT statement.
     622    /// \param params (MgParameterCollection)
     623    /// Parameters binded to the SQL statement.
     624    ///
     625    /// \return
     626    /// Returns an MgSqlDataReader instance (or NULL).
     627    ///
     628    virtual MgSqlDataReader* ExecuteSqlQuery( MgResourceIdentifier* resource,
     629                                              CREFSTRING sqlStatement,
     630                                              MgParameterCollection* params ) = 0;
     631
     632    ///////////////////////////////////////////////////////
     633    /// \brief
     634    /// Executes SQL statements NOT including SELECT statements
     635    /// with the specified parameters.
     636    ///
     637    /// \param resource (MgResourceIdentifier)
     638    /// A resource identifier for a feature source.
     639    /// \param sqlNonSelectStatement (String/string)
     640    /// The SQL statement that is NOT a SELECT statement.
     641    /// \param params (MgParameterCollection)
     642    /// Parameters binded to the SQL statement.
     643    ///
     644    /// \return
     645    /// Returns a positive integer value indicating how many
     646    /// instances (rows) have been affected.
     647    ///
     648    virtual INT32 ExecuteSqlNonQuery( MgResourceIdentifier* resource,
     649                                      CREFSTRING sqlNonSelectStatement,
     650                                      MgParameterCollection* params ) = 0;
     651};
     652}}}
     653
     654== Implications ==
     655
     656This RFC depends on FDO RFC 33 (http://trac.osgeo.org/fdo/wiki/FDORfc33), which improves parameter binding to support specifying parameter direction. If FDO RFC 33 can’t get approved, we will not remove class MgParameterDirection and method MgParameter::SetDirection(...) and MgParameter::GetDirection() in this RFC.
     657
     658== Test Plan ==
     659
     660This is new API only. There will be no effect on existing applications. However, API documentation need to be updated. Moreover, we will add unit tests for those two newly added methods into the existing Feature Service unit tests.
     661
     662== Funding/Resources ==
     663
     664Supplied by Autodesk.