int main() { otl_connect::otl_initialize(); // initialize ODBC environment try{ db.rlogon("scott/tigger@sybsql"); // connect to ODBC db.auto_commit_on(); otl_cursor::direct_exec(db,"drop procedure my_proc",0); otl_cursor::direct_exec (db, "CREATE PROCEDURE my_proc " " @A int out, " " @B varchar(60) out, " " @C varchar(60) " "AS " "BEGIN " " SELECT @A=@A+1" " SELECT @B=@C " "END" ); // create stored procedure stored_proc(); // invoking stored procedure } catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.code<<endl; // print out error code cerr<<p.var_info<<endl; // print out the variable that caused the error cerr<<p.sqlstate<<endl; // print out SQLSTATE message cerr<<p.stm_text<<endl; // print out SQL that caused the error } db.logoff(); // disconnect from the data source return 0; }
void select3() { otl_stream s; s.set_all_column_types(otl_all_num2str|otl_all_date2str); // map all numeric and date/time output columns to strings for simplicity. db.auto_commit_on(); // setting database connect auto-commit to ON db.get_connect_struct().get_henv(); s.open(100, // buffer size "$SQLColumns $1:'t1'", // get a list of all columns of table // "test_tab" that belongs to schema "dbo", // catalog "sybsql" db // connect object ); otl_column_desc* desc; int desc_len; desc=s.describe_select(desc_len); // describe the structure of the output columns of the result set. for(int col_num=0;col_num<desc_len;++col_num){ cout<<desc[col_num].name<<desc[col_num].dbtype<<"=NULL "; } int rpc=0; while(!s.eof()){ ++rpc; char str[512]; cout<<"ROW#"<<rpc<<" "; for(int col_num=0;col_num<desc_len;++col_num){ s>>str; if(s.is_null()) cout<<desc[col_num].name<<"=NULL "; else cout<<desc[col_num].name<<"="<<str<<" "; } cout<<endl; } }