41 sql <<
"drop table test1";
46 sql <<
"create table test1 (id integer)";
55 sql <<
"insert into test1(id) values(5)";
56 sql <<
"drop table test1";
61 std::cout <<
"test 1 passed" << std::endl;
71 sql <<
"drop table test2";
76 sql <<
"create table test2 (p1 char(10), p2 varchar(10))";
82 char a(
'a'), b(
'b'), c1, c2;
84 sql <<
"insert into test2(p1,p2) values(?,?)",
use(a),
use(b);
86 sql <<
"select p1,p2 from test2",
into(c1),
into(c2);
87 assert(c1 ==
'a' && c2 ==
'b');
89 sql <<
"delete from test2";
92 #if 0 // SOCI doesn't support binding into(char *, ...) anymore, use std::string 94 char msg[] =
"Hello, Firebird!";
95 char buf1[100], buf2[100], buf3[100];
96 char *b1 = buf1, *b2 = buf2, *b3 = buf3;
100 sql <<
"insert into test2(p1, p2) values (?,?)",
use(b1, 100),
use(b1, 100);
101 sql <<
"select p1, p2 from test2",
into(b2, 100),
into(b3, 100);
103 assert(!std::strcmp(buf2, buf3) && !std::strcmp(buf2,
"Hello, Fir"));
105 sql <<
"delete from test2";
109 char msg[] =
"Hello, Firebird!";
110 char buf1[100], buf2[100], buf3[100];
113 sql <<
"insert into test2(p1, p2) values (?,?)",
115 sql <<
"select p1, p2 from test2",
into(buf2),
into(buf3);
117 assert(!std::strcmp(buf2, buf3) && !std::strcmp(buf2,
"Hello, Fir"));
119 sql <<
"delete from test2";
124 std::string b1(
"Hello, Firebird!"), b2, b3;
126 sql <<
"insert into test2(p1, p2) values (?,?)",
use(b1),
use(b1);
127 sql <<
"select p1, p2 from test2",
into(b2),
into(b3);
129 assert(b2 == b3 && b2 ==
"Hello, Fir");
131 sql <<
"delete from test2";
137 char msg[] =
"Hello";
138 sql <<
"insert into test2(p1) values(\'" << msg <<
"\')";
142 sql <<
"select p1 from test2",
into(buf_str);
143 std::strcpy(buf, buf_str.c_str());
145 assert(std::strncmp(buf, msg, 5) == 0);
146 assert(std::strncmp(buf+5,
" ", 5) == 0);
148 sql <<
"delete from test2";
152 std::string str1(
"Hello, Firebird!"), str2, str3;
153 sql <<
"insert into test2(p1, p2) values (?, ?)",
156 sql <<
"select p1, p2 from test2",
into(str2),
into(str3);
157 assert(str2 ==
"Hello, Fir" && str3 ==
"Hello, Fir");
159 sql <<
"delete from test2";
162 sql <<
"drop table test2";
163 std::cout <<
"test 2 passed" << std::endl;
173 sql <<
"drop table test3";
178 sql <<
"create table test3 (p1 timestamp, p2 date, p3 time)";
184 std::time_t now = std::time(NULL);
185 std::tm t = *std::localtime(&now);
187 sql <<
"insert into test3(p1, p2, p3) " 188 <<
"values (?,?,?)",
use(t),
use(t),
use(t);
190 sql <<
"select p1, p2, p3 from test3",
into(t1),
into(t2),
into(t3);
193 assert(t1.tm_year == t.tm_year);
194 assert(t1.tm_mon == t.tm_mon);
195 assert(t1.tm_mday == t.tm_mday);
196 assert(t1.tm_hour == t.tm_hour);
197 assert(t1.tm_min == t.tm_min);
198 assert(t1.tm_sec == t.tm_sec);
201 assert(t2.tm_year == t.tm_year);
202 assert(t2.tm_mon == t.tm_mon);
203 assert(t2.tm_mday == t.tm_mday);
204 assert(t2.tm_hour == 0);
205 assert(t2.tm_min == 0);
206 assert(t2.tm_sec == 0);
209 assert(t3.tm_year == 0);
210 assert(t3.tm_mon == 0);
211 assert(t3.tm_mday == 0);
212 assert(t3.tm_hour == t.tm_hour);
213 assert(t3.tm_min == t.tm_min);
214 assert(t3.tm_sec == t.tm_sec);
216 sql <<
"drop table test3";
217 std::cout <<
"test 3 passed" << std::endl;
227 sql <<
"drop table test4";
232 sql <<
"create table test4 (p1 numeric(8,2), " 233 <<
"p2 decimal(14,8), p3 double precision, p4 integer)";
238 double d1 = 1234.23, d2 = 1e8, d3 = 1.0/1440.0,
241 sql <<
"insert into test4(p1, p2, p3) values (?,?,?)",
244 sql <<
"select p1, p2, p3 from test4",
247 assert(d1 == d4 && d2 == d5 && d3 == d6);
250 sql <<
"delete from test4";
255 sql <<
"insert into test4(p1, p2, p3) values (?,?,?)",
258 sql <<
"select p1, p2, p3 from test4",
261 assert(d1 == d4 && d2 == d5 && d3 == d6);
268 sql <<
"select p1 from test4",
into(i);
275 std::string error = e.what();
277 "Can't convert value with scale 2 to integral type");
284 sql <<
"insert into test4(p4) values(?)",
use(d1);
291 std::string error = e.what();
293 "Can't convert non-integral value to integral column type");
296 sql <<
"drop table test4";
297 std::cout <<
"test 4 passed" << std::endl;
307 sql <<
"select 3 from rdb$database",
into(sh);
313 sql <<
"select 5 from rdb$database",
into(i);
319 sql <<
"select 7 from rdb$database",
into(ul);
328 sql <<
"select 2 from rdb$database",
into(i, ind);
331 sql <<
"select NULL from rdb$database",
into(i, ind);
334 #if 0 // SOCI doesn't support binding into(char *, ...) anymore, use std::string 336 sql <<
"select \'Hello\' from rdb$database",
into(buf, ind);
340 sql <<
"select 5 from rdb$database where 0 = 1",
into(i, ind);
346 sql <<
"select NULL from rdb$database",
into(i);
351 std::string error = e.what();
353 "Null value fetched and no indicator defined.");
357 sql <<
"select 5 from rdb$database where 0 = 1",
into(i);
361 std::cout <<
"test 5 passed" << std::endl;
371 sql <<
"drop table test6";
376 sql <<
"create table test6 (p1 char(10), p2 varchar(10))";
381 for (
char c =
'a'; c <=
'z'; ++c)
383 sql <<
"insert into test6(p1, p2) values(?,?)",
use(c),
use(c);
390 "select p1,p2 from test6 order by p1",
into(c1),
into(c2));
393 for (
int n = 0; n < 2; ++n)
400 assert(c == c1 && c == c2);
410 std::vector<char> c1(10), c2(10);
413 "select p1,p2 from test6 order by p1",
into(c1),
into(c2));
418 for (std::size_t i = 0; i != c1.size(); ++i)
420 assert(c == c1[i] && c == c2[i]);
424 assert(c ==
'z' + 1);
429 std::vector<char> vec;
432 sql <<
"select p1 from test6",
into(vec);
437 std::string msg = e.what();
438 assert(msg ==
"Vectors of size 0 are not allowed.");
442 sql <<
"delete from test6";
445 int const rowsToTest = 10;
446 for (
int i = 0; i != rowsToTest; ++i)
448 std::ostringstream ss;
451 std::string
const &x = ss.str();
453 sql <<
"insert into test6(p1, p2) values(\'" 454 << x <<
"\', \'" << x <<
"\')";
458 sql <<
"select count(*) from test6",
into(count);
459 assert(count == rowsToTest);
465 "select p1, p2 from test6 order by p1",
into(s1),
into(s2));
470 std::ostringstream ss;
472 std::string
const &x = ss.str();
476 assert(s1 == ss.str() && s2 == x);
479 assert(i == rowsToTest);
485 std::vector<std::string> s1(4), s2(4);
487 "select p1, p2 from test6 order by p1",
into(s1),
into(s2));
491 for (std::size_t j = 0; j != s1.size(); ++j)
493 std::ostringstream ss;
495 std::string
const &x = ss.str();
499 assert(ss.str() == s1[j] && x == s2[j]);
503 assert(i == rowsToTest);
506 sql <<
"drop table test6";
507 std::cout <<
"test 6 passed" << std::endl;
517 sql <<
"drop table test7";
519 catch (std::runtime_error &)
522 sql <<
"create table test7(id integer, img blob)";
531 sql <<
"insert into test7(id, img) values(1,?)",
use(b);
532 sql <<
"select img from test7 where id = 1",
into(b, ind);
537 sql <<
"delete from test7";
544 char str1[] =
"Hello";
545 b.
write(0, str1, strlen(str1));
548 std::size_t i = b.
read(3, str2, 2);
550 assert(str2[0] ==
'l' && str2[1] ==
'o' && str2[2] ==
'\0');
552 char str3[] =
", Firebird!";
553 b.
append(str3, strlen(str3));
555 sql <<
"insert into test7(id, img) values(1,?)",
use(b);
562 sql <<
"select img from test7 where id = 1",
into(b);
564 std::vector<char> text(b.
get_len());
566 assert(strncmp(&text[0],
"Hello, Firebird!", b.
get_len()) == 0);
568 char str1[] =
"FIREBIRD";
569 b.
write(7, str1, strlen(str1));
572 sql <<
"update test7 set img=? where id=1",
use(b);
579 sql <<
"select img from test7 where id = 1",
into(b);
581 std::vector<char> text(b.
get_len());
584 char str1[] =
"HELLO";
585 b.
write(0, str1, strlen(str1));
588 assert(strncmp(&text[0],
"HELLO, FIREBIRD!", b.
get_len()) == 0);
591 sql <<
"insert into test7(id, img) values(2,?)",
use(b);
601 std::vector<char> text(b.
get_len());
603 assert(strncmp(&text[0],
"Hello, FIREBIRD!", b.
get_len()) == 0);
608 assert(strncmp(&text[0],
"HELLO", b.
get_len()) == 0);
615 sql <<
"update test7 set img=? where id = 1",
use(b, ind);
617 sql <<
"select img from test7 where id = 2",
into(b, ind);
620 sql <<
"select img from test7 where id = 1",
into(b, ind);
624 sql <<
"drop table test7";
625 std::cout <<
"test 7 passed" << std::endl;
635 sql <<
"drop table test8";
637 catch (std::runtime_error &)
640 sql <<
"create table test8(id1 integer, id2 integer)";
645 int j = 13, k = 4, i, m;
646 sql <<
"insert into test8(id1, id2) values(:id1, :id2)",
647 use(k,
"id2"),
use(j,
"id1");
648 sql <<
"select id1, id2 from test8",
into(i),
into(m);
649 assert(i == j && m == k);
651 sql <<
"delete from test8";
653 std::vector<int> in1(3), in2(3);
663 "insert into test8(id1, id2) values(:id1, :id2)",
664 use(k,
"id2"),
use(j,
"id1"));
666 std::size_t s = in1.size();
667 for (std::size_t x = 0; x < s; ++x)
683 assert(i = in1[x] && m == in2[x]);
688 sql <<
"delete from test8";
691 sql <<
"insert into test8(id1, id2) values(:id1, :id2)",
692 use(in1,
"id1"),
use(in2,
"id2");
694 std::vector<int> out1(3), out2(3);
696 sql <<
"select id1, id2 from test8",
into(out1),
into(out2);
697 std::size_t s = out1.size();
700 for (std::size_t x = 0; x<s; ++x)
702 assert(out1[x] == in1[x] && out2[x] == in2[x]);
705 sql <<
"drop table test8";
706 std::cout <<
"test 8 passed" << std::endl;
716 sql <<
"drop table test9";
718 catch (std::runtime_error &)
721 sql <<
"create table test9(id integer, msg varchar(20), ntest numeric(10,2))";
728 sql <<
"select * from test9",
into(r);
732 std::string msg(
"Hello");
739 <<
"values(:id,:msg,:ntest)",
740 use(i,
"id"),
use(msg,
"msg"),
use(d, ind,
"ntest")));
752 "select * from test9",
into(r));
755 assert(r.
size() == 3);
776 assert(r.
get<
int>(0) == 1);
777 assert(r.
get<std::string>(1) ==
"Hello");
778 assert(r.
get<
double>(2) == d);
781 assert(r.
get<
int>(
"ID") == 1);
782 assert(r.
get<std::string>(
"MSG") ==
"Hello");
783 assert(r.
get<
double>(
"NTEST") == d);
786 assert(r.
get<
int>(0) == 2);
787 assert(r.
get<std::string>(
"MSG") ==
"Firebird");
791 assert(r.
get<
double>(
"NTEST", 2) == 2);
795 double d1 = r.
get<
double>(
"NTEST");
796 std::cout << d1 << std::endl;
808 r.
get<std::string>(0);
810 catch (std::bad_cast
const &)
816 sql <<
"drop table test9";
817 std::cout <<
"test 9 passed" << std::endl;
827 sql <<
"drop procedure sp_test10";
829 catch (std::runtime_error &)
834 sql <<
"drop procedure sp_test10a";
836 catch (std::runtime_error &)
841 sql <<
"drop table test10";
843 catch (std::runtime_error &)
846 sql <<
"create table test10(id integer, id2 integer)";
848 sql <<
"create procedure sp_test10\n" 849 <<
"returns (rid integer, rid2 integer)\n" 851 <<
"for select id, id2 from test10 into rid, rid2 do begin\n" 856 sql <<
"create procedure sp_test10a (pid integer, pid2 integer)\n" 858 <<
"insert into test10(id, id2) values (:pid, :pid2);\n" 870 sql <<
"execute procedure sp_test10a ?, ?",
use(p1),
use(p2);
874 sql <<
"select * from sp_test10",
into(r);
876 assert(r.
get<
int>(0) == p1 && r.
get<
int>(1) == p2);
878 sql <<
"delete from test10";
884 sql.
prepare <<
"sp_test10a :p1, :p2",
885 use(p2,
"p2"),
use(p1,
"p1"));
894 assert(rw.
get<
int>(0) == p1 && rw.
get<
int>(1) == p2);
897 sql <<
"delete from test10";
900 std::vector<int> in1(3), in2(3);
910 sql.
prepare <<
"sp_test10a :p1, :p2",
911 use(in2,
"p2"),
use(in1,
"p1"));
920 assert(rw.
get<
int>(0) == in1[0] && rw.
get<
int>(1) == in2[0]);
922 assert(rw.
get<
int>(0) == in1[1] && rw.
get<
int>(1) == in2[1]);
924 assert(rw.
get<
int>(0) == in1[2] && rw.
get<
int>(1) == in2[2]);
925 assert(proc.
fetch() ==
false);
929 std::vector<int> out1(3), out2(3);
933 std::size_t s = out1.size();
936 for (std::size_t x = 0; x < s; ++x)
938 assert(out1[x] == in1[x] && out2[x] == in2[x]);
945 sql <<
"drop procedure sp_test10";
946 sql <<
"drop procedure sp_test10a";
947 sql <<
"drop table test10";
949 std::cout <<
"test 10 passed" << std::endl;
969 char cnt_req[2], cnt_info[128];
971 cnt_req[0]=isc_info_sql_records;
972 cnt_req[1]=isc_info_end;
981 if (isc_dsql_sql_info(stat, &statementBackEnd->
stmtp_,
sizeof(cnt_req),
982 cnt_req,
sizeof(cnt_info), cnt_info))
988 char type_ =
static_cast<char>(type);
989 for (
char *ptr = cnt_info + 3; *ptr != isc_info_end;)
991 char count_type = *ptr++;
992 int m = isc_vax_integer(ptr, 2);
994 count = isc_vax_integer(ptr, m);
996 if (count_type == type_)
1015 sql <<
"drop table test11";
1017 catch (std::runtime_error &)
1020 sql <<
"create table test11(id integer)";
1026 std::vector<int> in(3);
1054 std::vector<int> out(3);
1073 sql <<
"drop table test11";
1074 std::cout <<
"test 11 passed" << std::endl;
1083 sql <<
"drop table test12";
1085 catch (std::runtime_error &)
1088 sql <<
"create table test12(a decimal(10,3), b timestamp, c date, d time)";
1095 std::string a =
"-3.14150", b =
"2013-02-28 23:36:01",
1096 c =
"2013-02-28", d =
"23:36:01";
1098 "insert into test12(a, b, c, d) values (?, ?, ?, ?)",
1107 sql <<
"select a, b, c, d from test12",
1109 assert(std::fabs(a - (-3.141)) < 0.000001);
1110 assert(b.tm_year + 1900 == 2013 && b.tm_mon + 1 == 2 && b.tm_mday == 28);
1111 assert(b.tm_hour == 23 && b.tm_min == 36 && b.tm_sec == 1);
1112 assert(c.tm_year + 1900 == 2013 && c.tm_mon + 1 == 2 && c.tm_mday == 28);
1113 assert(c.tm_hour == 0 && c.tm_min == 0 && c.tm_sec == 0);
1114 assert(d.tm_hour == 23 && d.tm_min == 36 && d.tm_sec == 1);
1117 sql <<
"drop table test12";
1118 std::cout <<
"test 12 passed" << std::endl;
1127 assert(format_decimal<int>(&a, 1) ==
"-123456780");
1128 assert(format_decimal<int>(&a, 0) ==
"-12345678");
1129 assert(format_decimal<int>(&a, -3) ==
"-12345.678");
1130 assert(format_decimal<int>(&a, -8) ==
"-0.12345678");
1131 assert(format_decimal<int>(&a, -9) ==
"-0.012345678");
1134 assert(format_decimal<int>(&a, 1) ==
"123456780");
1135 assert(format_decimal<int>(&a, 0) ==
"12345678");
1136 assert(format_decimal<int>(&a, -3) ==
"12345.678");
1137 assert(format_decimal<int>(&a, -8) ==
"0.12345678");
1138 assert(format_decimal<int>(&a, -9) ==
"0.012345678");
1144 sql <<
"drop table test13";
1146 catch (std::runtime_error &)
1149 sql <<
"create table test13(ntest1 decimal(10,2), " 1150 <<
"ntest2 decimal(4,4), ntest3 decimal(3,1))";
1157 sql <<
"select * from test13",
into(r);
1161 std::string d_str0(
"+03.140"), d_str1(
"3.14"),
1162 d_str2(
"3.1400"), d_str3(
"3.1");
1167 "insert into test13(ntest1, ntest2, ntest3) " 1168 "values(:ntest1, :ntest2, :ntest3)",
1169 use(d_str0, ind,
"ntest1"),
use(d_str0,
"ntest2"),
1170 use(d_str0,
"ntest3")));
1182 assert(r.
size() == 3);
1201 assert(r.
get<std::string>(0) == d_str1);
1202 assert(r.
get<std::string>(1) == d_str2);
1203 assert(r.
get<std::string>(2) == d_str3);
1206 assert(r.
get<std::string>(
"NTEST1") == d_str1);
1207 assert(r.
get<std::string>(
"NTEST2") == d_str2);
1208 assert(r.
get<std::string>(
"NTEST3") == d_str3);
1215 sql <<
"drop table test13";
1216 std::cout <<
"test 13 passed" << std::endl;
1226 : tests::table_creator_base(sql)
1228 sql <<
"create table soci_test(id integer, val integer, c char, " 1229 "str varchar(20), sh smallint, ul bigint, d double precision, " 1230 "tm timestamp, i1 integer, i2 integer, i3 integer, name varchar(20))";
1239 : tests::table_creator_base(sql)
1241 sql <<
"create table soci_test(num_float float, num_int integer, " 1242 "name varchar(20), sometime timestamp, chr char)";
1251 : tests::table_creator_base(sql)
1253 sql <<
"create table soci_test(name varchar(100) not null, " 1254 "phone varchar(15))";
1263 : tests::table_creator_base(sql)
1265 sql <<
"create table soci_test(val integer)";
1276 : test_context_base(backEnd, connectString)
1301 return "'" + datdt_string +
"'";
1314 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
1315 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1324 std::cout <<
"usage: " << argv[0]
1325 <<
" connectstring\n" 1326 <<
"example: " << argv[0]
1327 <<
" \"service=/usr/local/firebird/db/test.fdb user=SYSDBA password=masterkey\"\n";
1328 return EXIT_FAILURE;
1337 std::cout <<
"\nSOCI Firebird Tests:\n\n";
1352 std::cout <<
"\nOK, all tests passed.\n\n";
1354 return EXIT_SUCCESS;
1356 catch (std::exception
const & e)
1358 std::cout << e.what() <<
'\n';
1360 return EXIT_FAILURE;
TableCreator2(session &sql)
column_properties const & get_properties(std::size_t pos) const
T get(std::size_t pos) const
details::into_container< T, details::no_indicator > into(T &t)
test_context(backend_factory const &backEnd, std::string const &connectString)
TableCreator4(session &sql)
int main(int argc, char **argv)
data_type get_data_type() const
tests::table_creator_base * table_creator_2(session &s) const
void run(bool dbSupportsTransactions=true)
SOCI_FIREBIRD_DECL backend_factory const * factory_firebird()
std::string get_name() const
void trim(std::size_t newLen)
details::statement_backend * get_backend()
TableCreator1(session &sql)
std::size_t read(std::size_t offset, char *buf, std::size_t toRead)
tests::table_creator_base * table_creator_4(session &s) const
soci::backend_factory const & backEnd
bool execute(bool withDataExchange=false)
void throw_iscerror(ISC_STATUS *status_vector)
indicator get_indicator(std::size_t pos) const
tests::table_creator_base * table_creator_1(session &s) const
std::size_t append(char const *buf, std::size_t toWrite)
std::string connectString
TableCreator3(session &sql)
tests::table_creator_base * table_creator_3(session &s) const
long getRowCount(soci::statement &statement, eRowCountType type)
std::string to_date_time(std::string const &datdt_string) const
details::prepare_type prepare
details::use_container< T, details::no_indicator > use(T &t, const std::string &name=std::string())
bool execute(bool withDataExchange=false)
std::size_t write(std::size_t offset, char const *buf, std::size_t toWrite)