-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlite.m
134 lines (97 loc) · 2.26 KB
/
Sqlite.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Sqlite.m
//
// Sqlite Objective C wrapper by Stephen Anderson is licensed under
// a Creative Commons Attribution-ShareAlike 3.0 Unported License.
// Permissions beyond the scope of this license may be available at
// ruralcoder.com.
#import "Sqlite.h"
#import "SqliteQuery.h"
@implementation Sqlite
- (id) initWithFilename:(NSString*) databaseFilename
{
if (self = [super init])
{
int status = sqlite3_open_v2([databaseFilename UTF8String], &database, SQLITE_OPEN_READONLY, NULL);
if (status != SQLITE_OK)
return nil;
}
return self;
}
- (id) initWithFilename:(NSString*) databaseFilename readOnly:(BOOL)readOnly
{
if (self = [super init])
{
int mode = (readOnly) ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
int status = sqlite3_open_v2([databaseFilename UTF8String], &database, mode, NULL);
if (status != SQLITE_OK)
return nil;
}
return self;
}
- (SqliteCodes) close
{
return sqlite3_close(database);
}
- (SqliteCodes) threadSafe
{
return sqlite3_threadsafe();
}
- (SqliteCodes) extendedResultCodes:(BOOL)enable
{
return sqlite3_extended_result_codes(database, enable);
}
- (sqlite3_int64) lastInsertRowId
{
return sqlite3_last_insert_rowid(database);
}
- (SqliteCodes) changes
{
return sqlite3_changes(database);
}
- (SqliteCodes) totalChanges
{
return sqlite3_total_changes(database);
}
- (void) interrupt
{
sqlite3_interrupt(database);
}
- (SqliteCodes) complete:(NSString*)sql
{
return sqlite3_complete([sql UTF8String]);
}
- (SqliteCodes) busyTimeout:(NSInteger)milliseconds
{
return sqlite3_busy_timeout(database, milliseconds);
}
//- (SqliteCodes) getTable;
//- (SqliteCodes) freeTable;
- (NSInteger) errorCode
{
return sqlite3_errcode(database);
}
- (NSInteger) extendedErrorCode
{
return sqlite3_extended_errcode(database);
}
- (NSString*) errorMessage
{
return [NSString stringWithUTF8String:sqlite3_errmsg(database)];
}
- (SqliteCodes) limit:(NSInteger)identifier value:(NSInteger)value
{
return sqlite3_limit(database, identifier, value);
}
- (SqliteQuery*) queryWithStatement:(NSString*)sqlQuery
{
SqliteQuery *query = [[[SqliteQuery alloc] initWithStatement:sqlQuery database:database] autorelease];
return query;
}
- (void) dealloc
{
[self close];
database = nil;
[super dealloc];
}
@end