Warning, /sdk/codevis/thirdparty/soci/docs/quickstart.md is written in an unsupported language. File is not indexed.
0001 # Quickstart
0002
0003 The following (complete!) example is purposedly provided without any explanation.
0004
0005 ```cpp
0006 #include "soci.h"
0007 #include "soci-oracle.h"
0008 #include <iostream>
0009 #include <istream>
0010 #include <ostream>
0011 #include <string>
0012 #include <exception>
0013
0014 using namespace soci;
0015 using namespace std;
0016
0017 bool get_name(string &name) {
0018 cout << "Enter name: ";
0019 return cin >> name;
0020 }
0021
0022 int main()
0023 {
0024 try
0025 {
0026 session sql(oracle, "service=mydb user=john password=secret");
0027
0028 int count;
0029 sql << "select count(*) from phonebook", into(count);
0030
0031 cout << "We have " << count << " entries in the phonebook.\n";
0032
0033 string name;
0034 while (get_name(name))
0035 {
0036 string phone;
0037 indicator ind;
0038 sql << "select phone from phonebook where name = :name",
0039 into(phone, ind), use(name);
0040
0041 if (ind == i_ok)
0042 {
0043 cout << "The phone number is " << phone << '\n';
0044 }
0045 else
0046 {
0047 cout << "There is no phone for " << name << '\n';
0048 }
0049 }
0050 }
0051 catch (exception const &e)
0052 {
0053 cerr << "Error: " << e.what() << '\n';
0054 }
0055 }
0056 ```