OScript API/Built-in Package Index |
The builtin-in functions in the SQL package perform connection and transaction operations, cursor allocation and management, and SQL statement operations with generic SQL databases.
The major functionalities offered by the SQL Package are the following:
Example:
// Retrieve values from DTree using a "fetching" cursor, and insert values into DTree // using a second "inserting" cursor. Integer status List colData string ok = undefined SqlCursor fetchCursor = undefined SqlCursor insertCursor = undefined Boolean done = FALSE SqlConnection sqlCnct = SQL.AllocFromConnect( $Connect ) // Start a transaction status = SQL.StartTransaction( sqlCnct ) //Declare the fetching cursor fetchCursor = SQL.Declare(\ sqlCnct,\ "Select OwnerID,DataID,DComment from " +\ "DTree " +\ "where " +\ "( DataType = 0 ) and ( SubType in (130,134) )" ) ok = $DBWizAPI.ConnectPkg.Check( fetchCursor, "Error Declaring FetchCursor] ) if IsDefined( ok ) fetchCursor = undefined end if IsUndefined( ok ) // Open the fetching cursor status = SQL.Open( fetchCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Opening Fetch Cursor" ) end if IsUndefined( ok ) // Prepare the fetching cursor status = SQL.Prepare( fetchCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Preparing Fetch Cursor" ) end if IsUndefined( ok ) // Execute the fetching cursor status = SQL.Execute( fetchCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Executing Fetch Cursor" ) end if IsUndefined( ok ) // Declare the insert cursor (note the value to be bound at a future point) insertCursor = SQL.Declare( sqlCnct, "Insert into DiscussionText values ( :A1, :A2, :A3 )" ) ok = $DBWizAPI.ConnectPkg.Check( insertCursor, "Error Declaring Insert Cursor" ) if IsDefined( ok ) insertCursor = undefined end end if IsUndefined( ok ) // Open the insert cursor status = SQL.Open( insertCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Opening Insert Cursor" ) end if IsUndefined( ok ) // Prepare the insert cursor status = SQL.Prepare( insertCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Preparing Insert Cursor" ) end while ok && !done // Fetch results using the fetch cursor status = SQL.Fetch( fetchCursor ) if IsError( status ) done = TRUE else // Retrieve column data from the fetching cursor colData = SQL.Cols( fetchCursor ) if IsDefined( coldata[ 3 ] ) // Bind the values retrieved by the fetching cursor into the // inserting cursor status = SQL.Bind( insertCursor, colData ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Binding Values"] ) if IsUndefined( ok ) // Execute the inserting cursor (whose statement has been bound with values from the // fetching cursor status = SQL.Execute( insertCursor ) ok = $DBWizAPI.ConnectPkg.Check( status, "Error Executing Insert Cursor" ) end end end end // Close the cursors if IsDefined( fetchCursor ) SQL.Close( fetchCursor ) end if IsDefined( insertCursor ) SQL.Close( insertCursor ) end // End the transaction status = SQL.EndTransaction( sqlCnct, !IsDefined( ok ) )
A commit flag for ODBC.
Cache the cursor.
Commit a transaction.
Expect hundreds of rows result from the select.
Expect tens of rows result from the select.
Expect on the order of a single result from the select.
Maximum number of IN clause for a sql statement.
The maximum value of BIGINT.
The maximum value for DataID.
The maximum value of INT ( or INTEGER).
The maximum value of SMALLINT.
The maximum value of TINYINT.
The minimum value of BIGINT.
The minimum value for DataID.
The minimum value of INT ( or INTEGER).
The minimum value of SMALLINT.
The minimum value of TINYINT.
Don't cache the cursor.
Statement shouldn't be logged.
Turn off warnings if statement is not in the context of a transaction.
An error returned by SQL.Fetch() to indicate completion and/or passed to SQL.EndTransaction() to rollback a transaction.
Allocates a connection object.
Allocates a connection object from a CAPIConnect
Binds a list of values to an SqlCursor.
Closes an SqlCursor.
Returns the names of the columns referenced by a cursor.
Returns the data from the last SQL.Fetch() execution.
Connects an allocated connection object to the database.
Returns the database version.
Declares an SqlCursor.
Drops the database connection.
Ends a database transaction, allowing commitment or rollback.
Executes an SQL statement.
Executes an SQL statement multipled times for a RecArray of parameterized values.
Executes an SqlCursor.
Fetches a row of data specified by the cursor.
Returns an assoc containing SQL transaction statistics or an error.
Determines whether the cursor contains a select statement.
Determines the number of columns the SQL statement will return.
Returns the current date and time as defined by the database.
Opens an SqlCursor.
Prepares an SqlCursor.
Resets all timing data used for SQL transaction statistics.
Returns the number of rows affected by the execution of an SQL statement contained in an SqlCursor.
Starts a database transaction.
A commit flag for ODBC.
This attribute directs SQL.Declare() to cache the cursor, allowing for rows to be fetched from the database more efficiently.
Not used.
A constant passed to Sql.EndTransaction() indicating a transaction should be committed.
Expect hundreds of rows result from the select.
Expect tens of rows result from the select.
Expect on the order of a single result from the select.
Maximum number of IN clause for a sql statement.
The maximum value for DataID:223,372,036,854,775,807.
The maximum value of BIGINT:223,372,036,854,775,807.
The maximum value of INT:223,372,036,854,775,807.
The maximum value of SMALLINT:2,147,483,647.
The maximum value of SMALLINT:255.
The minimum value for DataID:-223,372,036,854,775,808.
The minimum value of BIGINT:-223,372,036,854,775,808.
The minimum value of INT:-223,372,036,854,775,808.
The minimum value of SMALLINT:-2,147,483,648.
The minimum value of SMALLINT:0.
Not used.
Directs SQL.Declare() to not cache the cursor.
Directs SQL.Declare() to turn off statement logging within the cursor.
Directs SQL.Declare() to turn off warnings if the cursor is being used outside the context of a transaction.
An error passed to Sql.EndTransaction() indicating a transaction should be rolled back. SQL.Fetch() also returns SQL.ROLLBACK to indicated no further data can be fetched.
Not used.
Allocates an SqlConnection object. This data structure is used to hold information about the database connection.
An Integer specifying the connection type. CAPI.CT_ORACLE indicates Oracle and CAPI.CT_MSDBLIB indicates MSSQL Server.
A CAPILog object for logging transactions.
A CAPIErr object for logging errors.
This parameter must be zero.
An allocated SqlConnection, otherwise an error.
Remember that Alloc() merely allocates the connection, and that Connect() must be called afterwards to actually connect to the database.
Allocates an SqlConnection object from a CAPICONNECT. This SqlConnection is used to hold information about the database connection and is required for most SQL functions in this package.
A CAPIConnect, used to allocate an SqlConnection.
An allocated SqlConnection, or an error.
Binds a list of Strings, Integers, and/or Dates to parameters in the SQL statement contained in the cursor. This function must be called before the execution and fetching of the cursor, but after SQL.Prepare() is called. If there are no parameters in the SQL statement, pass an empty list.
The SqlCursor to be bound.
A list of values to bind to the parameters in the SQL statement within the cursor, or an empty list. These values can be Strings, Integers, or Dates.
0 if successful, Error otherwise.
Closes the specified SqlCursor after processing is complete.
The SqlCursor to be closed.
0 if successful, Error otherwise.
Returns a List of column names referenced by the SQL statement within the cursor.
The SqlCursor from which column information will be extracted.
A List of column names referenced by the SQL statement within the cursor.
Returns a List of the data from the last cursor fetch.
An SqlCursor.
A List containing the data from the last fetch of the cursor. The list contains one element for each row of data, and the values can be Strings, Integers, and/or Dates.
Connects an allocated SqlConnection to the database.
The SqlConnection to be connected.
The String name of the server to which the connection is made.
The String name of the database to which the connection is made. For an Oracle databases, a NULL string must be used.
The String name of the person user being connected.
The password of the user being connected.
0 if successful, Error otherwise.
Returns the version of the database serer being connected.
A valid SqlConnection or CAPIConnect object.
The database version; Error otherwise.
Declares an SqlCursor for later use. The statement may contain parameters for binding in the form of ":A1", ":A2", etc. Repeated values must be expressed as separate parameters, so that ":A1" cannot be reused later in the SQL statement even if the bound value is identical in both instances.
An SqlConnection.
An SQL statement.
Flag(s) to indicate how the statement and cursor will be handled. SQL.CACHE, SQL.NOCACHE, SQL.NOLOG, and SQL.NOTRANSWARN are all valid flags (See Attributes section above for more information on these flags) .
The declared cursor if successful, Error otherwise.
Drops or disconnects a database connection.
An SqlConnection to be dropped.
0 if successful, Error otherwise.
Ends a database transaction, allowing commitment or rollback of the transaction. See also SQL.EndTransaction().
An SqlConnection.
A value indicating a commitment or a rollback of the transaction. SQL.COMMIT and SQL.ROLLBACK are commonly passed. If the value is of type Error, rollback will occur.
0 if successful, Error otherwise.
Executes an SQL statement.
An SqlConnection.
An SQL statement. Parameterized values can be included in this statement, with the parameter syntax consisting of a colon followed by alphanumeric characters (":A1", ":A2", etc.). Up to 30 parameters can be passed.
the values of the optional parameters
included in the SQL statement. Either all the parameters can be
passed in a List for this argument, or they may be passed
as arguments, since this is a variable-argument function (like
Str.Format()).
Each sub<n> parameter specifies
a value to be substituted in the SQL statement for the respective
parameter. Values are substituted from left to right, regardless of
variable name or parameter characters.
For SELECT statements: A RecArray containing the data from the executed SQL statement is returned. For INSERT, UPDATE, or DELETE statements: An Integer indicating the number of rows affected by the executed statement is returned. If the execution of the SQL statement fails, Error is returned.
If a parameterized statement is executed multiple times for various data, ExecN() should be used instead since it is optimized for such cases.
Executes a parameterized SQL statement multiple times; once for each row in parms, a RecArray of parameter values. ExecN() may be optimized in some databases to perform better than calling Exec() for each iteration.
An SqlConnection.
An SQL statement. Parameterized values can be included in this statement, with the parameter syntax consisting of a colon followed by alphanumeric characters (":A1", ":A2", etc.). Up to 30 parameters can be passed.
A RecArray of parameters. The parameterized SQL statement is executed using parameters from each row in the RecArray, in left-to-right column order in a given row.
For SELECT statements: A RecArray containing the data from the executed SQL statement is returned. For INSERT, UPDATE, or DELETE statements: An Integer indicating the number of rows affected by the executed statement is returned. If the execution of the SQL statement fails, Error is returned.
Executes an SqlCursor. This function differs from SQL.Fetch() in that it is performed once, after the declaration, preparation, and binding of the cursor. All the data that will be obtained from the database by the SQL statement contained in the cursor is retrieved during SQL.Execute(). See also SQL.Prepare(), SQL.Bind(), and SQL.Fetch().
An SqlCursor to execute.
0 if successful, Error otherwise.
Fetches a row of data based on the specified SqlCursor. After an SQL.Execute() has been performed on a cursor, SQL.Fetch() is used to retrieve the data incrementally. In the case of a cached cursor, rows of data are retrieved in blocks for greater efficiency. See also SQL.Prepare(), SQL.Bind(), and SQL.Execute().
An SqlCursor upon which the fetch is to be performed.
0 if successful, Error otherwise. When the SQL.ROLLBACK is returned, the fetch is complete.
Returns an assoc containing SQL transaction statistics or an error. If a prefixString is defined then the assoc keys will have the prefix string prepended.
The string preappended to the Assoc keys.
An assoc containing SQL transaction statistics or an error. If returned, the assoc has the following structure:
Total_SQL_Time_Logged | Integer |
Total_SQL_Time | Integer |
Total_Fetch_Time | Integer |
Total_Execute_Time | Integer |
Number_of_Select_Statements | |
Number_of_Update_Statements | Integer |
Number_of_Insert_Statements | Integer |
Number_of_Delete_Statements | Integer |
Number_of_Other_Statements | Integer |
Total_SQL_Statements | Integer |
Number_of_Rows_Fetched | Integer |
Indicates whether the SQL statement within an SqlCursor is a SELECT statement. The SQL statement must have been parsed with SQL.Prepare() before this method is called.
The SqlCursor in question.
TRUE if the statement is a SELECT, FALSE otherwise.
Determines the number of columns that the SQL statement in the cursor will return.
The SqlCursor in question.
An Integer specifying the number of columns that the SQL statement will return.
Returns the current date and time as defined by the database server.
An SqlConnection.
The current date and time as defined by the database server.
Opens the SqlCursor after it has been declared.
The SqlCursor to be opened.
0 if successful, Error otherwise.
Triggers the server to parse the SQL statement within the cursor. The SqlCursor must be parsed before most other methods can be performed with it.
The SqlCursor to be parsed/prepared.
0 if successful, Error otherwise.
Resets all timing data used for SQL transaction statistics.
0(zero) if successful; Error otherwise.
Determines the number of rows affected by the execution of an SQL statement defined within an SqlCursor. SQL.Prepare() must have been called before this method can be used.
The SqlCursor whose affected rows are to be counted.
An Integer specifying the number of rows affected by the SQL statement.
Starts a database transaction, allowing multiple SQL statements to be grouped together. Should an error occur during the execution of any statement after the beginning of the transaction and before the SQL.EndTransaction(), all of the intervening statements can be rolled back or canceled.
An SqlConnection.
0 if successful, Error otherwise.
Copyright © 2023 OpenText Corporation. All rights reserved. |