#include "soci.h" #include <iostream> #include <istream> #include <ostream> #include <string> #include <exception>
using namespace SOCI; using namespace std;
bool getName(string &name) { cout << "Enter name: "; return cin >> name; }
int main() { try { Session sql("oracle", "service=mydb user=john password=secret");
int count; sql << "select count(*) from phonebook", into(count); cout << "We have " << count << " entries in the phonebook.\n";
string name; while (getName(name)) { string phone; eIndicator ind; sql << "select phone from phonebook where name = :name", into(phone, ind), use(name); if (ind == eOK) { cout << "The phone number is " << phone << '\n'; } else { cout << "There is no phone for " << name << '\n'; } } } catch (exception const &e) { cerr << "Error: " << e.what() << '\n'; } }
|