Skip to content

Commit 3a387aa

Browse files
committed
Update README.md
1 parent 7c85a24 commit 3a387aa

File tree

1 file changed

+133
-133
lines changed

1 file changed

+133
-133
lines changed

README.md

Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4,141 +4,12 @@ It simplyfies the C API by using BLOBs as vectors and TEXT as strings and makes
44
To provide a single versioned library the SQLite3 is included in the SQLite3 folder and updated when necessary.
55

66

7-
## Classes
8-
9-
### field_type
10-
This class represents a singe result field (column field of a row).
11-
12-
SQLite has 5 data types:
13-
| SQLite3 type | sqlitepp type |
14-
|--------------|---------------|
15-
| INTEGER | `std::int64_t` |
16-
| FLOAT | `double` |
17-
| TEXT | `std::string` |
18-
| BLOB | `std::vector<std::uint8_t>` |
19-
| NULL | internally handled, checked by `is_null()` |
20-
21-
Use these sqlitepp types when accessing result fields.
22-
There is an automatic type conversion/cast:
23-
```c++
24-
int i = row["num"]; // get data of num field (INTEGER) as integer
25-
std::string s = row["num"]; // get data of num field (INTEGER) as string
26-
double d = row["flo"]; // get data of flo field (FLOAT) as double
27-
// CAUTION:
28-
int f = row["flo"]; // ERROR: integer result flo field (FLOAT) is not defined/set!
29-
```
30-
31-
Methods of `field_type` are:
32-
33-
`name()`
34-
Returns the name of the field column.
35-
36-
`type()`
37-
Returns the field type as sqlite3 type definition (SQLITE_INTEGER, SQLITE_TEXT etc.)
38-
39-
`is_null()`
40-
Returns true if the field is NULL.
41-
42-
43-
### row
44-
This class represents a single result row.
45-
Fields can be accessed via the `[]` operator by their numeric column index or by their column name.
46-
Access by name is slower, because of the name lookup.
47-
48-
All std::vector operations are valid, because `row` is a std::vector of `field_type`.
49-
50-
Methods of `row` are:
51-
52-
`operator[](size_type idx)`
53-
Access the field by its index position in the row.
54-
55-
`operator[](const char* colname)`
56-
Access the field by its column name.
57-
58-
`num_fields()`
59-
Returns the field count of the row. (A wrapper for size())
60-
61-
62-
### result
63-
This class is a std::vector of `row`. It represents a complete result set.
64-
65-
Methods of `result` are:
66-
67-
`num_rows()`
68-
Returns the number of rows of the result. (A wrapper for size())
69-
70-
71-
### db
72-
Main class that holds the sqlite3 object, which can be accessed via `get()` or, even shorter, via the `()` operator.
73-
74-
Methods of `db` are:
75-
76-
`db(name, initial_open = true, flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)`
77-
Ctor which creates and optionally opens the database.
78-
79-
`open(flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)`
80-
Opens the database with the apropriate access flags.
81-
82-
`close()`
83-
Closes the db. The db is automatically closed when db goes out of scope.
84-
85-
`version()`
86-
Returns the version of the SQLite3 database as string.
87-
88-
`vacuum()`
89-
Executes the SQLite VACUUM command for database defragmentation.
90-
91-
92-
### query
93-
Class for query assembly and execution.
94-
The `<<` operator can add query parts or bind BLOB and TEXT data.
95-
96-
`exec()`
97-
Executes the query and returns only the execution status. This can be used for commands like UPDATE or DELETE.
98-
99-
`use()`
100-
Executes the query and returns the first row of the result set. This can be uses if only one row is needed or to get the result set row by row.
101-
Repeatly call `use_next()` until `use_next()` returns an empty row or call `use_abort()` before.
102-
103-
`use_next()`
104-
Returns the next row of the `use()` function.
105-
An empty row is returned if no further rows exist.
106-
107-
`use_abort()`
108-
Aborts `use()`/`use_next()` sequence before `use_next()` finished (returned an empty row).
109-
This is a **MANDATORY** call if `use()`/`use_next()` need to be aborted.
110-
111-
`store()`
112-
Executes the query and returns the complete result as result object.
113-
114-
`bind()`
115-
Binds the given vector or string to the according params.
116-
CAUTION: The vector or string must be constant until end of query execution!
117-
The vector/string is internally not copied!
118-
119-
120-
### transaction
121-
The `transaction` class simplifies begin, commit and rollback of transactions.
122-
`begin()` is called by class ctor, so an explicit `begin()` isn't necessary.
123-
124-
Methods are:
125-
126-
`begin()`
127-
Begin the transaction with the according level flags. Default is deferred.
128-
129-
`commit()`
130-
Commit the transaction.
131-
132-
`rollback()`
133-
Rollback the transaction. Rollback is called by the dtor when transaction object goes out of scope.
134-
135-
1367
## Usage
137-
Here are some examples how to use sqlitepp:
8+
This are examples how to use sqlitepp.
1389

13910
Create and open the database by its filename:
14011
```c++
141-
sqlitepp::db db(TEST_DB);
12+
sqlitepp::db db("D:/test.sqlite");
14213
assert(db.is_open());
14314
```
14415
The following code asumes this db object.
@@ -195,7 +66,7 @@ All text and string values need to be in UTF-8 format in SQLite3.
19566
Storing a string in UTF-8 - here on a Windows platform with ATL conversion:
19667
```c++
19768
sqlitepp::query q(db);
198-
q << "INSERT INTO test(id, name) VALUES (13,'" << ATL::CT2CA(L"Schöne Grüße", CP_UTF8) << "')";
69+
q << "INSERT INTO test(id, name) VALUES (13,'" << ATL::CT2CA(L"Sch�ne Gr��e", CP_UTF8) << "')";
19970
int err = q.exec();
20071
```
20172

@@ -310,6 +181,135 @@ Rollback when the transaction goes out scope:
310181
```
311182

312183

184+
## Classes
185+
186+
### field_type
187+
This class represents a singe result field (column field of a row).
188+
189+
SQLite has 5 data types:
190+
191+
| SQLite3 type | sqlitepp type |
192+
|--------------|---------------|
193+
| INTEGER | `std::int64_t` |
194+
| FLOAT | `double` |
195+
| TEXT | `std::string` |
196+
| BLOB | `std::vector<std::uint8_t>` |
197+
| NULL | internally handled, checked by `is_null()` |
198+
199+
Use these sqlitepp types when accessing result fields.
200+
There is an automatic type conversion/cast:
201+
```c++
202+
int i = row["num"]; // get data of num field (INTEGER) as integer
203+
std::string s = row["num"]; // get data of num field (INTEGER) as string
204+
double d = row["flo"]; // get data of flo field (FLOAT) as double
205+
// CAUTION:
206+
int f = row["flo"]; // ERROR: integer result flo field (FLOAT) is not defined/set!
207+
```
208+
209+
Methods of `field_type` are:
210+
211+
`name()`
212+
Returns the name of the field column.
213+
214+
`type()`
215+
Returns the field type as sqlite3 type definition (SQLITE_INTEGER, SQLITE_TEXT etc.)
216+
217+
`is_null()`
218+
Returns true if the field is NULL.
219+
220+
221+
### row
222+
This class represents a single result row.
223+
Fields can be accessed via the `[]` operator by their numeric column index or by their column name.
224+
Access by name is slower, because of the name lookup.
225+
All std::vector operations are valid, because `row` is a std::vector of `field_type`.
226+
227+
Methods of `row` are:
228+
229+
`operator[](size_type idx)`
230+
Access the field by its index position in the row.
231+
232+
`operator[](const char* colname)`
233+
Access the field by its column name.
234+
235+
`num_fields()`
236+
Returns the field count of the row. (A wrapper for size())
237+
238+
239+
### result
240+
This class is a std::vector of `row`. It represents a complete result set.
241+
242+
Methods of `result` are:
243+
244+
`num_rows()`
245+
Returns the number of rows of the result. (A wrapper for size())
246+
247+
248+
### db
249+
Main class that holds the sqlite3 object, which can be accessed via `get()` or, even shorter, via the `()` operator.
250+
251+
Methods of `db` are:
252+
253+
`db(name, initial_open = true, flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)`
254+
Ctor which creates and optionally opens the database.
255+
256+
`open(flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)`
257+
Opens the database with the apropriate access flags.
258+
259+
`close()`
260+
Closes the db. The db is automatically closed when db goes out of scope.
261+
262+
`version()`
263+
Returns the version of the SQLite3 database as string.
264+
265+
`vacuum()`
266+
Executes the SQLite VACUUM command for database defragmentation.
267+
268+
269+
### query
270+
Class for query assembly and execution.
271+
The `<<` operator can add query parts or bind BLOB and TEXT data.
272+
273+
`exec()`
274+
Executes the query and returns only the execution status. This can be used for commands like UPDATE or DELETE.
275+
276+
`use()`
277+
Executes the query and returns the first row of the result set. This can be uses if only one row is needed or to get the result set row by row.
278+
Repeatly call `use_next()` until `use_next()` returns an empty row or call `use_abort()` before.
279+
280+
`use_next()`
281+
Returns the next row of the `use()` function.
282+
An empty row is returned if no further rows exist.
283+
284+
`use_abort()`
285+
Aborts `use()`/`use_next()` sequence before `use_next()` finished (returned an empty row).
286+
This is a **MANDATORY** call if `use()`/`use_next()` need to be aborted.
287+
288+
`store()`
289+
Executes the query and returns the complete result as result object.
290+
291+
`bind()`
292+
Binds the given vector or string to the according params.
293+
CAUTION: The vector or string must be constant until end of query execution!
294+
The vector/string is internally not copied!
295+
296+
297+
### transaction
298+
The `transaction` class simplifies begin, commit and rollback of transactions.
299+
`begin()` is called by class ctor, so an explicit `begin()` isn't necessary.
300+
301+
Methods are:
302+
303+
`begin()`
304+
Begin the transaction with the according level flags. Default is deferred.
305+
306+
`commit()`
307+
Commit the transaction.
308+
309+
`rollback()`
310+
Rollback the transaction. Rollback is called by the dtor when transaction object goes out of scope.
311+
312+
313313
## License
314-
sqlitepp is LGPLv3
314+
sqlitepp is LGPLv3
315315
SQLite3 is public domain

0 commit comments

Comments
 (0)