Win32Forth


ADO -- ADO Classes for Database Interfacing


Tom Dixon - August 2006

These classes were developed to make accessing databases easy and convienent with win32forth.

 ADOConnection Class

:class ADOConnection               <SUPER Object

An ADO connection object controls the access of cursors to the database. It is meant to control things such as tranactions, read/write properties and error handling.

:M Start: ( -- )

Initializes the ADO Connection Component.  Most methods will not execute properly if this is not called when the object instance is created

:M Connect: ( -- )

Connects to the data source specified by the connection string with the given connection properties.

:M Close: ( -- flag )

Closes the database connection.  The COM component still exists and a new connection may be made if desired.

:M GetErrorCnt: ( -- cnt )

Return the number of errors in the FIFO error queue

:M GetError: ( cnt -- n )

Return the error number of the 'cnt' error in the error queue

:M Error>str: ( n -- str len )

Return the error string of the 'cnt' error in the error queue

:M ClearErrors: ( -- )

Clears the FIFO error queue

:M ERR: ( n -- ) \ thows an error on any problem

Displays and clears all errors in the queue

:M Transaction: ( -- )

Starts a transaction session for this connection.  All changes performed on the database will not take effect until they are committed. Some databases may not support this functionality.

:M Commit: ( -- )

Commit all changes in the current transaction to the database.

:M RollBack: ( -- )

Drop all changes in the current transaction - no changes are made for the transaction session.

:M GetTimeOut: ( -- n )

Returns the timeout time (in seconds) that queries will give up.

:M SetTimeOut: ( n -- )

Sets the timeout time (in seconds) that queries will give up.

:M GetConnString: ( -- str len )

Return the connection string for the data source.  This may not necessarily be the same string that was given to the object

:M SetConnString: ( str len -- )

Set the connection string for the data source.  The connection string tells the object what drivers to use, where the database is, user name, and password.

:M GetProvider: ( -- str len )

Returns the provider for the connection.

:M SetProvider: ( str len -- )

Sets the provider for the connection.  Can be set through the connection string as well.

:M GetMode: ( -- n )

Returns the connection mode.

:M SetMode: ( n -- )

Sets the connection mode.  The connection mode indicates whether the database is read-only, write-only, sharable, etc...
See the ConnectModeEnum constants below the class descriptions.

:M GetState: ( -- n )

Returns the current state of the connection object.

 ADOCursor Class

:class ADOCursor               <SUPER Object

An ADO cursor object represents a recordset of data, or data in a table-like structure.  Data can be loaded, updated, inserted through this object.

:M Start: ( -- )

Initializes the ADO Recordset Component.  Most methods will not execute properly if this is not called when the object instance is created

:M SetConnection: ( ADOConnection -- )

Sets the connection object for this cursor.  It is required before any query is executed.

:M GetCacheSize: ( -- n )

Returns the cache size of the cursor.  The value is the number of records in the cache before updates are required.

:M SetCacheSize: ( n -- )

Sets the cache size of the cursor.  The default is 1, or updates occur with every new record edited.

:M GetCursorType: ( -- ctype )

Returns the cursor type.

:M SetCursorType: ( ctype -- )

Sets the cursor type.  The cursor type determines what is allowed on the cursor data and how data is seen in a multi-client environment.  The possible values are:

adOpenUnspecified The cursor type is unspecified.  Usually defaults to adOpenForwardOnly
adOpenStatic All movement methods are available.  Changes from other users are not visible
adOpenForwardOnly The cursor can only move forward.  The record count and other navigation methods are invalid.  This should have the best performance of the cursors.
adOpenDynamic All additions, deletions and changes from other users are visible
adOpenKeyset Like a dynamic cursor, except added records can't be seen and deleted records are inaccessible
:M GetLockType: ( -- n )

Returns the lock type.

:M SetLockType: ( n -- )

Sets the lock type.  The lock type determines how the database is to handle changes to the data on a cursor.  The possible values are:

adLockUnspecified The lock type is unspecified.  Usually defaults to adLockReadOnly
adLockReadOnly The records are read-only. Data cannot be altered
adLockPessimistic Pessamistic locking.  Record(s) are locked at the data source immediately when the alterations begin.
adLockOptimistic Optimistic locking.  Record(s) are locked only when the update method is called
adLockBatchOptimistic Useful for batch updates.
:M GetMaxRows: ( -- n )

Returns the maximum number of records to be returned in a query.

:M SetMaxRows: ( n -- )

Sets the maximum number of records to be returned from a query (0 = unlimited)

:M Close: ( -- )

Closes the cursor.  Another query can be executed on the cursor once it has been closed.

:M GetState: ( -- n )

Returns the state of the cursor.  Useful when executing queries asyncronously.

:M Executing?: ( -- flag )

Returns true if the query is still executing.

:M Fetching?: ( -- flag )

Returns true if the rows are still being retrieved

:M Execute: ( str len -- )

Execute a SQL query on the cursor.  Any returned data will be in the cursor.

:M AsyncExecute: ( str len -- )

Operates the same as the execute method, but is asyncronous.  The cursor's state will indicate if the query has finished executing or not.

:M Requery: ( n -- )

Rerun the last query.

:M RecordCount: ( -- n )

Return the number of records in cursor.  May not work with the adOpenForwardOnly cursor type.

:M Move: ( n -- )

Move to the record number 'n' of the cursor's data

:M MoveFirst: ( -- )

Move to the first record of the cursor's data.

:M MoveNext: ( -- )

Move to the next record of the cursor's data

:M MovePrevious: ( -- )

Move to the previous record of the cursor's data

:M MoveLast: ( -- )

Move to the last record of the cursor's data

:M EOF: ( -- flag )

Flag that indicates if the current record position is after the last record.

:M BOF: ( -- flag )

Flag that indicates if the current record position is before the first record.

:M FieldCnt: ( -- n )

Returns the number of columns in the current record.

:M FieldType: ( field -- DataTypeEnum )

Returns the data type constant of the given column. Possible data types are:

adEmpty
adTinyInt
adSmallInt
adInteger
adBigInt
adUnsignedTinyInt
adUnsignedSmallInt
adUnsignedInt
adUnsignedBigInt
adSingle
adDouble
adCurrency
adDecimal
adNumeric
adBoolean
adError
adUserDefined
adVariant
adIDispatch
adIUnknown
adGUID
adDate
adDBDate
adDBTime
adDBTimeStamp
adBSTR
adChar
adVarChar
adLongVarChar
adWChar
adVarWChar
adLongVarWChar
adBinary
adVarBinary
adLongVarBinary
adChapter
adFileTime
adPropVariant
adVarNumeric
adArray
:M FieldName: ( field -- str len )

Returns the column name of the given column number.

:M FieldSize: ( field -- n )

Returns the data size of the given column number.

:M GetInt: ( field -- int )

Returns an integer value of the given column on the current row.

:M GetDouble: ( field -- d )

Returns the double of the given column on the current row.

:M GetFloat: ( field -- float )

Returns the floating point value of the given column on the current row.

:M GetStr: ( field -- str len )

Returns the string of the given column on the current row.  May be much longer than 255

:M GetTimeStamp: ( field -- float )

Return the timestamp value of the given column on the current row.  The timestamp value is a floating point number that indicates the number of days since Dec 31, 1899.

:M GetDateTime: ( field -- sec min hour day month year )

Returns the datetime values of the given column on the current row.

:M isNull?: ( field -- flag )

Returns true if the given field for the given flag is null

:M SetInt: ( int field -- )

Sets the integer value of a given column on the current row.

:M SetDouble: ( d field -- )

Sets the double value of a given column on the current row.

:M SetFloat: ( float field -- )

Sets the floating point number of a given column on the current row.

:M SetNull: ( field -- )

Sets the field value to null of a given column on the current row.

:M SetStr: ( str len field -- )

Sets the string value of a given column on the current row.

:M SetTimeStamp: ( float field -- )

Sets the timestamp value of the given column on the current row.  The timestamp value is a floating point number that indicates the number of days since Dec 31, 1899.

:M SetDateTime: ( sec min hour day month year field -- )

Sets the datetime values of the given column on the current row.

:M AddRow: ( -- )

Adds a new record to the end of the recordset and sets this as the current row.  The row is not actually created until the update method is called.

:M DeleteRow: ( -- )

Deletes the current record.

:M Update: ( -- )

Updates the alterations to the data.

:M SaveNative: ( str len -- )

Saves the cursor's data to a file that is in a unspecified format.

:M SaveXML: ( str len -- )

Saves the cursor's data as a XML file.

:M SaveADTG: ( str len -- )

Saves the cursor's data in the Microsoft Advanced Data TableGram (ADTG) format. Requires a filename.

:M SaveCSV: ( str len -- )

Saves the cursor's data to a comma separated value file for easy viewing. Cannot be loaded later through the loadfile method.

:M LoadFile: ( str len -- )

Loads a cursor data file that was saved previously.
A connection object is not required to load this data.


Document $Id: ADO.htm,v 1.3 2007/05/26 10:24:12 dbu_de Exp $