OTL

读数据

读数据必须使用is_null()来判断是否为空,当为空时进行赋值,变量初始化时的默认值在这里是无效的。

// otl_stream and NULLs
// @see <http://otl.sourceforge.net/otl4_ex283.htm>
 
  try{
    // Buffer size通常设置为50~2000,小数据设置50即可,大数据设置为2000
    otl_stream o(2000, sql_select_customers, db);
    while (!o.eof())
    {
      int custid = 0;
      string email = "", nickname = "";
      o >> custid;
      // 非常重要,这里必须使用o.is_null()来判断是否NULL,否则会出现上次Buffer中非NULL字段的值覆盖当前条目NULL值
      if (o.is_null()) { custid = 0; } 
      o >> email;
      if (o.is_null()) { email = ""; }
      o >> nickname;
      if (o.is_null()) { nickname = ""; }
      // Do Something
    }    
    db.logoff();
 
  }catch(otl_exception& p){ // intercept OTL exceptions
    cerr<<p.msg<<endl; // print out error message
    cerr<<p.stm_text<<endl; // print out SQL that caused the error
    cerr<<p.sqlstate<<endl; // print out SQLSTATE info.
    cerr<<p.var_info<<endl; // print out the variable that caused the error
//        db.rollback(); // roll back transaction 
  }

http://otl.sourceforge.net/otl4_ex283.htm

by default, OTL does not set the output buffer to any value in the case of NULL

http://otl.sourceforge.net/otl3_faq.htm

Panzhibiao 2012/01/12 11:44

c/otlnotice.txt · 最后更改: 2012/01/12 11:48 由 admin
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki