$sqlrc = $session->sql ($cmd_string);
sql is a method of the class Loader. You use this method to send the SQL statement specified under $cmd_string to the program Loader Server.
You can also use the methods cmd or rawCmd 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.
If the statement is executed successfully, the value of the result is 0.
If the execution of the statement causes an SQL error, the number of the error message of the SQL statement is returned.
If the execution of the statement causes a Loader error, an exception of the type LoaderError is raised.
Executing a valid SQL statement
print $session->cmd ('CREATE TABLE testtable3 (a integer)');
Output:
0
Executing an invalid SQL statement
print $session->cmd ('invalid command');
The output is the error code of the SQL statement:
3005
Executing an invalid Loader command
print $session->cmd ('dataload invalid spec')
The output is the 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.