-
Notifications
You must be signed in to change notification settings - Fork 1
/
SLDatabase.m
80 lines (53 loc) · 1.24 KB
/
SLDatabase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// SLDatabase.m
//
// Copyright 2008 Steven Fisher.
//
// This file is covered by the MIT/X11 License.
// See LICENSE.TXT for more information.
//
#import "SLDatabase.h"
#import "SLStmt.h"
@implementation SLDatabase
@synthesize extendedErr, dtbs;
@dynamic simpleErr;
- (int)simpleErr;
{
return extendedErr & 0xFF;
}
- (void)setResult: (int)inErr;
{
extendedErr = inErr;
msg = sqlite3_errmsg(dtbs);
if ( ( extendedErr != SQLITE_OK ) && ( self.simpleErr < 100 ) )
NSLog( @"SLDatabase: (%d) %s", extendedErr, msg );
}
+ (id)databaseWithPath: (NSString *)inPath;
{
return [[[self alloc] initWithPath:inPath] autorelease];
}
- (id)initWithPath: (NSString *)inPath;
{
self = [super init];
if (!self) return self;
[self setResult: sqlite3_open([inPath UTF8String], &dtbs)];
sqlite3_extended_result_codes( dtbs, TRUE );
return self;
}
- (void)dealloc;
{
int theErr = sqlite3_close( dtbs );
if ( theErr != SQLITE_OK )
NSLog( @"Error %d while closing database.", theErr );
[super dealloc];
}
- (BOOL)execSQL: (NSString *)inSQL;
{
[self setResult: sqlite3_exec(dtbs, [inSQL UTF8String], NULL, NULL, NULL)];
return (extendedErr == SQLITE_OK);
}
- (long long)lastInserted;
{
return sqlite3_last_insert_rowid(dtbs);
}
@end