Nebula
Loading...
Searching...
No Matches
sqlite3database.h
Go to the documentation of this file.
1#pragma once
2#ifndef DB_SQLITE3DATABASE_H
3#define DB_SQLITE3DATABASE_H
4//------------------------------------------------------------------------------
14#include "core/config.h"
15#include "attr/attribute.h"
16#include "db/database.h"
17#include "sqlite3.h"
18
19//------------------------------------------------------------------------------
20namespace Attr
21{
22 // some SQLite-internal names
23 DeclareString(name, 'name', ReadOnly);
24 DeclareString(type, 'type', ReadOnly);
25 DeclareInt(cid, 'cid_', ReadOnly);
26 DeclareInt(notnull, 'ntnl', ReadOnly);
27 DeclareBlob(dflt_value, 'dflv', ReadOnly);
28 DeclareBool(pk, 'pk__', ReadOnly);
29 DeclareInt(seq, 'seq_', ReadOnly);
30 DeclareBool(unique, 'uniq', ReadOnly);
31 DeclareInt(seqno, 'sqno', ReadOnly);
32}
33
34//------------------------------------------------------------------------------
35namespace Db
36{
38{
40public:
43 {
46 };
47
51 virtual ~Sqlite3Database();
52
54 void SetCacheNumPages(SizeT numCachePages);
56 SizeT GetCacheNumPages() const;
58 void SetTempStore(TempStore s);
60 TempStore GetTempStore() const;
62 void SetSynchronousMode(bool b);
64 bool GetSynchronousMode() const;
66 void SetBusyTimeout(int ms);
68 int GetBusyTimeout() const;
69
71 virtual bool Open();
73 virtual void Close();
74
76 virtual bool AttachDatabase(const IO::URI& uri, const Util::String& dbName);
78 virtual void DetachDatabase(const Util::String& dbName);
80 virtual void BeginTransaction();
82 virtual void EndTransaction();
83
85 sqlite3* GetSqliteHandle() const;
86
88 virtual void CopyInMemoryDatabaseToFile(const IO::URI& fileUri);
89
90private:
92 void ReadTableLayouts();
94 void RegisterAttributes(Ptr<Table>& attrTable);
95
100 sqlite3* sqliteHandle;
103};
104
105//------------------------------------------------------------------------------
108inline sqlite3*
110{
111 n_assert(0 != this->sqliteHandle);
112 return this->sqliteHandle;
113}
114
115//------------------------------------------------------------------------------
118inline void
120{
121 n_assert(!this->IsOpen());
122 n_assert(p > 0);
123 this->cacheNumPages = p;
124}
125
126//------------------------------------------------------------------------------
129inline SizeT
131{
132 return this->cacheNumPages;
133}
134
135//------------------------------------------------------------------------------
138inline void
143
144//------------------------------------------------------------------------------
149{
150 return this->tempStore;
151}
152
153//------------------------------------------------------------------------------
156inline void
158{
159 this->syncMode = b;
160}
161
162//------------------------------------------------------------------------------
165inline bool
167{
168 return this->syncMode;
169}
170
171//------------------------------------------------------------------------------
174inline void
176{
177 this->busyTimeout = ms;
178}
179
180//------------------------------------------------------------------------------
183inline int
185{
186 return this->busyTimeout;
187}
188
189} // namespace Db
190//------------------------------------------------------------------------------
191#endif
192
#define DeclareString(NAME, FOURCC, ACCESSMODE)
Definition attributedefinition.h:94
#define DeclareBool(NAME, FOURCC, ACCESSMODE)
Definition attributedefinition.h:78
#define DeclareBlob(NAME, FOURCC, ACCESSMODE)
Definition attributedefinition.h:106
#define DeclareInt(NAME, FOURCC, ACCESSMODE)
Definition attributedefinition.h:54
Wraps an entire database into a C++ object.
Definition database.h:30
IO::URI uri
Definition database.h:106
bool IsOpen() const
return true if database is open
Definition database.h:154
SQLite3 implementation of Db::Database.
Definition sqlite3database.h:38
sqlite3 * sqliteHandle
Definition sqlite3database.h:100
virtual void EndTransaction()
end a transaction on the database
Definition sqlite3database.cc:249
virtual void Close()
close the database
Definition sqlite3database.cc:206
TempStore
temporary storage location
Definition sqlite3database.h:43
@ File
Definition sqlite3database.h:44
@ Memory
Definition sqlite3database.h:45
virtual ~Sqlite3Database()
destructor
Definition sqlite3database.cc:52
int busyTimeout
Definition sqlite3database.h:99
Sqlite3Database()
constructor
Definition sqlite3database.cc:39
Ptr< Command > endTransactionCmd
Definition sqlite3database.h:102
TempStore tempStore
Definition sqlite3database.h:97
virtual void DetachDatabase(const Util::String &dbName)
detach an attached database
Definition sqlite3database.cc:392
Ptr< Command > beginTransactionCmd
Definition sqlite3database.h:101
int GetBusyTimeout() const
get busy timeout in milliseconds
Definition sqlite3database.h:184
void SetCacheNumPages(SizeT numCachePages)
set the SQLite3 database cache size in number of pages
Definition sqlite3database.h:119
SizeT GetCacheNumPages() const
get SQLite3 database cache size
Definition sqlite3database.h:130
bool GetSynchronousMode() const
get synchronous mode
Definition sqlite3database.h:166
void RegisterAttributes(Ptr< Table > &attrTable)
dynamically register attributes from special _Attributes db table
Definition sqlite3database.cc:269
void SetSynchronousMode(bool b)
synchronous mode on/off
Definition sqlite3database.h:157
SizeT cacheNumPages
Definition sqlite3database.h:96
__DeclareClass(Sqlite3Database)
virtual void BeginTransaction()
begin a transaction on the database
Definition sqlite3database.cc:234
void ReadTableLayouts()
read table layouts from database
Definition sqlite3database.cc:307
void SetTempStore(TempStore s)
set temporary storage location
Definition sqlite3database.h:139
sqlite3 * GetSqliteHandle() const
get the SQLite database handle
Definition sqlite3database.h:109
virtual bool Open()
open the database
Definition sqlite3database.cc:64
virtual void CopyInMemoryDatabaseToFile(const IO::URI &fileUri)
copy in memory database to file
Definition sqlite3database.cc:411
TempStore GetTempStore() const
get temporary storage location
Definition sqlite3database.h:148
virtual bool AttachDatabase(const IO::URI &uri, const Util::String &dbName)
attach another database to the current database
Definition sqlite3database.cc:355
void SetBusyTimeout(int ms)
set busy timeout in milliseconds (default is 100, 0 disabled busy handling)
Definition sqlite3database.h:175
bool syncMode
Definition sqlite3database.h:98
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
#define n_assert(exp)
Definition debug.h:50
Nebula compiler specific defines and configuration.
Definition accessmode.h:13
@ ReadOnly
Definition accessmode.h:16
Definition column.cc:10
Nebula's universal string class.
Definition string.h:50
int SizeT
Definition types.h:49