Permalink
Browse files

pragmas are confusing.

  • Loading branch information...
1 parent d065d5e commit 1777d2e981f69d52942692184bf096e143fe4d94 @ccgus committed Jul 4, 2012
Showing with 19 additions and 1 deletion.
  1. +1 −1 README.markdown
  2. +18 −0 src/fmdb.m
View
@@ -42,7 +42,7 @@ Before you can interact with the database, it must be opened. Opening fails if
### Executing Updates
-Any sort of SQL statement which is not a `SELECT` statement qualifies as an update. This includes `CREATE`, `PRAGMA`, `UPDATE`, `INSERT`, `ALTER`, `COMMIT`, `BEGIN`, `DETACH`, `DELETE`, `DROP`, `END`, `EXPLAIN`, `VACUUM`, and `REPLACE` statements (plus many more). Basically, if your SQL statement does not begin with `SELECT`, it is an update statement.
+Any sort of SQL statement which is not a `SELECT` statement qualifies as an update. This includes `CREATE`, `UPDATE`, `INSERT`, `ALTER`, `COMMIT`, `BEGIN`, `DETACH`, `DELETE`, `DROP`, `END`, `EXPLAIN`, `VACUUM`, and `REPLACE` statements (plus many more). Basically, if your SQL statement does not begin with `SELECT`, it is an update statement.
Executing updates returns a single value, a `BOOL`. A return value of `YES` means the update was successfully executed, and a return value of `NO` means that some error was encountered. You may invoke the `-lastErrorMessage` and `-lastErrorCode` methods to retrieve more information.
View
@@ -69,6 +69,24 @@ int main (int argc, const char * argv[]) {
FMDBQuickCheck(([db boolForQuery:@"SELECT ? not null", [NSData data]]));
+
+ // how do we do pragmas? Like so:
+ FMResultSet *ps = [db executeQuery:@"PRAGMA journal_mode=delete"];
+ FMDBQuickCheck(![db hadError]);
+ FMDBQuickCheck(ps);
+ FMDBQuickCheck([ps next]);
+ [ps close];
+
+ // oh, but some pragmas require updates?
+ [db executeUpdate:@"PRAGMA page_size=2048"];
+ FMDBQuickCheck(![db hadError]);
+
+ // what about a vacuum?
+ [db executeUpdate:@"vacuum"];
+ FMDBQuickCheck(![db hadError]);
+
+ exit(0);
+
// but of course, I don't bother checking the error codes below.
// Bad programmer, no cookie.

0 comments on commit 1777d2e

Please sign in to comment.