SQL::Connection Object
The SQL::Connection object is the heart of all database activity. Each instance of SQL::Connection represents a potential or active database session. In order to do anything with a SQL database you must first create (or dimension) a variable and associate it with a programming interface (API) and with a vendor syntax ( Oracle, Access, etc.).
Using the Connection Object
The following sample script creates a SQL::Connection object and opens a connection to a Microsoft Access database.
|
DIM c as SQL::Connection DIM cs as C cs = "{A5API='Access', A5Syntax='Access', FileName='C:\Program Files\a5v6\MDBFiles\Alphasports.mdb', UserName='Admin'}" ? c.Open(cs) = .T. |
The SQL::Connection object has the following properties.
|
Property |
Type |
Mode |
Description |
|
R |
Returns the results of the last call. | ||
|
ConnectionString |
C |
RW |
The current connection string in syntax format. Should be set by ::SetConnectString(). |
|
ConnectionTimeout |
C |
RW |
Timeout values are "Default", "Infinite", or a string containing an integer specifying the timeout in seconds. Must be set prior to opening the connection. |
|
CurrentAPI |
C |
R |
The name of the current application programming interface being used. For example: Access, Oracle, ODBC, MySQL. |
|
CurrentSyntax |
C |
R |
The dialect of SQL (and typically the vendor or product) being used to interact with the database. |
|
L |
R |
Returns true if the connection is currently open and false if it has not been opened yet or has been closed. | |
|
LoginTimeout |
C |
RW |
Timeout values are "Default", "Infinite", or a string containing an integer specifying the timeout in seconds. Must be set prior to opening the connection. |
|
L |
RW |
Default = FALSE (.F.). When this property is set to true, SQL statements passed to the ApplyData(), Execute(), ToOpenTable(), ToGridComponentDataObject(), ToOpenTable(), ToPropertyArray(), ToString(), ToXML(), and ValidateQuery() methods are checked to see if they are supported Portable SQL Statements and, if so, then translated to native syntax before being processed. Statements that are not supported are passed directly through to the underlying database driver as if PortableSQLEnabled were false. | |
|
QueryTimeout |
C |
RW |
Timeout values are "Default", "Infinite", or a string containing an integer specifying the timeout in seconds. Must be set prior to executing a query. |
|
ResultSet |
R |
Returns the currently active result set, or an error if there isn't one. | |
|
SchemaCacheEnabled |
L |
RW |
Default = TRUE (.T.). When this property is set to TRUE (.T.), schema objects retrieved (such as SQL::TableInfo) will be cached for the connection (disconnecting and some update functions clear the cache), when false, all objects are not cached and subsequent requests for a schema object will go directly to the database. |
The SQL::Connection object has the following functions. Create a SQL::Connection object with the ::Open() method.
|
Item |
Description |
|
Adds an additional event script (see SQL Events) to the connection. | |
|
Forces all objects held in the connections cache to be freed. | |
|
Closes a SQL connection. | |
|
Retrieves the API specific XDialog syntax for the dialog to prompt for a connection string. | |
|
Returns a syntax script implemented in some detail to show how to write a syntax handler. | |
|
Returns a the most appropriate syntax for the server specified or an empty string if not known. | |
|
Returns a collection of the tables requested for the current database and optionally for those owned by a specific user. | |
|
Returns a syntax script with all function prototypes for building a syntax handler. | |
|
Creates a CR-LF delimited list of installed SQL Application Programming Interfaces. | |
|
Returns a list of databases from the current server. | |
|
::ListAutoIncrement Implementations() |
Create a CR-LF delimited list of valid auto-increment implementations current syntax. |
|
Creates a CR-LF delimited list of portable functions. | |
|
Create a CR-LF delimited list of valid procedure languages for the current syntax. | |
|
Creates a list of property names and values in the format Name <TAB> Value <CR-LF>. | |
|
Returns a list of servers for the current connection Application Programming Interface (API). | |
|
Create a CR-LF delimited list of installed SQL syntaxes. | |
|
Returns a list of tables for the current database. | |
|
Returns a list of tables for the current database suffixed with (<type>). | |
|
Reformats a password so it will not be readable. | |
|
Connects to a database and sets a the values of a SQL::Connection object. | |
|
::RemoveEventScript() |
Removes an event script (see SQL Events ) from the connection. |
|
Sets the connection string with required parameters. The actual values will depend on how you are connecting to your database. |
|
Item |
Description |
|
| |
|
| |
|
| |
|
| |
|
| |
|
Generates a SQL Create Table statement. | |
|
Generates a SQL Delete statement. | |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
Generates a SQL Insert statement for a table. | |
|
Generates the SQL to retrieve the last identity value generated for an insert on the currently open connection. | |
|
Generates a list of key columns for a table based on the primary key. | |
|
Generate a SQL Select statement for a table. | |
|
::GenerateUpdateStatement() |
Generates a SQL Update statement for a table. |
|
::GenerateWhereClause() |
Generates a SQL Where Clause based on criteria. |
|
| |
|
::LastInsertedIdentity() |
Retrieves the last identity inserted for the current connection/table. |
|
::SetSyntaxHandlerScript() |
Assigns a handler script for the connection to override the default behavior of some or all of the event functions. |
|
Item |
Description |
|
Executes a query on the connection using SQL. | |
|
Fetches data to an XML formatted string using a SQL query. | |
|
Releases the result set from the last SQL select statement. | |
|
::LastInsertedIdentity() |
Retrieves the last identity value generated for an insert on the currently open connection. |
|
Creates a SQL::ResultSet object for a table. | |
|
Fetches data to an Alpha Five .DBF table using a SQL query. | |
|
Fetches data to a Grid Component Data Object using a SQL Query. | |
|
::ToJSON() |
Converts the data in one or more rows to an implementation of JavaScript Object Notation format specific to the Alpha Five AJAX implementation. |
|
Fetches rows from a SQL database to a local .DBF file. | |
|
Fetches data to a property array using a SQL query. | |
|
Fetches data to a string using a SQL query. | |
|
Validates a SQL query on the connection. |
|
Item |
Description |
|
Returns the number of affected rows. | |
|
Applies the query to existing rows in a table in the currently connected database using the result set provided. | |
|
::DeleteData() |
Deletes rows from a table in the currently connected database using a result set. |
|
Applies new rows to a table in the currently connected database using a result set. | |
|
Applies changes to existing rows. |
Transaction Management Methods
|
Item |
Description |
|
Begins a batch of SQL updates, inserts and/or deletes that need to succeed or fail as a group. | |
|
Applies a set of changes started with ::BeginTransaction(). | |
|
Undoes a set of changes started with ::BeginTransaction(), but not yet applied with ::CommitTransaction(). |
|
Item |
Description |
|
Creates a new database. | |
|
::CreateIndex() |
Creates an index on the specified table in the currently connected database using SQL::TableInfo and SQL::IndexColumnInfo objects. |
|
Creates a table in the currently connected database using a SQL::TableInfo object. | |
|
Removes a database. | |
|
Drops the index named from table specified in the currently connected database. | |
|
Drops the table named from the currently connected database. | |
|
Returns the definition of a table. | |
|
Returns the primary key expression for a table. |
|
Item |
Description |
|
Creates a new user in the currently connected database or server. | |
|
Makes the user a member of the group in the currently connected database or server. | |
|
Makes the user a member of the group in the currently connected database or server. | |
|
Removes a database. | |
|
Removes the user named from the currently connected database or server. | |
|
Removes the user from the group in the currently connected database or server. | |
|
Removes the user group named from the currently connected database or server. | |
|
::GenerateAddUserStatement() |
|
|
::GrantAccess() |
Grants specified access to a resource to a user or group. |
|
::RevokeAccess() |
Revokes the specified access to the resource from a user or group. |
|
Item |
Description |
|
Generates a formatted column name suitable for a SQL query using the current syntax. | |
|
Generates a formatted table name suitable for a SQL query using the current syntax. | |
|
Generates a SQL type string for a type using the current syntax. |
See Also
Supported By
Alpha Five Version 8 Enterprise Edition
Limitations
Desktop applications only.