// 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