ObjMatrix  Check-in [f599dcefbe]

Overview
Comment:Adjust to ObjSQLite3 changes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f599dcefbe494390a5babff9fc664f2f0ce08dd5bd6319a220ced3d3b17cce45
User & Date: js on 2024-08-11 15:37:57
Other Links: manifest | tags
Context
2024-08-11
15:38
Update URLs in GitHub issue template check-in: 33ca8aea88 user: js tags: trunk
15:37
Adjust to ObjSQLite3 changes check-in: f599dcefbe user: js tags: trunk
09:46
README.md: Fix code blocks check-in: 212ebfd3b7 user: js tags: trunk
Changes

Modified src/MTXSQLite3Storage.h from [c5ea1293d1] to [70e9916f01].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * @brief SQLite3-based storage for @ref MTXClient.
 */
@interface MTXSQLite3Storage: OFObject <MTXStorage>
/**
 * @brief Creates a new SQLite3-based storage for @ref MTXClient.
 *
 * @param path The path for the SQLite3 database
 * @return An autoreleased MTXSQLite3Storage
 */
+ (instancetype)storageWithPath: (OFString *)path;

/**
 * @brief Initializes an already allocated MTXSQLite3Storage.
 *
 * @param path The path for the SQLite3 database
 * @return An initialized MTXSQLite3Storage
 */
- (instancetype)initWithPath: (OFString *)path OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







|


|




|


|



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * @brief SQLite3-based storage for @ref MTXClient.
 */
@interface MTXSQLite3Storage: OFObject <MTXStorage>
/**
 * @brief Creates a new SQLite3-based storage for @ref MTXClient.
 *
 * @param IRI The IRI for the SQLite3 database
 * @return An autoreleased MTXSQLite3Storage
 */
+ (instancetype)storageWithIRI: (OFIRI *)IRI;

/**
 * @brief Initializes an already allocated MTXSQLite3Storage.
 *
 * @param IRI The IRI for the SQLite3 database
 * @return An initialized MTXSQLite3Storage
 */
- (instancetype)initWithIRI: (OFIRI *)IRI OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/MTXSQLite3Storage.m from [bf3c6ee0fb] to [cd6b37a0a1].

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
{
	return [[[self alloc] initWithPath: path] autorelease];
}

- (instancetype)initWithPath: (OFString *)path
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		_conn = [[SL3Connection alloc] initWithPath: path];

		[self createTables];

		_nextBatchSetStatement = [[_conn prepareStatement:
		    @"INSERT OR REPLACE INTO next_batch (\n"
		    @"    device_id, next_batch\n"
		    @") VALUES (\n"







|

|


|






|







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)storageWithIRI: (OFIRI *)IRI
{
	return [[[self alloc] initWithIRI: IRI] autorelease];
}

- (instancetype)initWithIRI: (OFIRI *)IRI
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		_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
		@"$device_id": deviceID
	}];

	if (![_nextBatchGetStatement step])
		return nil;

	OFString *nextBatch =
	    [_nextBatchGetStatement.rowDictionary[@"next_batch"] retain];

	objc_autoreleasePoolPop(pool);

	return [nextBatch autorelease];
}

- (void)addJoinedRoom: (OFString *)roomID forUser: (OFString *)userID







|







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.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
	void *pool = objc_autoreleasePoolPush();

	[_joinedRoomsGetStatement reset];
	[_joinedRoomsGetStatement bindWithDictionary: @{ @"$user_id": userID }];

	while ([_joinedRoomsGetStatement step])
		[joinedRooms addObject:
		    _joinedRoomsGetStatement.rowDictionary[@"room_id"]];

	objc_autoreleasePoolPop(pool);

	return [joinedRooms autorelease];
}
@end







|






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.currentRowDictionary[@"room_id"]];

	objc_autoreleasePoolPop(pool);

	return [joinedRooms autorelease];
}
@end

Modified tests/Tests.m from [87e53c2ee0] to [c73d417318].

41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
		[OFStdErr writeString: @"Please set OBJMATRIX_USER, "
				       @"OBJMATRIX_PASS and OBJMATRIX_HS in "
				       @"the environment!\n"];
		[OFApplication terminateWithStatus: 1];
	}

	OFIRI *homeserver = [OFIRI IRIWithString: environment[@"OBJMATRIX_HS"]];

	id <MTXStorage> storage =
	    [MTXSQLite3Storage storageWithPath: @"tests.db"];
	[MTXClient logInWithUser: environment[@"OBJMATRIX_USER"]
			password: environment[@"OBJMATRIX_PASS"]
		      homeserver: homeserver
			 storage: storage
			   block: ^ (MTXClient *client, id exception) {
		if (exception != nil) {
			OFLog(@"Error logging in: %@", exception);







>

|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
		[OFStdErr writeString: @"Please set OBJMATRIX_USER, "
				       @"OBJMATRIX_PASS and OBJMATRIX_HS in "
				       @"the environment!\n"];
		[OFApplication terminateWithStatus: 1];
	}

	OFIRI *homeserver = [OFIRI IRIWithString: environment[@"OBJMATRIX_HS"]];
	OFIRI *storageIRI = [OFIRI fileIRIWithPath: @"tests.db"];
	id <MTXStorage> storage =
	    [MTXSQLite3Storage storageWithIRI: storageIRI];
	[MTXClient logInWithUser: environment[@"OBJMATRIX_USER"]
			password: environment[@"OBJMATRIX_PASS"]
		      homeserver: homeserver
			 storage: storage
			   block: ^ (MTXClient *client, id exception) {
		if (exception != nil) {
			OFLog(@"Error logging in: %@", exception);