MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / DatabaseConnection

Method DatabaseConnection

sql/databaseconnection.cpp:33–94  ·  view source on GitHub ↗

This class is used to connect to the database.

Source from the content-addressed store, hash-verified

31//* database.
32//*****************************************
33DatabaseConnection::DatabaseConnection(QString connection)
34{
35 dbLocked = Unlocked;
36 this->connection = connection;
37 QLOG_DEBUG() << "SQL drivers available: " << QSqlDatabase::drivers();
38 QLOG_TRACE() << "Adding database SQLITE";
39 conn = QSqlDatabase::addDatabase("QSQLITE", connection);
40 QLOG_TRACE() << "Setting DB name";
41 conn.setDatabaseName(global.fileManager.getDbDirPath("nixnote.db"));
42 QLOG_TRACE() << "Opening database";
43 if (!conn.open()) {
44 QLOG_ERROR() << "Error opening database: " << conn.lastError();
45 exit(16);
46 }
47
48 if (connection == "nixnote")
49 global.db = this;
50 QLOG_TRACE() << "Preparing tables";
51 // Start preparing the tables
52 configStore = new ConfigStore(this);
53 dataStore = new DataStore(this);
54
55 NSqlQuery tempTable(this);
56// tempTable.exec("pragma cache_size=8096");
57// tempTable.exec("pragma page_size=8096");
58 tempTable.exec("pragma busy_timeout=50000");
59 tempTable.exec("pragma journal_mode=wal");
60
61// tempTable.exec("pragma SQLITE_THREADSAFE=2");
62 if (connection == "nixnote") {
63 tempTable.exec("pragma COMPILE_OPTIONS");
64 QLOG_DEBUG() << "*** SQLITE COMPILE OPTIONS ***";
65 while (tempTable.next()) {
66 QLOG_DEBUG() << tempTable.value(0).toString();
67 }
68
69 int value = global.getDatabaseVersion();
70 if (value < 2){
71 QLOG_DEBUG() << "*****************";
72 QLOG_DEBUG() << "Upgrading Database";
73 DatabaseUpgrade dbu;
74 dbu.fixSql();
75 }
76 global.setDatabaseVersion(2);
77
78 // Get username to use for default notes. This needs to be done after
79 // the database is started because we set it by default to the usertable
80 // username.
81 global.full_username = global.getUsername();
82
83 }
84
85 QLOG_TRACE() << "Creating filter table";
86 tempTable.exec("Create table if not exists filter (lid integer)");
87 tempTable.exec("delete from filter");
88 QLOG_TRACE() << "Adding to filter table";
89 tempTable.exec("insert into filter select distinct lid from NoteTable;");
90 QLOG_TRACE() << "Addition complete";

Callers

nothing calls this directly

Calls 9

getDbDirPathMethod · 0.80
openMethod · 0.80
valueMethod · 0.80
getDatabaseVersionMethod · 0.80
fixSqlMethod · 0.80
setDatabaseVersionMethod · 0.80
getUsernameMethod · 0.80
execMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected