dboo::odb

The class odb is the main interface to DBOO. Through odb’s methods the connection is initiated, commits and selects are done anything requiring a database connection.

Usage

You would normally follow these steps to connect to a database:

 1#include <dboo/odb.h>
 2#include <string>
 3
 4using namespace std;
 5string host = "localhost";
 6int port = 8822;
 7string database = "testdb";
 8string userid = "testuser";
 9string password = "mypassword";
10
11int main(int argc, char **argv) {
12  dboo::init();
13
14  auto db = dboo::odb{host, port, database, userid, password};
15
16  // or...
17  dboo::odb db2;
18  db2.connect(host, port, database, userid, password);
19
20  // start using the database...
21  // ...
22}
 1const dboo = require('dboo');
 2
 3const host = "localhost";
 4const port = 8822;
 5const database = "testdb";
 6const user = "testuser";
 7const password = "mypassword";
 8
 9dboo.init(); // Class declarations must come before init!
10
11const db = new dboo.odb();
12
13db.connect(host, port, database, user, password);

Server database

All operations that affects the server, such as creating a database, adding users or groups or modifying logging settings must be done when logged in to the server database.

The login process is the same as during database use but the user must have root priviligies (be member of group root) and the connection must be made to the server database, dboo::database_name::server:

 1#include <dboo/odb.h>
 2#include <string>
 3
 4string host = "localhost";
 5int port = 8822;
 6string root_pwd = "admin";
 7
 8int main(int argc, char *argv) {
 9  dboo::init();
10  
11  auto db = dboo::odb{host, port, dboo::database_name::server, "root", root_pwd};
12  
13  db.add_group("my-db", "Used for users of database my-db");
14  db.add_group("users", "Other uses");
15  db.add_user("me", "my password", {"users", "my-db"});
16}
 1const dboo = require('dboo');
 2
 3
 4const host = "localhost";
 5const port = 8822;
 6const root_pwd = "admin";
 7
 8dboo.init(); // Class declarations must come before init!
 9
10const db = new dboo.odb();
11
12db.connect(host, port, dboo.server_root, "root", root_pwd);
13
14db.add_group("my-db", "Used for users of database my-db");
15db.add_group("users", "Used for normal users");
16db.add_user("me", "my password", ["users", "my-db"]);

Member functions

The following member functions can be used on a user database.

Server functions

The following member functions require a connection to the server database. The above functions can be used on a server database as well, but as the server database make use of private data structures and does not have any type or field indices it is difficult to access the data directly.