34 sql <<
"CREATE TABLE SOCI_TEST(ID INTEGER, VAL SMALLINT, C CHAR, STR VARCHAR(20), SH SMALLINT, UL NUMERIC(20), D DOUBLE, " 35 "TM TIMESTAMP, I1 INTEGER, I2 INTEGER, I3 INTEGER, NAME VARCHAR(20))";
44 sql <<
"CREATE TABLE SOCI_TEST(NUM_FLOAT DOUBLE, NUM_INT INTEGER, NAME VARCHAR(20), SOMETIME TIMESTAMP, CHR CHAR)";
53 sql <<
"CREATE TABLE SOCI_TEST(NAME VARCHAR(100) NOT NULL, PHONE VARCHAR(15))";
62 sql <<
"CREATE TABLE SOCI_TEST(VAL INTEGER)";
74 pr_s <<
"SET CURRENT SCHEMA = 'DB2INST1'";
80 pr_s <<
"SET CURRENT SCHEMA = 'DB2INST1'";
86 pr_s <<
"SET CURRENT SCHEMA = 'DB2INST1'";
95 std::string
to_date_time(std::string
const & pi_datdt_string)
const 97 return "to_date('" + pi_datdt_string +
"', 'YYYY-MM-DD HH24:MI:SS')";
111 sql <<
"SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1";
112 sql <<
"SELECT " << 123 <<
" FROM SYSIBM.SYSDUMMY1";
114 std::string query =
"CREATE TABLE DB2INST1.SOCI_TEST (ID BIGINT,DATA VARCHAR(8))";
119 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(i,
"id");
121 sql <<
"select id from db2inst1.SOCI_TEST where id=7",
into(j);
126 const long int li = 9;
127 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(li,
"id");
129 sql <<
"select id from db2inst1.SOCI_TEST where id=9",
into(lj);
134 const long long ll = 11;
135 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(ll,
"id");
137 sql <<
"select id from db2inst1.SOCI_TEST where id=11",
into(lj);
144 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(i,i_ind,
"id");
147 sql <<
"select id from db2inst1.SOCI_TEST where id=13",
into(j,j_ind);
149 assert(j_ind ==
i_ok);
153 std::vector<int> numbers(100);
154 for (
int i = 0 ; i < 100 ; i++)
156 numbers[i] = i + 1000;
158 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(numbers,
"id");
159 sql <<
"select id from db2inst1.SOCI_TEST where id >= 1000 and id < 2000 order by id",
into(numbers);
160 for (
int i = 0 ; i < 100 ; i++)
162 assert(numbers[i] == i + 1000);
167 std::vector<int> numbers(100);
168 std::vector<indicator> inds(100);
169 for (
int i = 0 ; i < 100 ; i++)
171 numbers[i] = i + 2000;
174 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(numbers,inds,
"id");
175 for (
int i = 0 ; i < 100 ; i++)
180 sql <<
"select id from db2inst1.SOCI_TEST where id >= 2000 and id < 3000 order by id",
into(numbers,inds);
181 for (
int i = 0 ; i < 100 ; i++)
183 assert(numbers[i] == i + 2000);
184 assert(inds[i] ==
i_ok);
207 statement st = (sql.
prepare <<
"select id, data from db2inst1.SOCI_TEST where id = 13",
into(i, i_ind),
into(d, d_ind));
211 assert (i_ind ==
i_ok);
216 std::vector<int> numbers(100);
217 for (
int i = 0 ; i < 100 ; i++)
221 statement st = (sql.
prepare <<
"select id from db2inst1.SOCI_TEST where id >= 1000 order by id",
into(numbers));
224 for (
int i = 0 ; i < 100 ; i++)
226 assert(numbers[i] == i + 1000);
229 for (
int i = 0 ; i < 100 ; i++)
231 assert(numbers[i] == i + 2000);
236 std::vector<int> numbers(100);
237 std::vector<indicator> inds(100);
238 for (
int i = 0 ; i < 100 ; i++)
243 statement st = (sql.
prepare <<
"select id from db2inst1.SOCI_TEST where id >= 1000 order by id",
into(numbers, inds));
246 for (
int i = 0 ; i < 100 ; i++)
248 assert(numbers[i] == i + 1000);
249 assert(inds[i] ==
i_ok);
252 for (
int i = 0 ; i < 100 ; i++)
254 assert(numbers[i] == i + 2000);
255 assert(inds[i] ==
i_ok);
274 std::vector<int> numbers(100);
280 std::vector<int> numbers(100);
281 std::vector<indicator> inds(100);
285 sql<<
"DROP TABLE DB2INST1.SOCI_TEST";
290 std::cout <<
"test 1 passed" << std::endl;
297 std::string query =
"CREATE TABLE DB2INST1.SOCI_TEST (ID BIGINT,DATA VARCHAR(8),DT TIMESTAMP)";
302 std::string n(
"test");
303 sql <<
"insert into db2inst1.SOCI_TEST (id,data) values (:id,:name)",
use(i,
"id"),
use(n,
"name");
306 sql <<
"select id,data from db2inst1.SOCI_TEST where id=7",
into(j),
into(m);
313 sql <<
"insert into db2inst1.SOCI_TEST (id) values (:id)",
use(i,
"id");
317 sql <<
"select id,data from db2inst1.SOCI_TEST where id=8",
into(j),
into(m,ind);
324 sql <<
"select current timestamp from sysibm.sysdummy1",
into(dt);
325 sql <<
"insert into db2inst1.SOCI_TEST (dt) values (:dt)",
use(dt,
"dt");
327 sql <<
"select dt from db2inst1.SOCI_TEST where dt is not null",
into(dt2);
328 assert(dt2.tm_year == dt.tm_year && dt2.tm_mon == dt.tm_mon && dt2.tm_mday == dt.tm_mday &&
329 dt2.tm_hour == dt.tm_hour && dt2.tm_min == dt.tm_min && dt2.tm_sec == dt.tm_sec);
332 sql<<
"DROP TABLE DB2INST1.SOCI_TEST";
336 std::cout <<
"test 2 passed" << std::endl;
344 std::string query =
"CREATE TABLE DB2INST1.SOCI_TEST (ID BIGINT,DATA VARCHAR(8),DT TIMESTAMP)";
347 std::vector<long long> ids(100);
348 std::vector<std::string> data(100);
349 std::vector<std::tm> dts(100);
350 for (
int i = 0; i < 100; i++)
352 ids[i] = 1000000000LL + i;
354 dts[i].tm_year = 112;
359 dts[i].tm_sec = i % 60;
362 sql <<
"insert into db2inst1.SOCI_TEST (id, data, dt) values (:id, :data, :dt)",
363 use(ids,
"id"),
use(data,
"data"),
use(dts,
"dt");
370 const long long id = r.
get<
long long>(0);
371 const std::string data = r.
get<std::string>(1);
372 const std::tm dt = r.
get<std::tm>(2);
374 assert(
id == 1000000000LL + i);
375 assert(data ==
"test");
376 assert(dt.tm_year == 112);
377 assert(dt.tm_mon == 7);
378 assert(dt.tm_mday == 17);
379 assert(dt.tm_hour == 0);
380 assert(dt.tm_min == 0);
381 assert(dt.tm_sec == i % 60);
386 sql<<
"DROP TABLE DB2INST1.SOCI_TEST";
390 std::cout <<
"test 3 passed" << std::endl;
394 int main(
int argc,
char** argv)
402 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
403 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
412 std::cout <<
"usage: " << argv[0]
413 <<
" connectstring\n" 414 <<
"example: " << argv[0]
415 <<
" \'DSN=SAMPLE;Uid=db2inst1;Pwd=db2inst1;autocommit=off\'\n";
425 std::cout<<
"\nSOCI DB2 Tests:\n\n";
432 sql <<
"DROP TABLE DB2INST1.SOCI_TEST";
444 std::cout <<
"\nOK, all tests passed.\n\n";
448 catch (std::exception
const & e)
450 std::cout << e.what() <<
'\n';
table_creator_base * table_creator_1(session &pr_s) const
const_iterator begin() const
T get(std::size_t pos) const
details::into_container< T, details::no_indicator > into(T &t)
backend_factory const & backEnd
table_creator_base * table_creator_2(session &pr_s) const
void run(bool dbSupportsTransactions=true)
int main(int argc, char **argv)
table_creator_one(session &sql)
std::string to_date_time(std::string const &pi_datdt_string) const
table_creator_base * table_creator_4(session &s) const
const_iterator end() const
test_context(backend_factory const &pi_back_end, std::string const &pi_connect_string)
table_creator_for_get_affected_rows(session &sql)
table_creator_base * table_creator_3(session &pr_s) const
std::string connectString
SOCI_DB2_DECL backend_factory const * factory_db2()
table_creator_two(session &sql)
details::prepare_type prepare
table_creator_three(session &sql)
details::use_container< T, details::no_indicator > use(T &t, const std::string &name=std::string())
bool execute(bool withDataExchange=false)