9 int main(int argc, char ** argv)
13 void * lh = dlopen("./pg_driver.so", RTLD_NOW | RTLD_GLOBAL);
16 std::cout << "Error loading shared object file pg_driver.so. Reason: '" << dlerror() << "'" << std::endl;
20 CreateDriverFn CreateDriver = reinterpret_cast<CreateDriverFn>(dlsym(lh, "CreateDriver"));
21 if (CreateDriver == NULL) {
22 std::cout << "Error getting symbol 'CreateDriver' address. Reason: '" << dlerror() << "'" << std::endl;
26 DestroyDriverFn DestroyDriver = reinterpret_cast<DestroyDriverFn>(dlsym(lh, "DestroyDriver"));
27 if (DestroyDriver == NULL) {
28 std::cout << "Error getting symbol 'DestroyDriver' address. Reason: '" << dlerror() << "'" << std::endl;
35 db->SetHost("localhost");
36 db->SetDatabase("stargazer");
38 db->SetPassword("123456");
41 std::cout << "Error connecting db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
47 std::stringstream query;
48 query << "SELECT * FROM information_schema.tables";
50 if (db->Query(query.str())) {
51 std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
58 std::cout << "Tuples: " << db->GetTuples() << std::endl;
59 std::cout << "Columns: " << db->GetColumns() << std::endl;
60 BASE_DB::COLUMNS cols;
61 BASE_DB::COLUMNS::iterator it;
62 cols = db->GetColumnsNames();
63 std::cout << "Cols count: " << cols.size() << std::endl;
64 std::cout << "Columns names:" << std::endl;
65 for (it = cols.begin(); it != cols.end(); ++it)
66 std::cout << *it << " ";
67 std::cout << std::endl;
69 for (int i = 0; i < db->GetTuples(); ++i) {
70 BASE_DB::TUPLE tuple(db->GetTuple(i));
71 BASE_DB::TUPLE::iterator it;
72 for (it = tuple.begin(); it != tuple.end(); ++it)
73 std::cout << it->second << " ";
74 std::cout << std::endl;
78 query << "create table test ( id bigserial, message text )";
79 if (db->Query(query.str())) {
80 std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
88 query << "insert into test (message) values ('abc');";
89 query << "insert into test (message) values ('def');";
90 query << "insert into test (message) values ('zxc');";
91 if (db->Query(query.str())) {
92 std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
100 query << "SELECT * FROM test";
101 if (db->Query(query.str())) {
102 std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
108 std::cout << "Tuples: " << db->GetTuples() << std::endl;
109 std::cout << "Columns: " << db->GetColumns() << std::endl;
110 cols = db->GetColumnsNames();
111 std::cout << "Cols count: " << cols.size() << std::endl;
112 std::cout << "Columns names:" << std::endl;
113 for (it = cols.begin(); it != cols.end(); ++it)
114 std::cout << *it << " ";
115 std::cout << std::endl;
117 for (int i = 0; i < db->GetTuples(); ++i) {
118 BASE_DB::TUPLE tuple(db->GetTuple(i));
119 BASE_DB::TUPLE::iterator it;
120 for (it = tuple.begin(); it != tuple.end(); ++it)
121 std::cout << it->second << " ";
122 std::cout << std::endl;
126 query << "drop table test";
127 if (db->Query(query.str())) {
128 std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
135 if (db->Disconnect()) {
136 std::cout << "Error connecting db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;