SELECT as scalar value
[sqlgg.git] / example / test_cxx.cpp
blobc2f272c6c7f9f946997c47b4515d4a8d1bda4639
1 //
3 #include "../sqlite3_helper.hpp"
4 #include "test_cxx_gen.hpp"
5 #include <boost/foreach.hpp>
6 #include <iostream>
7 #include <vector>
9 using namespace std;
11 typedef sqlgg<sqlite3_traits> gen;
14 void to_console(const wchar_t* s)
16 HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
18 DWORD ignore;
19 WriteConsoleW(console, s, wcslen(s), &ignore, NULL);
22 void to_console(const std::wstring& s)
24 to_console(s.c_str());
28 void explain(char const* msg, sqlite3* db)
30 cout << msg << " : " /*<< sqlite3_errcode(db) << " "*/ << sqlite3_errmsg(db) << endl;
33 int main()
35 sqlite3* db = NULL;
36 int nResult = SQLITE_OK;
38 nResult = sqlite3_open("test.db", &db);
39 explain("open",db);
41 nResult = sqlite3_exec(db,"DROP TABLE test;",NULL,NULL,NULL);
42 explain("drop",db);
43 nResult = sqlite3_exec(db,"DROP TABLE loc;",NULL,NULL,NULL);
44 explain("drop",db);
45 nResult = sqlite3_exec(db,"DROP TABLE zuzu;",NULL,NULL,NULL);
46 explain("drop",db);
48 nResult = gen::create(db);
49 explain("create",db);
52 gen::data_1 t;
53 t.name="c++";
54 t.descr="ugly";
55 nResult = gen::Add(db,t);
56 cout << "insert : " << nResult << " " << sqlite3_errmsg(db) << endl;
58 nResult = gen::Add(db,"c++","ugly");
59 explain("insert",db);
61 nResult = gen::Add(db,"c","hard");
62 explain("insert",db);
64 nResult = gen::Add(db,"ocaml","wonderful");
65 explain("insert",db);
67 nResult = gen::Exaggerate(db,"really");
68 explain("update",db);
70 std::vector<gen::data_1> all;
71 nResult = gen::select_all(db,all);
72 explain("select",db);
74 BOOST_FOREACH(gen::data_1 const& q, all)
76 std::cout << q.id << ") " << q.name << " is " << q.descr << std::endl;
79 gen::create_loc(db);
80 explain("create_loc",db);
82 nResult = gen::create_zuzu(db,"qq");
83 explain("create_zuzu",db);
85 nResult = sqlite3_close(db);
86 cout << "close : " << nResult << endl;
88 return 0;