CreateDynaset Method

Applies To

OraDatabase Object

Description

Creates an OraDynaset object from the specified SQL SELECT statement and options.

Usage

Set oradynaset = oradatabase.CreateDynaset(sql_statement, options, SnapShotID)
Set oradynaset = oradatabase.DbCreateDynaset(sql_statement, options, SnapShotID)

Arguments

The arguments for the method are:

Arguments Description
sql_statement A String containing any valid Oracle SQL SELECT statement.
options A bit flag indicating the status of any optional states of the dynaset. You can combine one or more options by adding their respective values. Specifying the constant ORADYN_DEFAULT or the value &H0& gives the following defaults for the dynaset:
  • Behave like Visual Basic Mode for a database: Field values not explicitly set are set to Null, overriding database column defaults.

  • Perform automatic binding of database parameters.

  • Remove trailing blanks from character string data retrieved from the database.

  • Create an updatable dynaset.

  • Cache data on client.

  • Force a MoveFirst when the dynaset is created.

  • Maintain read-consistency.

SnapShotID [optional] A ID of the snapshot obtained from the SnapShot property of an OraDynaset object.

Constants

The following table lists constants and values for the options flag.

Constant Value Description
ORADYN_DEFAULT &H0& Accept the default behavior.
ORADYN_NO_AUTOBIND &H1& Do not perform automatic binding of database parameters.
ORADYN_NO_BLANKSTRIP &H2& Do not remove trailing blanks from character string data retrieved from the database.
ORADYN_READONLY &H4& Force dynaset to be read-only.
ORADYN_NOCACHE &H8& Do not create a local dynaset data cache. Without the local cache, previous rows within a dynaset are unavailable; however, increased performance results during retrieval of data from the database (move operations) and from the rows (field operations). Use this option in applications that make single passes through the rows of a dynaset for increased performance and decreased resource usage.
ORADYN_ORAMODE &H10& Behave the same as Oracle Mode for a database except affect only the dynaset being created. If database was created in Oracle Mode, the dynaset inherits the property from it (for compatibility).
ORADYN_NO_REFETCH &H20& Behave the same as ORADB_NO_REFETCH mode for a database except affect only the dynaset being created. If the database was created in ORADB_NO_REFETCH mode, the dynaset inherits the property for compatibility.
ORADYN_NO_MOVEFIRST &H40& Does not force a MoveFirst when the dynaset is created. BOF and EOF are both true.
ORADYN_DIRTY_WRITE &H80& Update and Delete methods do not check for read consistency.

These values can be found in the oraconst.txt file.

Remarks

Features such as simple views and synonyms can be used freely. You can also use schema references, column aliases, table joins, nested select statements and remote database references, but in each case, the dynaset is read-only.

If you use a complex expression or SQL function on a column, such as "sal + 100" or "abs(sal)" , you get an updatable dynaset, but the column associated with the complex expression is not updatable.

Object names generally are not modifed, but in certain cases they can be changed. For example, if you use a column alias, you must use the alias to refer to the field by name. Also, if you use spaces in a complex expression, you must refer to the column without the spaces, since the database strips spaces. Note that you can always refer to a field by number, that is, by its ordinal position in the SELECT statement.

Executing the Update method generates a commit operation to the database by default. To avoid this, use the BeginTrans method on the session object before using the CreateDynaset method.

The updatability of the resultant dynaset depends on the Oracle SQL rules of updatability, on the access you have been granted, and on the options flag. For the dynaset to be updatable, these conditions must be met:

  • A SQL statement must refer to a simple column list or to the entire column list (*).

  • The statement must not set the read-only flag of the options argument.

  • Oracle Database must permit ROWID references to the selected rows of the query.

Any SQL statement that does not meet these criteria is processed, but the results are not updatable and the Updatable property of the dynaset returns False. This method automatically moves to the first row of the created dynaset. You can use SQL bind variables in conjunction with the OraParameters collection.

The SnapShotID option causes a snapshot descriptor to be created for the SQLStmt object created. This property can later be obtained and used in creation of other SQLStmt or OraDynaset objects. Execution snapshots provide the ability to ensure that multiple commands executed in the context of multiple OraDatabase objects operate on the same consistent snapshot of the committed data in the database.

Examples

This example demonstrates CreateObject, OpenDatabase and CreateDynaset methods. Copy and paste this code into the definition section of a form. Then, press F5.

Sub Form_Load ()
 
 'Declare variables
 Dim OraSession As OraSession 
 Dim OraDatabase As OraDatabase 
 Dim OraDynaset As OraDynaset 
 
 'Create the OraSession Object.
 Set OraSession = CreateObject("OracleInProcServer.XOraSession")
 
 'Create the OraDatabase Object by opening a connection to Oracle.
 Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&)
 
 'Create the OraDynaset Object.
 Set OraDynaset = OraDatabase.CreateDynaset("select empno, ename from emp", 0&)
 
 'Display the first record.
 MsgBox "Employee " & OraDynaset.Fields("empno").value & ", #" & _
                OraDynaset.Fields("ename").value
 
End Sub