32 try { sql <<
"drop table test1"; }
36 "create table test1 (" 41 sql <<
"insert into test1(id, name) values(7, \'John\')";
44 sql <<
"select oid from test1 where id = 7",
into(rid);
49 sql <<
"select id, name from test1 where oid = :rid",
53 assert(name ==
"John");
55 sql <<
"drop table test1";
58 std::cout <<
"test 1 passed" << std::endl;
68 "create table soci_test (" 82 char buf[] =
"abcdefghijklmnopqrstuvwxyz";
84 sql <<
"insert into soci_test(id, img) values(7, '')";
89 sql <<
"select img from soci_test where id = 7",
into(b);
92 b.
write(0, buf,
sizeof(buf));
93 assert(b.
get_len() ==
sizeof(buf));
94 sql <<
"update soci_test set img=? where id = 7",
use(b);
96 b.
append(buf,
sizeof(buf));
97 assert(b.
get_len() == 2 *
sizeof(buf));
98 sql <<
"insert into soci_test(id, img) values(8, ?)",
use(b);
102 sql <<
"select img from soci_test where id = 8",
into(b);
103 assert(b.
get_len() == 2 *
sizeof(buf));
106 assert(std::strncmp(buf2,
"abcdefghij", 10) == 0);
108 sql <<
"select img from soci_test where id = 7",
into(b);
109 assert(b.
get_len() ==
sizeof(buf));
114 std::cout <<
"test 2 passed" << std::endl;
125 sql <<
"create table soci_test( id integer, name varchar, subname varchar);";
136 sql <<
"insert into soci_test(id,name,subname) values( 1,'john','smith')";
137 sql <<
"insert into soci_test(id,name,subname) values( 2,'george','vals')";
138 sql <<
"insert into soci_test(id,name,subname) values( 3,'ann','smith')";
139 sql <<
"insert into soci_test(id,name,subname) values( 4,'john','grey')";
140 sql <<
"insert into soci_test(id,name,subname) values( 5,'anthony','wall')";
143 std::vector<int> v(10);
147 std::string name =
"john";
155 assert(v.size() == 2);
158 std::cout <<
"test 3 passed" << std::endl;
173 sql <<
"create table soci_test (col INTEGER PRIMARY KEY AUTOINCREMENT, name char)";
185 sql <<
"insert into soci_test(name) values('john')";
186 sql <<
"insert into soci_test(name) values('james')";
191 sql <<
"select * from soci_test",
into(key),
into(name);
192 assert(name ==
"john");
196 row const& r1 = (*it);
197 assert(r1.
get<std::string>(0) ==
"soci_test");
198 assert(r1.
get<std::string>(1) ==
"2");
201 std::cout <<
"test 4 passed" << std::endl;
209 sql <<
"create table soci_test(val number(20))";
221 long long v1 = 1000000000000LL;
222 assert(v1 / 1000000 == 1000000);
224 sql <<
"insert into soci_test(val) values(:val)",
use(v1);
227 sql <<
"select val from soci_test",
into(v2);
238 std::vector<long long> v1;
239 v1.push_back(1000000000000LL);
240 v1.push_back(1000000000001LL);
241 v1.push_back(1000000000002LL);
242 v1.push_back(1000000000003LL);
243 v1.push_back(1000000000004LL);
245 sql <<
"insert into soci_test(val) values(:val)",
use(v1);
247 std::vector<long long> v2(10);
248 sql <<
"select val from soci_test order by val desc",
into(v2);
250 assert(v2.size() == 5);
251 assert(v2[0] == 1000000000004LL);
252 assert(v2[1] == 1000000000003LL);
253 assert(v2[2] == 1000000000002LL);
254 assert(v2[3] == 1000000000001LL);
255 assert(v2[4] == 1000000000000LL);
258 std::cout <<
"test 5 passed" << std::endl;
265 sql <<
"create table soci_test (id INTEGER PRIMARY KEY, name char)";
276 sql <<
"insert into soci_test(id, name) values(1, 'john')";
282 sql <<
"insert into soci_test(id, name) values(1, 'jack')";
286 assert(SQLITE_CONSTRAINT == (0xFF & e.
result()));
290 std::cout <<
"test 6 passed" << std::endl;
299 sql <<
"create table soci_test(id integer, val integer, c char, " 300 "str varchar(20), sh smallint, ul numeric(20), d float, " 301 "tm datetime, i1 integer, i2 integer, i3 integer, " 311 sql <<
"create table soci_test(num_float float, num_int integer," 312 " name varchar(20), sometime datetime, chr char)";
321 sql <<
"create table soci_test(name varchar(100) not null, " 322 "phone varchar(15))";
336 sql <<
"create table soci_test(val integer)";
373 return "datetime(\'" + datdt_string +
"\')";
377 int main(
int argc,
char** argv)
385 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
386 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
405 std::cout <<
"\nSOCI sqlite3 Tests:\n\n";
414 std::cout <<
"\nOK, all tests passed.\n\n";
420 std::cout <<
"SOCIERROR: " << e.what() <<
'\n';
422 catch (std::exception
const & e)
424 std::cout <<
"EXCEPTION: " << e.what() <<
'\n';
const_iterator begin() 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)
test6_table_creator(session &sql)
table_creator_base * table_creator_2(session &s) const
void run(bool dbSupportsTransactions=true)
std::size_t read(std::size_t offset, char *buf, std::size_t toRead)
backend_factory const & backEnd
int main(int argc, char **argv)
table_creator_one(session &sql)
table_creator_base * table_creator_4(session &s) const
std::string connectString
blob_table_creator(session &sql)
table_creator_base * table_creator_1(session &s) const
test4_table_creator(session &sql)
longlong_table_creator(session &sql)
std::size_t append(char const *buf, std::size_t toWrite)
table_creator_base * table_creator_3(session &s) const
table_creator_for_get_affected_rows(session &sql)
std::string to_date_time(std::string const &datdt_string) const
table_creator_two(session &sql)
details::prepare_type prepare
void exchange(details::into_type_ptr const &i)
table_creator_three(session &sql)
details::use_container< T, details::no_indicator > use(T &t, const std::string &name=std::string())
test3_table_creator(session &sql)
SOCI_SQLITE3_DECL backend_factory const * factory_sqlite3()
bool execute(bool withDataExchange=false)
std::size_t write(std::size_t offset, char const *buf, std::size_t toWrite)