Andrew Grafham
2014-01-27 17:13:29 UTC
Hi,
Is there a way of accurately bulk inserting into a decimal field in SQL
server? I'm trying to insert into a table called nets, which has 2 column,
an integer column (id) and a decimal(23,6) column (net). This is the code
I'm using:-
try
{
session sql("odbc", "DSN=socitest;Uid=sa;Pwd=XXXXX;");
vector<int> ids;
vector<string> nets;
for (int i = 0; i != 1000; ++i)
{
ids.push_back(i);
nets.push_back("1234.123456");
}
sql << "insert into nets(id, net) values(:id, :net)",
use(ids), use(nets);
}
catch (soci::odbc_soci_error const& e)
{
cerr << "ODBC Error Code: " << e.odbc_error_code() << endl
<< "Native Error Code: " << e.native_error_code() << endl
<< "SOCI Message: " << e.what() << std::endl
<< "ODBC Message: " << e.odbc_error_message() << endl;
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
And I get:-
ODBC Error Code: 01000
Native Error Code: 0
SOCI Message: Statement Execute
ODBC Message: [SOCI]: No error.
If I change the string vector to doubles, it works fine, but will lose
precision (and it works fine via the MySQL backend).
Thanks
Andy
Is there a way of accurately bulk inserting into a decimal field in SQL
server? I'm trying to insert into a table called nets, which has 2 column,
an integer column (id) and a decimal(23,6) column (net). This is the code
I'm using:-
try
{
session sql("odbc", "DSN=socitest;Uid=sa;Pwd=XXXXX;");
vector<int> ids;
vector<string> nets;
for (int i = 0; i != 1000; ++i)
{
ids.push_back(i);
nets.push_back("1234.123456");
}
sql << "insert into nets(id, net) values(:id, :net)",
use(ids), use(nets);
}
catch (soci::odbc_soci_error const& e)
{
cerr << "ODBC Error Code: " << e.odbc_error_code() << endl
<< "Native Error Code: " << e.native_error_code() << endl
<< "SOCI Message: " << e.what() << std::endl
<< "ODBC Message: " << e.odbc_error_message() << endl;
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
And I get:-
ODBC Error Code: 01000
Native Error Code: 0
SOCI Message: Statement Execute
ODBC Message: [SOCI]: No error.
If I change the string vector to doubles, it works fine, but will lose
precision (and it works fine via the MySQL backend).
Thanks
Andy