# OTL 4.0, Constant SQL statements

# Constant SQL statements

A SQL statement / PL/SQL block / stored procedure call is considered to be constant if it does not have any bind variables. OTL 4.0 has a static (in class) function to execute constant statements.

Examples (Oracle)

      otl_cursor::direct_exec
       (db, // connect object
        "create table test_tab(f1 number, f2 varchar2(30))"
        );  // create table

      otl_cursor::direct_exec
       (db, // connect object
        "drop table test_tab", // SQL statement or PL/SQL block
        otl_exception::disabled // disable OTL exceptions,
                                // in other words, ignore any
                                // database error
       ); // drop table

Examples (ODBC, DB2-CLI)

      otl_cursor::direct_exec
       (db, // connect object
        "create table test_tab(f1 numeric, f2 varchar(30))"
        );  // create table

      otl_cursor::direct_exec
       (db, // connect object
        "drop table test_tab", // SQL statement or stored procedure call
        otl_exception::disabled // disable OTL exceptions,
                                // in other words, ignore any
                                // database error
       ); // drop table

otl_cursor is one of the OTL 4.0 internal classes. It is not recommended to use the OTL 4.0 low level classes and functions except for the direct_exec() because it is a special case and it will not be discontinued in the future releases of the OTL.

The direct_exec() function may return the following values of the long int datatype:

- -1, if otl_exceptions are disabled (the second parameter is set to otl_exception::disabled) and the underlying API returns an error.
- >=0, if the SQL command to be executed is finished succesfully. Actually, the function returns the ROWS PROCESSED COUNT (RPC)in case of INSERT, UPDATE or DELETE statements.

Here is an example of the direct_exec(), returning a row processed count:

      long rpc=otl_cursor::direct_exec
                (db, // connect object
                 "delete from test_tab where f1>=95"
                );

      cout<<"Rows deleted: "<<rpc<<endl;

Prev Next Contents Go Home

Copyright © 1996, 2007, Sergei Kuchin, email: skuchin@ispwest.com, skuchin@gmail.com.

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies.