contents   index   previous   next



Database execute()

syntax:

database.execute(sqlstatement)

where:

sqlstatement - string representing the SQL statement to execute.

 

return:

number - 0 if the call was successful; otherwise, a nonzero status code based on the error message produced by the database. If the method returns a nonzero status code, use the majorErrorCode and majorErrorMessage methods to interpret the meaning of the error.

 

description:

This method allows execution of any data definition language (DDL) or data manipulation language (DML) SQL statement supported by the database server that does not return a cursor (such as CREATE, ALTER, or DROP). Each database supports a standard core of DDL and DML statements. In addition, a database may support DDL and DML statements specific to that database vendor. Use execute to call any of those statements. However, a database vendor may provide functions that are not DDL or DML statements. Do not use execute to call those functions. For example, do not call the Oracle describe function or the Informix load function from the execute method.

 

Although the execute method can be used to perform data modification (INSERT, UPDATE, or DELETE statements), it is recommended that Cursor objects be used instead to achieve the same functionality. Using the Cursor object for these sorts of actions allows better database-type independence and also allows the use of binary large object (BLOb) data.

 

When using the execute method, the SQL statement must strictly conform to the syntax requirements of the database server. For example, some servers require each SQL statement be terminated with a semicolon. See the server documentation for more information. If a transaction has not been started with beginTransaction, the single statement is automatically immediately committed when execute is called.

 

see:

#link <sedbc>, Database cursor(), Database beginTransaction(), Database commitTransaction(), Database rollbackTransaction()

 

example:

// This example deletes all records from the database

// whose ID is 'requestedID'. It is recommended,

// however, that the Cursor object be used

// to perform this action.

err = db.execute("delete from customer where customer.ID = " + requestedID );

 


Database majorErrorCode()