Lalit Bhasin
2013-06-11 07:57:08 UTC
Hi Guys,
Here is my test code to simulate the problem:
*****************
#include <soci/oracle/soci-oracle.h>
#include<soci/soci.h>
#include<iostream>
main()
{
soci::session sql( soci::oracle, "service=XE user=scott password=tiger" );
soci::rowset<soci::row> rs = (
sql.prepare << "select data_length+0, data_length from "
<< " user_tab_cols where table_name = 'TABLE2' ");
soci::rowset<soci::row>::const_iterator it = rs.begin();
soci::row const & row = *it;
std::cout << "DATA_LENGTH + 0 = " << row.get<int>(0) <<std::endl; // no error here as expected
std::cout << "DATA_LENGTH = " << row.get<int>(1) <<std::endl; // this gives bad_cast error. Why ??
}
*************************
Now when running this executable:
sqlplus> create table table2 ( a number);
sqlplus> exit
[ubuntu_host]$ ./a.out
DATA_LENGTH + 0 = 22
terminate called after throwing an instance of 'std::bad_cast'
what(): St8bad_cast
Aborted
[ubuntu_host]$
Any idea why I am getting bad_cast error on accessing data_length column from user_tab_cols view, even though the column is of type number ? The only way to access this column is using data_length+0 in select query.
Thanks,
Lalit
Here is my test code to simulate the problem:
*****************
#include <soci/oracle/soci-oracle.h>
#include<soci/soci.h>
#include<iostream>
main()
{
soci::session sql( soci::oracle, "service=XE user=scott password=tiger" );
soci::rowset<soci::row> rs = (
sql.prepare << "select data_length+0, data_length from "
<< " user_tab_cols where table_name = 'TABLE2' ");
soci::rowset<soci::row>::const_iterator it = rs.begin();
soci::row const & row = *it;
std::cout << "DATA_LENGTH + 0 = " << row.get<int>(0) <<std::endl; // no error here as expected
std::cout << "DATA_LENGTH = " << row.get<int>(1) <<std::endl; // this gives bad_cast error. Why ??
}
*************************
Now when running this executable:
sqlplus> create table table2 ( a number);
sqlplus> exit
[ubuntu_host]$ ./a.out
DATA_LENGTH + 0 = 22
terminate called after throwing an instance of 'std::bad_cast'
what(): St8bad_cast
Aborted
[ubuntu_host]$
Any idea why I am getting bad_cast error on accessing data_length column from user_tab_cols view, even though the column is of type number ? The only way to access this column is using data_length+0 in select query.
Thanks,
Lalit