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
|
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
|
-
+
-
+
-
+
-
+
|
SL3Connection *_conn;
SL3PreparedStatement *_nextBatchSetStatement, *_nextBatchGetStatement;
SL3PreparedStatement *_joinedRoomsAddStatement;
SL3PreparedStatement *_joinedRoomsRemoveStatement;
SL3PreparedStatement *_joinedRoomsGetStatement;
}
+ (instancetype)storageWithPath: (OFString *)path
+ (instancetype)storageWithIRI: (OFIRI *)IRI
{
return [[[self alloc] initWithPath: path] autorelease];
return [[[self alloc] initWithIRI: IRI] autorelease];
}
- (instancetype)initWithPath: (OFString *)path
- (instancetype)initWithIRI: (OFIRI *)IRI
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
_conn = [[SL3Connection alloc] initWithPath: path];
_conn = [[SL3Connection alloc] initWithIRI: IRI];
[self createTables];
_nextBatchSetStatement = [[_conn prepareStatement:
@"INSERT OR REPLACE INTO next_batch (\n"
@" device_id, next_batch\n"
@") VALUES (\n"
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
-
+
|
@"$device_id": deviceID
}];
if (![_nextBatchGetStatement step])
return nil;
OFString *nextBatch =
[_nextBatchGetStatement.rowDictionary[@"next_batch"] retain];
[_nextBatchGetStatement.currentRowDictionary[@"next_batch"] retain];
objc_autoreleasePoolPop(pool);
return [nextBatch autorelease];
}
- (void)addJoinedRoom: (OFString *)roomID forUser: (OFString *)userID
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
+
|
void *pool = objc_autoreleasePoolPush();
[_joinedRoomsGetStatement reset];
[_joinedRoomsGetStatement bindWithDictionary: @{ @"$user_id": userID }];
while ([_joinedRoomsGetStatement step])
[joinedRooms addObject:
_joinedRoomsGetStatement.rowDictionary[@"room_id"]];
_joinedRoomsGetStatement.currentRowDictionary[@"room_id"]];
objc_autoreleasePoolPop(pool);
return [joinedRooms autorelease];
}
@end
|