34. SQLite API -
Opening a connection
#import "sqlite3.h"
35. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
36. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
37. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
38. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
[NSException raise:@"SQLITE ERROR"
39. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
[NSException raise:@"SQLITE ERROR"
format:@"Error %d", result];
40. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
[NSException raise:@"SQLITE ERROR"
format:@"Error %d", result];
}
41. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
[NSException raise:@"SQLITE ERROR"
format:@"Error %d", result];
}
//later
42. SQLite API -
Opening a connection
#import "sqlite3.h"
sqlite3 *db;
int result = sqlite3_open(PATH, &db);
if (result != SQLITE_OK) {
[NSException raise:@"SQLITE ERROR"
format:@"Error %d", result];
}
//later
sqlite3_close(db);
118. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
119. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
120. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
121. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
122. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
123. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
124. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
125. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
126. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
127. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
128. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b) values (?, ?)" ,
129. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b) values (?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
130. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b) values (?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
[NSNumber numberWithInt:i]];
131. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b) values (?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
[NSNumber numberWithInt:i]];
}
132. FMDB Usage
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open])
NSLog(@"Could not open db.");
[db executeUpdate:@"blah blah blah"];
if ([db hadError])
NSLog(@"Err %d: %@", [db lastErrorCode],
[db lastErrorMessage]);
[db executeUpdate:@"create table test (a text, b integer)"];
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b) values (?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
[NSNumber numberWithInt:i]];
}
[db commit];