Created
May 27, 2010 09:57
-
-
Save deepfryed/415646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dbixx/dbixx.h> | |
#include <unistd.h> | |
#include <iostream> | |
using namespace dbixx; | |
using namespace std; | |
int main() { | |
nice(19); | |
try { | |
session sql("pgsql"); | |
sql.param("dbname","..."); | |
sql.param("username","..."); | |
sql.param("host","127.0.0.1"); | |
sql.connect(); | |
int id; | |
string name; | |
result res; | |
for (int i = 0; i < 10000; i++) { | |
sql << "SELECT name FROM users WHERE id = ?", 1; | |
row r; | |
if(sql.single(r)) { | |
r >> name; | |
cout << name << endl; | |
} | |
else { | |
cout << "No user with id=" << 1 << endl; | |
} | |
sql << "SELECT id, name FROM users"; | |
sql.fetch(res); | |
while(res.next(r)) { | |
r >> id >> name; | |
cout << id <<"\t" << name << endl; | |
} | |
} | |
} | |
catch(std::exception const &e) { | |
cerr << e.what() << endl; | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment