# UOX3 Script Engine

### API and Event handling

### ODBC Related Methods

BeginTransaction
Prototype |
    bool BeginTransaction( void );
Purpose | Begins a new transaction. It should only occur for CUD (Create, Update, Delete) statements, and it is used to aggregate multiple statements into a single transaction that commits as one. It returns true if successful.
Example of Usage |
    var didStart = ODBC.BeginTransaction();

FinaliseTransaction
Prototype |
    bool FinaliseTransaction( bool commit );
Purpose | Commits (commit == true) or rolls back (commit == false) the queries in the transaction. Returns true if successful.
Example of Usage |
    var didStart = ODBC.BeginTransaction();
    if( didStart )
    {
    	var i = 0;
    	var anyProbs = false;
    	for( i = 0; i < 10 && !anyProbs; ++i )
    	{
    		var iSQL = "INSERT INTO Account( AccountID, Username, Password, ContactDetails, ";
    		iSQL += "IsBanned, IsSuspended, IsPublic, IsOnline, IsSeer, IsCounselor, IsGM, LastUpdated ) VALUES( ";
    		iSQl += " " + (10 + i) + ", 'tempguest" + (i+1) + "', 'tempguest" + (i+1) + "', '', 0, 0, 0, 0, 0, 0, 0";
    		iSQL += ", getdate() );";
    		ODBC.ExecuteQuery( iSQL );
    		if( !ODBC.lastOK )
    			anyProbs = true;
    	}
    	// If we have issues (anyProbs == true), we want to rollback (commit == false) and add NONE
    	ODBC.FinaliseTransaction( !anyProbs );
    }

ExecuteQuery
Prototype |
    int ExecuteQuery( string sql );
Purpose | Attempts to execute query that is specified in sql, and returns a statement index. If lastOK == false, the returned index is not trustable. This index MUST be stored if the query is a select, so that rows and columns can be fetched.
Example of Usage |
    var iResult = ODBC.ExecuteQuery( "SELECT Count(*) FROM Account;" );

QueryRelease
Prototype |
    bool QueryRelease( void );
Purpose | This releases the statement handle associated with your last query. DO NOT execute this from within a transaction, as it will force a rollback. Otherwise, you should call thiswhen you have finished with your query.
Example of Usage |
    ODBC.QueryRelease();

FetchRow
Prototype |
    bool FetchRow( int index );
Purpose | This method will fetch the next row in a resultset, associated with the statement handle you pass in, and retrieved on ExecuteQuery.
Example of Usage |
    ODBC.FetchRow( iResult );

GetColumn
Prototype |
    string GetColumn( int colNumber, int iResult );
Purpose | Returns the data from the row, at column colNumber from result set iResult. Note, columns MUST be fetched in ascending order starting from 0, and can only be retrieved once. Check lastOK if true, as the returned data is invalid if it is false.
Example of Usage |
    var colData = ODBC.GetColumn( 0, iResult );

LastOK
Prototype |
    bool LastOK( void );
Purpose | Method equivalent of lastOK. Only created for testing purposes, use the property instead.
Example of Usage |
    var isOK = ODBC.LastOK();

©Copyright 2000-2001 WWW.UOX3.NET (Daniel Stratton/Matthew Randall)