views:

98

answers:

1

Here is the problem, I dont know how many attributes or which type are the attributes in table and I need simple select statment like: SELECT * FROM TABLE1; to write down to file.

And this need to be done with otlv4 wrapper.

Please help.

otl_stream i(50, // buffer size             
     "select * from test_tab where f1>=:f<int> and f1<=:f*2",                 // SELECT statement           
     db // connect object      
     );     
int ac=0;
     char bc[64];
     memset(bc, 0, 64);

     while(!i.eof())
     {

        i >> ac >> bc;
        cout << "Boooo " << ac << "  " << bc << endl;
     }

This is example where I know how many attributes are there and which type are there. But what if I dont know that??

A: 

A file stream along with OTL's check_end_of_row() and set_all_column_types() functions should do what you're asking. While looping on an OTL stream's eof check, for each row you could loop on the end of row check, and send each attribute's value from the OTL stream to the file stream. After each end of row check, send your line break code(s) to the file stream. Setting all column types to str should allow you to use just one variable to process all attribute values in a row.

This example from the OTL docs demonstrates how to use the set_all_column_types function. You must create a stream first, set the option, then open the stream. If you create and open the stream at the same time, it won't work.

pheadbaq