OTL 4.0,无量纲SQL指令(2010.4.24更新)

来源:互联网 发布:吉林省水利造价软件 编辑:程序博客网 时间:2024/05/04 07:48

 

 

原文地址:http://otl.sourceforge.net/otl3_const_sql.htm

 

无量纲SQL指令


一个SQL指令/PL/SQL/存储过程调用,如果没有绑定任何变量,则被认为是无量纲的。OTL4.0有一个用于执行无量纲指令的静态(在类中)函数。


示例

// static otl_cursor::direct_exec()

  otl_cursor::direct_exec
   (db, // connect object
    "create table test_tab(f1 int, f2 varchar(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

// or otl_connect::direct_exec()
  db.direct_exec // connect object  
("create table test_tab(f1 int, f2 varchar(30))"
   );  // create table
  db.direct_exec // 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

// or otl_connect::operator<<(const char*)
  db<<"create table test_tab(f1 number, f2 varchar2(30))";
try{
db<<"drop table test_tab""; // SQL statement or PL/SQL block
}catch(otl_exception&){
// ignore a database error
}

otl_cursorOTL4.0的一个内部类。除了direct_exec()这个特例,我们不推荐使用OTL4.0中低层次的类集和函数,因为在以后的版本将不会被支持。
函数direct_exec()可能会返回类型为long int的值:

·  -1,数据库API返回一个错误并且otl_exceptions异常被禁止(在第二个参数设置为otl_exception::disabled

·  >=0,在SQL命令成功执行后.事实上只有在执行INSERT, UPDATE或者DELETE指令后,才会返回ROWS PROCESSED COUNT(RPC)

下面是direct_exec()函数的一个例子,返回处理过的行数:

 

// static otl_cursor::direct_exec

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

// or otl_connect:direct_exec

  long rpc=db.direct_exec // connect object
            ("delete from test_tab where f1>=95"
            ); 
  cout<<"Rows deleted: "<<rpc<<endl;

 

 


 

原创粉丝点击