Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database.cpp
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//
3// This code was automatically generated by the joedb compiler
4// https://www.joedb.org/
5//
6// Path to compiler: /home/rcoulom/repos/joedb/doc/source/tutorial/build/joedbc
7// Version: 9.1.4
8// joedbc compilation time: Apr 15 2025 14:46:29
9// Generation of this file: 2025-04-15 12:46:31 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#include "Writable_Database.h"
13#include "joedb/Writable.h"
15
16#include <ctime>
17
19{
20 ////////////////////////////////////////////////////////////////////////////
21 void Writable_Database::write_comment(const std::string &comment)
22 ////////////////////////////////////////////////////////////////////////////
23 {
24 journal.comment(comment);
25 }
26
27 ////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////
30 {
31 journal.timestamp(std::time(nullptr));
32 }
33
34 ////////////////////////////////////////////////////////////////////////////
35 void Writable_Database::write_timestamp(int64_t timestamp)
36 ////////////////////////////////////////////////////////////////////////////
37 {
38 journal.timestamp(timestamp);
39 }
40
41 ////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////
44 {
45 journal.valid_data();
46 }
47
48 ////////////////////////////////////////////////////////////////////////////
49 void Writable_Database::play_journal()
50 ////////////////////////////////////////////////////////////////////////////
51 {
52 max_record_id = size_t(journal.get_checkpoint_position());
53 ready_to_write = false;
54 journal.play_until_checkpoint(*this);
55 ready_to_write = true;
56 max_record_id = 0;
57 }
58
59 ////////////////////////////////////////////////////////////////////////////
60 void Writable_Database::auto_upgrade()
61 ////////////////////////////////////////////////////////////////////////////
62 {
63 const size_t file_schema_size = size_t(schema_file.get_size());
64
65 if (file_schema_size < detail::schema_string_size)
66 {
67 journal.comment("Automatic schema upgrade");
68
69 joedb::Readonly_Memory_File schema_file(detail::schema_string, detail::schema_string_size);
71
72 schema_journal.set_position(int64_t(file_schema_size));
73 schema_journal.play_until(journal, detail::schema_string_size);
74
75 schema_journal.set_position(int64_t(file_schema_size));
76 upgrading_schema = true;
77 schema_journal.play_until(*this, detail::schema_string_size);
78 upgrading_schema = false;
79
80 journal.valid_data();
81 }
82 }
83
84 ////////////////////////////////////////////////////////////////////////////
85 Writable_Database::Writable_Database
86 ////////////////////////////////////////////////////////////////////////////
87 (
89 bool perform_initialization,
91 joedb::Commit_Level commit_level
92 ):
93 journal(file, check, commit_level)
94 {
95 journal.rewind();
96
97 if (perform_initialization)
98 initialize();
99 }
100
101 ////////////////////////////////////////////////////////////////////////////
102 Writable_Database::Writable_Database
103 ////////////////////////////////////////////////////////////////////////////
104 (
107 joedb::Commit_Level commit_level
108 ):
109 Writable_Database(file, true, check, commit_level)
110 {
111 }
112
113 ////////////////////////////////////////////////////////////////////////////
114 void Writable_Database::check_single_row()
115 ////////////////////////////////////////////////////////////////////////////
116 {
117 }
118
119 /////////////////////////////////////////////////////////////////////////////
121 /////////////////////////////////////////////////////////////////////////////
122 {
123 while (!get_buffer_table().is_empty())
125 }
126}
int64_t get_size() const override
Definition Memory_File.h:24
void play_until(Writable &writable, int64_t end)
void set_position(int64_t position)
int64_t get_checkpoint_position() const
void play_until_checkpoint(Writable &writable)
void timestamp(int64_t timestamp) final
void comment(const std::string &comment) final
joedb::Writable_Journal schema_journal
Definition Database.h:381
container_of_buffer get_buffer_table() const
Definition Database.h:577
void timestamp(int64_t timestamp) override
Definition Database.h:376
joedb::Memory_File schema_file
Definition Database.h:380
void comment(const std::string &comment) override
Definition Database.h:375
A writable Database constructed from a writable joedb::Buffered_File.
void write_comment(const std::string &comment)
Automatically generated by joedbc.
Definition Client.h:19
Commit_Level
Definition Writable.h:13