We are now going to write a minimal client program which will perform the following operations:
initialize the EyeDB package and the person
package
open a connection with the EyeDB server
open a database
perform error management
release the EyeDB package and the person
package
Example 4.1, “A minimal C++ client” shows the code for this minimal client.
Example 4.1. A minimal C++ client
#include "person.h" int main(int argc, char *argv[]) { eyedb::init(argc, argv); // initializes EyeDB package person::init(); // initializes person package eyedb::Exception::setMode(eyedb::Exception::ExceptionMode); // use exception mode try { eyedb::Connection conn; conn.open(); // opens the connection personDatabase db(argv[1]); // creates a database handle db.open(&conn, eyedb::Database::DBRW); // opens the database in read/write mode } catch(Exception &e) { // catch any exception and print it e.print(); } person::release(); // releases person package eyedb::release(); // releases EyeDB package return 0; }
Note that statement Exception::setMode(...) is mandatory if you want to use the exception error policy.