コード例 #1
0
ファイル: ex589_odbc.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize ODBC environment
 try{

  db.rlogon("scott/tiger@edbsql"); // connect to EDB

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

  otl_cursor::direct_exec
   (
    db,
    "create table test_tab(f1 number, f2 long raw)"
    );  // create table

  insert(); // insert records into table
  select(); // select records from table

 }

 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.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from EDB

 return 0;

}
コード例 #2
0
ファイル: ex301_odbc.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize ODBC environment
 try{

  db.rlogon("scott/tiger@msaccess");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  insert(); // insert records into table

 }

 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 message
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from ODBC

 return 0;

}
コード例 #3
0
ファイル: ex227_odbc.cpp プロジェクト: HJolin1986/otl
int main()
{
 otl_connect::otl_initialize(); // initialize ODBC environment
 try{

  db.rlogon("scott/tiger@mysql35"); // connect to ODBC

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab2",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

  otl_cursor::direct_exec
   (
    db,
    "create table test_tab2(f1 int, f2 datetime, f3 date) type=innoDB"
    );  // create table
  insert(); // insert records into table
  select(); // select records from table

 }

 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 message
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from ODBC

 return 0;

}
コード例 #4
0
ファイル: ex744_db2.cpp プロジェクト: GerHobbelt/otl
int main()
{
    otl_connect::otl_initialize(); // initialize database API environment
    try {

        db.rlogon("scott/tiger@db2sql"); // connect to the database

        otl_cursor::direct_exec
        (
            db,
            "drop table test_tab",
            otl_exception::disabled // disable OTL exceptions
        ); // drop table

        otl_cursor::direct_exec
        (
            db,
            "create table test_tab(f1 DECIMAL(31), f2 varchar(30))"
        );  // create table

        insert();
        select();
        select2();
    }

    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.var_info<<endl; // print out the variable that caused the error
    }

    db.logoff(); // disconnect from the database

    return 0;

}
コード例 #5
0
ファイル: ex645_odbc.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize Informix CLI environment
 try{

  db.rlogon("informix/tigger@informixsql"); // connect to Informix

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  insert(); // insert records into table
  select(); // select records from table

 }

 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.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from Informix

 return 0;

}
コード例 #6
0
ファイル: ex573_odbc.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize ODBC environment
 try{

  db.rlogon("scott/tigger@freetds_sybsql"); // connect to ODBC
  db.auto_commit_off();

  select(); // query the system data dictionary via ODBC functions.

 }

 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 message
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from ODBC

 return 0;

}
コード例 #7
0
ファイル: ex362_odbc.cpp プロジェクト: HJolin1986/otl
int main()
{
 otl_connect::otl_initialize(); // initialize the database API environment
 try{

  db.rlogon("scott/tiger@postgresql2"); // connect to the database

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table
   db.commit();
  otl_cursor::direct_exec
   (
    db,
    "create table test_tab(f1 int, f2 varchar(4))"
    );  // create table
   db.commit();
  insert(); // insert records into table
  select(); // select records from table

 }

 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.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from the database

 return 0;

}
コード例 #8
0
ファイル: ex688_odbc.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize the environment
 try{

  db.rlogon("scott/tiger@mssql2008",1); 
   // connect to the database in the "auto-commit" mode
   // in order to avoid generating transactions.

  otl_nocommit_stream stm; 
   // the OTL "nocommit" stream doesn't generate any COMMITs,
   // which is needed for the BACKUP command.

  short int rec_ndx=1; // diagnostic record index
  SQLCHAR sql_state[1000]; // "SQL state" buffer
  SQLCHAR msg[SQL_MAX_MESSAGE_LENGTH+1]; // diagnostic record / message buffer
  int native_error; // native error code
  SQLRETURN ret; // return value (for SQLMoreResults() calls)

  const char* cmd = "BACKUP DATABASE master TO DISK='d:\\master.bak'";

  stm.open(1,cmd,db);
    // the stream recognizes the command as an "SQL statement 
    // with diagnostic record output" with the help of 
    // the sql_statement_with_diag_rec_output() function.
    // the stream executes the statement right away with an
    // SQLExecDirect() function call, which, in the case
    // of a BACKUP statement returns right away.

  bool done;
  // get all diagnostic records from the BACKUP command
  do{
    done=stm.get_next_diag_rec
           (rec_ndx,
            sql_state,
            msg,
            sizeof(msg),
            native_error);
    cout<<msg<<endl;
    // BACKUP command generates multiple results,
    // so we need to check if there are more results
    ret=SQLMoreResults(stm.get_stm_handle());
    if(ret==SQL_SUCCESS_WITH_INFO){
       done=false;
       rec_ndx=1; // in order to start a new diagnostic record
                  // sequence, the record index needs to be set
                  // to 1.
    }
  }while(!done);
  stm.close();

 }

 catch(otl_exception& p){ // intercept OTL exceptions
  cerr<<p.msg<<endl; // print out error message
  cerr<<p.sqlstate<<endl; // print out SQLSTATE 
  cerr<<p.stm_text<<endl; // print out SQL that caused the error
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from the database

 return 0;

}
コード例 #9
0
ファイル: ex150_oci8.cpp プロジェクト: HJolin1986/otl
int main()
{
 otl_connect::otl_initialize(); // initialize OCI environment
 try{

  db.rlogon("scott/tiger"); // connect to Oracle

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  // create a PL/SQL package
  otl_cursor::direct_exec
   (db,
    "CREATE OR REPLACE PACKAGE my_pkg IS "
    " "
    "  TYPE my_cursor IS REF CURSOR; "
    "  TYPE my_tab IS TABLE OF VARCHAR2(100) "
    "                 INDEX BY BINARY_INTEGER; "
    " "
    "  PROCEDURE my_proc "
    "    (f1_in IN NUMBER, "
    "     f2_in IN NUMBER, "
    "     str1 OUT my_tab, "
    "     cur1 OUT my_cursor, "
    "     cur2 OUT my_cursor); "
    " "
    "END; "
   );

  otl_cursor::direct_exec
   (db,
    "CREATE OR REPLACE PACKAGE BODY my_pkg IS "
    " "
    "  PROCEDURE my_proc "
    "    (f1_in IN NUMBER, "
    "     f2_in IN NUMBER, "
    "     str1 OUT my_tab, "
    "     cur1 OUT my_cursor, "
    "     cur2 OUT my_cursor) "
    "  IS "
    "    lv_cur1 my_cursor; "
    "    lv_cur2 my_cursor; "
    "  BEGIN "
    "    FOR i IN 1..4 LOOP "
    "      str1(i) := 'Line'||i; "
    "    END LOOP; "
    "    str1(5) := NULL; "
    "    OPEN lv_cur1 FOR "
    "      SELECT * FROM test_tab "
    "      WHERE f1>=f1_in  "
    "        AND f1<=f1_in*2; "
    "    OPEN lv_cur2 FOR "
    "      SELECT * FROM test_tab "
    "      WHERE f1>=f2_in  "
    "        AND f1<=f2_in*2; "
    "    cur1 := lv_cur1; "
    "    cur2 := lv_cur2; "
    "  END; "
    "   "
    "END; "
   );

  insert(); // insert records into table
  select(); // select records from table

 }

 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.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from Oracle

 return 0;

}
コード例 #10
0
ファイル: ex675_odbc.cpp プロジェクト: lunar2296/DBTest
int main()
{
 otl_connect::otl_initialize(); // initialize ODBC environment
 try{

// ===================== Sybase via ODBC ======================================

  db.set_connection_mode(OTL_DEFAULT_ODBC_CONNECT);
  db.rlogon("scott/tigger@sybsql");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"============== Sybase via ODBC ====================="<<endl;
  insert(10); // insert records into the table
  update(10,10); // update records in the table
  select(8,10); // select records from the table
  cout<<"===================================================="<<endl;

  db.logoff(); // disconnect from ODBC

// ===================== TimesTen via ODBC ======================================

  db.set_connection_mode(OTL_TIMESTEN_ODBC_CONNECT);
  db.rlogon("scott/tiger@TT_tt1121_32");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"============== TimesTen via TimesTen ODBC driver ==================="<<endl;
  insert(10); // insert records into the table
  update(10,10); // update records in the table
  select(8,1); // select records from the table, 
               // stream buffer size should be set to 1 
               // when connected to TimesTen via TimesTen ODBC driver
  cout<<"===================================================================="<<endl;

  db.logoff(); // disconnect from ODBC


// ===================== MS SQL 2008 via ODBC ==============================

  db.set_connection_mode(OTL_MSSQL_2008_ODBC_CONNECT);
  db.rlogon("scott/tiger@mssql2008");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"=========== MS SQL 2008 via ODBC ==================="<<endl;
  insert(10); // insert records into the table
  update(10,10); // update records in the table
  select(8,10); // select records from the table
  cout<<"===================================================="<<endl;

  db.logoff(); // disconnect from ODBC

// ===================== PostgreSQL via ODBC ==============================

  db.set_connection_mode(OTL_POSTGRESQL_ODBC_CONNECT);
  db.rlogon("scott/tiger@postgresql");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"=========== PostgreSQL via ODBC ==================="<<endl;
  insert(10); // insert records into the table
  update(10,10); // update records in the table
  select(8,10); // select records from the table
  cout<<"===================================================="<<endl;

  db.logoff(); // disconnect from ODBC

// ===================== EntipriseDB via ODBC ==============================

  db.set_connection_mode(OTL_ENTERPRISE_DB_ODBC_CONNECT);
  db.rlogon("scott/tiger@edbsql");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"=========== Enterprise DB via ODBC ================="<<endl;
  insert(10); // insert records into the table
  update(10,10); // update records in the table
  select(8,10); // select records from the table
  cout<<"===================================================="<<endl;

  db.logoff(); // disconnect from ODBC

// ===================== MySQL via ODBC ==============================

  db.set_connection_mode(OTL_MYODBC35_ODBC_CONNECT);
  db.rlogon("scott/tiger@mysql35");

  otl_cursor::direct_exec
   (
    db,
    "drop table test_tab",
    otl_exception::disabled // disable OTL exceptions
   ); // drop table

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

  db.commit();

  cout<<"=========== MySQL via MyODBC 3.5 ==================="<<endl;
  insert(1); // insert records into the table, stream buffer size should be set to 1
  update(10,1); // update records in the table, stream buffer size should be set to 1
  select(8,10); // select records from the table
  cout<<"===================================================="<<endl;

  db.logoff(); // disconnect from ODBC

 }

 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 message
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from ODBC

 return 0;

}
コード例 #11
0
ファイル: ex313_oci7.cpp プロジェクト: 008fy/otl
int main()
{
 otl_connect::otl_initialize(); // initialize OCI environment
 try{

  db.rlogon("scott/tiger"); // connect to Oracle

  otl_cursor::direct_exec
   (db,
    "CREATE OR REPLACE PACKAGE pkg_test IS "
    "  TYPE my_numeric_table IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; "
    "  TYPE my_varchar_table IS TABLE OF VARCHAR2(31) INDEX BY BINARY_INTEGER; "
    "  TYPE my_char_table IS TABLE OF CHAR(31) INDEX BY BINARY_INTEGER; "
    " "
    "  PROCEDURE prc_test(v1 IN OUT my_numeric_table, "
    "                     v2 OUT my_varchar_table, "
    "                     v3 OUT my_char_table); "
    " "
    "END; "
  );

  otl_cursor::direct_exec
   (db,
    "CREATE OR REPLACE PACKAGE BODY pkg_test IS "
    " "
    "  PROCEDURE prc_test(v1 IN OUT my_numeric_table, "
    "                     v2 OUT my_varchar_table, "
    "                     v3 OUT my_char_table) "
    "  IS "
    "  BEGIN "
    "    FOR i IN 1..v1.last LOOP "
    "      v1(i) := v1(i)+100; "
    "    END LOOP; "
    "    v1(v1.last+1) := 0; "
    "    v2(1) := 'Hello'; "
    "    v2(2) := 'World'; "
    "    v2(3) := '!!!'; "
    "    v3(1) := 'Hello'; "
    "    v3(2) := 'World'; "
    "    v3(3) := '!!!'; "
    "  END; "
    "   "
    "END; "
  );


  plsql();

 }

 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.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from Oracle

 return 0;

}