Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
file_tutorial.cpp
Go to the documentation of this file.
3
5
6/////////////////////////////////////////////////////////////////////////////
7static int file_tutorial_main(int argc, char **argv)
8/////////////////////////////////////////////////////////////////////////////
9{
10 const char * const file_name = "file_tutorial.joedb";
11
12 //
13 // Create a new database and write something
14 // (If a file already exists, it will fail)
15 //
16 {
18 db.new_city("Villeneuve d'Ascq");
19 db.checkpoint();
20 }
21
22 //
23 // Re-open the database and add one more city
24 // (If the file does not exist, it will fail)
25 //
26 {
28 db.new_city("Tombouctou");
29 db.checkpoint();
30 }
31
32 //
33 // Open the database read-only
34 //
35 {
36 tutorial::Readonly_Database db(file_name);
37 for (const auto city: db.get_city_table())
38 std::cout << db.get_name(city) << '\n';
39 }
40
41 return 0;
42}
43
44/////////////////////////////////////////////////////////////////////////////
45int main(int argc, char **argv)
46/////////////////////////////////////////////////////////////////////////////
47{
48 return joedb::main_exception_catcher(file_tutorial_main, argc, argv);
49}
Shortcut to directly build a Writable_Database from a file name.
Load a database from a read-only file.
int main()
@ create_new
fails if already exists, locks the file for writing
@ write_existing
fails if does not exist or locked, locks the file for writing
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.