Class: SqlExecutor

sqlExecutor~ SqlExecutor

SqlExecutor provides functions for a convenient execution of SQL statements

new SqlExecutor(connection)

Creates an SqlExecutor object for a given database connection.
Parameters:
Name Type Description
connection $.db.Connection database connection
Example
var SqlExecutor = $.import('sap.hana.testtools.unit.util', 'sqlExecutor').SqlExecutor;
var connection = $.db.getConnection();
var sqlExecutor = new SqlExecutor(connection);

Methods

callProcedure(sql)

Executes a call statement.
Parameters:
Name Type Description
sql String call statement that should be executed
Throws:
SQLException
Example
try {
    sqlExecutor.callProcedure('CALL "SCHEMA"."package.subpackage::procedure"(#InTable,#OutError) with overview');
} finally {
    connection.close();
}

execQuery(sql) → {module:tableDataSet~TableDataSet}

Executes a select statement and returns the results.
Parameters:
Name Type Description
sql String select statement that should be executed
Throws:
SQLException
Returns:
table data set that contains the results of the select statement
Type
module:tableDataSet~TableDataSet
Example
try {
    var actualTableDataSet = sqlExecutor.execQuery('select 1 from dummy');
} finally {
    connection.close();
}

execSingle(sql)

Executes a common statement.
Parameters:
Name Type Description
sql String common statement that should be executed
Throws:
SQLException
Example
//copies a table into a test schema
try {
    sqlExecutor.execSingle('create column table TEST.ORDERS like SAP_HANA_TEST_DEMO.ORDERS with no data');
} finally {
    connection.close();
}

execSingleIgnoreFailing(sql)

Executes a common statement and ignores any error during execution.
Parameters:
Name Type Description
sql String common statement that should be executed
Example
//tries to delete a test table if it exists
sqlExecutor.execSingleIgnoreFailing('drop table TEST.ORDERS');