AMT Help Files

Database Interface

The Database object is returned by the CreateDatabase function that is provided through the ComScript connection interface. Through this object, the functionality of the Database interface can be used in programs that are written in any COM supporting development environment.

The queries are executed through the normal application connection to the database server and will therefore by default be executed against the application database.

The following functionality is provided:

Properties

Name
Type
Access
Description
ErrorCode Integer Readonly

Return the error code of the last database operation.

Note: nonzero when an error occurred.

ErrorDescription String Readonly Description of the error when the database operation failed.

Functions

Function Name

Return
Type

Parameters Description
Name Type
Commit Void ---   Commits the changes of the current transaction to the database.
ExecuteQuery Void SqlQuery String Executes the query provided in the parameter SqlQuery.
FillDataTable Integer DataTable System.Data.DataTable

Fills the database table provided in the parameter DataTable with the data from the text stream object provided in the parameter TextStream.

Returns the number of records added to the table.

LineLength: the line length used in the file (excluding CR/LF).

BatchSize: the total number of lines to be read.

BiteSize: the number of lines to be read in a single Read statement.

SubstringArguments: the collection of substring arguments to use when taking data from the line in a two dimensional array.

TextStream FileTextStream
LineLength Integer
BatchSize Integer
BiteSize Integer
SubstringArguments Integer array
   
GetBulkCopy AmtBulkCopy
Object
---   Returns an object of type AmtBulkCopy.
GetColumnDefinitions Void DataTable System.Data.DataTable Fills the data table provided in the parameter DataTable with the column definitions of the table provided in the parameter TableName.
TableName String
   
OpenQuery System.Database.DataTable SqlQuery String Opens a SELECT query and returns a DataTable object containing the result set.
RdmsLockTable Void TableName String Locks the table provided in the parameter TableName.
RdmsUnloadQuery Integer FileTextStream FileTextStream

Executes the query provide in the parameter SqlQuery and save the result set to the file provided in the parameter FileTextStream.

Returns the number of records unloaded.

When the parameter ForInternal is set to True the internal format is used for saving, otherwise the external format.

When the parameter WithDescription is set to True a description will be written in the file.
SqlQuery String
ForInternal Boolean
WithDescription Boolean
   
RdmsUnlockTable Void TableName String Unlocks the table provided in the parameter TableName.
Rollback Void ---   Rolls all the changes of the current transaction back.
StartTransaction Void ---   Starts a new Transaction.

Example


PowerShell


#See ComScript Connection Interface
... 
$ComScr.Connect()

#Create an object of the Database Interface to be able to start a transaction

$Database = $ComScr.CreateDatabase()


#Start a transaction and commit

$Database.StartTransaction()

$Database.ExecuteQuery("UPDATE AMTSYSSESSIONDATA SET PREVFORM='DEFAULT3' WHERE STATION='RSTEFFENS';")

$Database.Commit()


#Check if an error occurred and log if so.

if ($Database.ErrorCode -ne 0) {

    [void]$Msg.AddMsgInformation("ErrorCode is: $($Database.ErrorCode)")

    [void]$Msg.AddMsgInformation("ErrorDescription is: $($Database.ErrorDescription)")

} else {

    [void]$Msg.AddMsgInformation("Report succeeded.")

}


# Finally release the variables and clean up the session.
$ComScr.Dispose()