A remote Data object provides a series of objects to meet the special requirements of remote database access. On top of the ODBC API and Driver Manager, RDO implements a thin layer of code to connect, create result sets and cursors, and perform complex processes using as few workstation resources as possible. If the code creates a ODBCDirect workspace object, then RDO is also accessed by DAO, as described in the previous section.
With RDO, an application does not need to use a local query handler to access an ODBC data source. This means better performance and greater flexibility when accessing the remote database engine.
By using RDO, you can create simple cursor-free result Sets or more complex cursors; You can execute queries and process any number of result sets, you can perform action queries that include data operations or data definition operations, you can limit the number of rows returned or processed, and you can, without prejudice to the execution of queries, Monitor all information and errors generated by remote data resources; RDO also supports synchronous, asynchronous, or event-driven asynchronous processing, so applications are not blocked even when lengthy queries are executed or the current pointer is repositioned.
The properties of the RDO object and collection describe the characteristics of the database parts, as well as the methods used to manipulate them. In this overall framework, you can establish relationships between objects and collections that represent the logical structure of the database system. The RDO object model is shown in the figure:
In addition to the Rdoengine object, each object is saved in a related collection. When you first access the real initialization RDO, RDO automatically creates a rdoengine and the default rdoenvironments (0) instance.
The Remote Data object programming pattern is similar to the data Access object (DAO) programming pattern in many ways. However, it focuses on processing stored procedures and their result sets, rather than only on data access retrieval methods in ISAM programming mode. Each of the objects in the RDO object model is described below.
1.RdoEngine objects
This object is the most basic object in the RDO object model. The Rdoengine object is automatically created when the application first accesses the RDO. This object cannot be explicitly created or declared by the user. The Rdoengine object is similar to the DAO's DBEngine object.
2.RdoError objects
The Rdoerror object is used to handle all ODBC errors and messages generated by RDO, which are automatically created when an error occurs. The Rdoerror object is similar to the DAO's Error object.
3.RdoEnvironment objects
The Rdoenvironment object defines a logical set of connections and transaction scopes for a particular user name. Includes open and allocated (but not open) connections, provides a mechanism for concurrent transactions, and provides a secure context for the data Manipulation Language (DML) of the database, and when the application first accesses RDO, Automatically creates a Rdoenvironment object and adds it to the Rdoenvironments collection, referencing it with rdoenvironment (0). The Rdoenvironment object is the default object, or the Rdoenvironment object can be explicitly created in the program, and the application uses Rdoenvironments (0) If no new Rdoenvironment object is created in the program.
Use the Rdoengine Rdocreateenvironment method to create a new Rdoenvironment object:
Var=rdoengine.rdocreateenvironment (Name,username,password)
Where the name parameter is the names of the Rdoenvironment objects, the username and password parameters are the user names and passwords that connect to the ODBC data source, respectively. They are properties of the Rdoenvironment object.
The Rdoenvironment object is similar to the DAO's Workspace object.
4.RdoConnection objects
The Rdoconnection object represents a connection that is open between a remote data source and a particular database on the data source, or an assigned but still disconnected object that can be used for a subsequent connection.
You can use the OpenConnection method of the Rdoenvironment object to create a Rdoconnection object and establish a connection.
Connection=rdoenvironment.openconnection (Dsname[,prompt[,readonly[,connect[options]]])
The Rdoconnection object is similar to the DAO's connection object, so the argument meaning of the above method is the same as described earlier.
For example, the following statement shows the application and data source WORKDB establish a connection that prompts the user for a username and password when connected:
All of these are DSN-connected, and RDO can also be used to create a connection without a DSN. Creating a connection without a DSN simplifies the setup and installation of client applications, speeds up connection speeds, and improves security. When creating a connection without a DSN, you must set the OpenConnection dsname parameter to an empty string, and in the connect string, the DSN parameter must be after the server and driver parameters. For example, the following statement creates a connection without a DSN:
The Rdoconnection object is similar to the DAO's database.
5.RdoTable objects
The Rdotable object represents a storage definition for a basic table or SQL view. Use this object to manage the structure of the database. Once a connection has been established with the data source, each base table or SQL view in the data source is added to the Rdotables collection as a Rdotable object. Adding a table, deleting a table, or modifying a table's structure is an operation on a Rdotable object, as the following code lists the names of all the tables in the data source:
6.RdoResultset objects
The Rdoresultset object represents the rows of data that are generated by running a query. This object is the most commonly used object in RDO programming. When you execute a query, the query results are placed in the result set. A result set can contain fields from one or more tables in the database. Depending on the type of cursor, you can have 4 different types of rdoresultset objects:
(1) a result set (Forward only) in which records can be moved forward only. In this result set, each row of data can be accessed, but the record movement can only use the MoveNext method to move backwards.
(2) A static type result set (Static-type). It can be used to find data or to produce a static copy of a report's records. If the data source can be modified, the static result set can also be modified.
(3) The result set of a keyset (Keyset-type) type. This result set can contain modifiable rows, where movement is unrestricted. This result set enables you to dynamically add, modify, and delete records. Its members are fixed.
(4) A dynamic type result set (Dynamic-type). This result set can contain modifiable rows, dynamically adding, modifying, and deleting records, and its members are not fixed.
You can create a Rdoresultset object by using the OpenResultset method of the Rdoquery object or Rdoconnection object.
Once you have created the rdoresultset, you can access the data in it. The following points need to be noted when working with result sets:
(1) If the result set is created as a cursor, the result must be placed in the result set as soon as possible because the data rows and pages obtained by the cursor may be locked by the remote database engine. The result set does not complete placement until the last row is positioned.
(2) In many cases, a result set without a cursor is more efficient. Rdoresultset object functions to meet the needs of the appropriate, do not have redundant features. For example, if you do not need to use cursors to modify data, do not request a result set that is allowed to be updated. Cursors that can scroll arbitrarily are also unnecessary if you want to place only into a list box.
(3) Consider using a cursor-free result set and an action query to perform the update. In many cases, this approach can improve performance. Although it is more complex to implement, this approach can be used when basic data is not directly accessible.
(4) Use asynchronous operations and event procedures as much as possible to prevent applications from being locked down, at least to reduce this possibility. You can also handle the move method asynchronously, such as using MoveLast, to prevent the lock from being locked when the result set is placed.
(5) Complex result set processing creates several small result sets, which often make it faster and better manage system resources.
(6) Generate result sets as much as possible from stored procedures, as this can improve the efficiency of servers, networks, and workstations and make application development simpler.
(7) Disconnect existing rdoresultset objects created in the form of a client batch cursor. You can continue to modify the data using the edit or AddNew method. When you are ready to return the changes you made to the database, you can set the ActiveConnection object to an open Rdoconnection object, which associates the rdoresultset to an open connection.
The Rdoresultset object is similar to the DAO's Recordset object.
7.RdoQuery objects
The Rdoquery object is a query SQL definition that can include 0 or more parameters. You can use the CreateQuery method of the Rdoconnection object to create a new query, such as:
8.Rdocolumn objects
The Rdocolumn object represents a series of data with common data types and public properties. This object is a child of the rdotable, Rdoquery, and Rdoresultset objects. You can use the object's "value" property to access the value of a column, or you can use the object's Type property or the Size property to modify the structure of the table in the database.
The Rdocolumn object is similar to the DAO's Field object.
9.RdoParameter objects
The Rdoparameter object object represents a parameter that is connected to the Rdoquery object. Query parameters can be input, output, or input and output parameters. This object is created automatically when a query with parameters is made. You can set the parameter type with the "Direction" property of the Rdoparameter object: the input parameter (Rdparamreturn Value). For example, the following code executes an SQL statement with 4 arguments.
10.RdoPrepareStatement objects
This object defines a query in advance. It is obsolete, only to preserve this object in order to maintain compatibility with previous versions of RDO. After RDO2.0, you should use the Rdoquery object.