You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-12Lines changed: 27 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,20 +82,20 @@ Prepared Statements
82
82
It is possible to retain and reuse statments this will keep the query plan and in case of an complex query or many uses might increase the performance significantly.
83
83
84
84
```c++
85
-
86
85
database db(":memory:");
87
86
88
87
// if you use << on a sqlite::database you get a prepared statment back
89
88
// this will not be executed till it gets destroyed or you execute it explicitly
90
-
auto ps = db << "select ?,? "; // get a prepared parsed and ready statment
89
+
auto ps = db << "select a,b from table where something = ? and anotherthing = ?"; // get a prepared parsed and ready statment
91
90
92
91
// first if needed bind values to it
93
92
ps << 5;
94
93
int tmp = 8;
95
94
ps << tmp;
96
95
97
-
// now you can execute it, if the statment was executed once it will not be executed again when it goes out of scope.
98
-
// But beware that it will if it wasn't executed!
96
+
// now you can execute it with `operator>>` or `execute()`.
97
+
// If the statment was executed once it will not be executed again when it goes out of scope.
98
+
// But beware that it will execute on destruction if it wasn't executed!
99
99
ps >> [&](int a,int b){ ... };
100
100
101
101
// after a successfull execution the statment needs to be reset to be execute again. This will reset the bound values too!
@@ -108,7 +108,7 @@ It is possible to retain and reuse statments this will keep the query plan and i
108
108
ps++;
109
109
110
110
// To disable the execution of a statment when it goes out of scope and wasn't used
111
-
ps.set_used(true); // or false if you want it to execute even if it was used
111
+
ps.used(true); // or false if you want it to execute even if it was used
112
112
113
113
// Usage Example:
114
114
@@ -124,15 +124,30 @@ Shared Connections
124
124
=====
125
125
If you need the handle to the database connection to execute sqlite3 commands directly you can get a managed shared_ptr to it, so it will not close as long as you have a referenc to it.
126
126
127
+
Take this example on how to deal with a database backup using SQLITEs own functions in a save and modern way.
127
128
```c++
128
-
sqlite::connection_type con;
129
-
130
-
{ // scope of our db object
131
-
database db(":memory:"); // Make a connection and create in memory db
132
-
con = db.get_sqlite3_connection();
133
-
} // here the temporary db would be lost but we still have the connection for our direct API calls
129
+
try {
130
+
database backup("backup"); //Open the database file we want to backup to
134
131
135
-
database db2(con); // or we can even make a new database object from it
132
+
auto con = db.connection(); // get a handle to the DB we want to backup in our scope
133
+
// this way we are sure the DB is open and ok while we backup
134
+
135
+
// Init Backup and make sure its freed on exit or exceptions!
0 commit comments