#define OTL_ORA10G_R2
// this next line is not necessary here,
// but it's useful for std::string and some iterators
#define OTL_STL
#include <iostream>
#include <otlv4.h>

using namespace std;

int main( int argc, char *argv[] ) {
    int         buffer_size;
    int         count = 0;
    int         i = 1;
    otl_connect db;
    otl_stream  sql;
    otl_stream  sql_count;

    cout << "Starting...\n" << flush;
    if( argc > 1 && (buffer_size = atoi(argv[1]) ) ) {
        cout << "Good number passed in\n" << flush;
    }
    else {
        cout << "Usage " << argv[0] << " <number>\n" << flush;
        return 0;
    }
    try {
        db.rlogon( "username/password" );
        // or db.rlogon( "username/password@tnsname" );
        db << "truncate table temp_table";
        cout << "Opening sql..." << flush;
        sql_count.open( buffer_size,
                        "select count(1):#1<int> from temp_table",
                        db );
        sql.open( buffer_size,
                  "insert into temp_table (data) values (:data<int>)",
                  db );
        cout << "Done!\n" << flush;
        while( count<1001 ) {
            sql << i;
            sql_count.rewind();
            sql_count >> count;
            cout << i << '\t' << count << endl;
            if( i == buffer_size ) {
                i = 1;
            }
            else {
                ++i;
            }
        }
    }
    catch( otl_exception e ) {
        cout << "Program failed\n" << flush;
        cout << e.msg << flush;
        cout << e.stm_text << flush;
    }
    catch(...) {
        cout << "Program failed\n" << flush;
    }

    sql.close();
    db.commit();

    return 0;
}
