Background documentationsql Method (Loader Class) Locate this document in the navigation structure

 

sql is a method of the Loader class (loader module). You use this method to send an SQL statement $cmd_string to the Loader server.

You can also use the methods cmd (Loader class) or rawCmd (Loader class) to execute SQL statements. However, if exceptions are raised when you do this, you must recognize them yourself, and find the error code in the text of the exception.

Syntax Syntax

  1. $sqlrc = $session->sql ($cmd_string);
End of the code.

More information: Loader, Loader Commands and SQL Statements

Result

If the statement is executed successfully, the result value is 0.

If executing the statement causes an SQL error, the number of the error message for the SQL statement is returned.

If the execution of the statement causes a Loader error, an exception of the LoaderError class (Loader module) is raised.

Example

You execute a valid SQL statement.

print $session->cmd ('CREATE TABLE testtable3 (a integer)');

Output:

0

You execute an invalid SQL statement.

print $session->cmd ('invalid command');

Output (error code of the SQL statement):

3005

Execute an invalid Loader command.

print $session->cmd ('dataload invalid spec')

Output (Exception of the Loader Server):

Error Loader Server: Syntax error at position 10 (Unexpected token: invalid). at /opt/sdb/programs/misc/SAP/DBTech/loader.pm line 89.