ObjSQLite3  Check-in [7a52167702]

Overview
Comment:SL3PreparedStatement: Add -[row{Array,Dictionary}]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7a52167702278bdd7c5f3aac48771cba8ac5a77abfac4d1664b05a507fe8236e
User & Date: js on 2020-10-01 23:53:00
Other Links: manifest | tags
Context
2020-10-01
23:55
Fix automatically running tests check-in: 076176fd98 user: js tags: trunk
23:53
SL3PreparedStatement: Add -[row{Array,Dictionary}] check-in: 7a52167702 user: js tags: trunk
23:43
Add support for retrieving columns check-in: 727a6838a5 user: js tags: trunk
Changes

Modified src/SL3PreparedStatement.h from [b2196c1017] to [df54b678ff].

37
38
39
40
41
42
43

44
45
46
47

48
49
50
51
	sqlite3_stmt *_stmt;
}

- (void)bindWithArray: (OFArray *)array;
- (void)bindWithDictionary:
    (OFDictionary OF_GENERIC(OFString *, id) *)dictionary;
- (void)clearBindings;

- (id)objectForColumn: (size_t)column;
- (size_t)columnCount;
- (OFString *)nameForColumn: (size_t)column;
- (bool)step;

- (void)reset;
@end

OF_ASSUME_NONNULL_END







>



|
>




37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	sqlite3_stmt *_stmt;
}

- (void)bindWithArray: (OFArray *)array;
- (void)bindWithDictionary:
    (OFDictionary OF_GENERIC(OFString *, id) *)dictionary;
- (void)clearBindings;
- (bool)step;
- (id)objectForColumn: (size_t)column;
- (size_t)columnCount;
- (OFString *)nameForColumn: (size_t)column;
- (OFArray *)rowArray;
- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary;
- (void)reset;
@end

OF_ASSUME_NONNULL_END

Modified src/SL3PreparedStatement.m from [fdeb582274] to [94b4feb125].

212
213
214
215
216
217
218




























219
220
221
222
223
224
225
		@throw [OFOutOfRangeException exception];

	if ((name = sqlite3_column_name(_stmt, column)) == NULL)
		@throw [OFOutOfMemoryException exception];

	return [OFString stringWithUTF8String: name];
}





























- (void)reset
{
	int code = sqlite3_reset(_stmt);

	if (code != SQLITE_OK)
		@throw [SL3ResetStatementFailedException







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
		@throw [OFOutOfRangeException exception];

	if ((name = sqlite3_column_name(_stmt, column)) == NULL)
		@throw [OFOutOfMemoryException exception];

	return [OFString stringWithUTF8String: name];
}

- (OFArray *)rowArray
{
	size_t count = [self columnCount];
	OFMutableArray *array = [OFMutableArray arrayWithCapacity: count];

	for (size_t i = 0; i < count; i++)
		[array addObject: [self objectForColumn: i]];

	[array makeImmutable];

	return array;
}

- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary
{
	size_t count = [self columnCount];
	OFMutableDictionary *dictionary =
	    [OFMutableDictionary dictionaryWithCapacity: count];

	for (size_t i = 0; i < count; i++)
		[dictionary setObject: [self objectForColumn: i]
			       forKey: [self nameForColumn: i]];

	[dictionary makeImmutable];

	return dictionary;
}

- (void)reset
{
	int code = sqlite3_reset(_stmt);

	if (code != SQLITE_OK)
		@throw [SL3ResetStatementFailedException

Modified tests/Tests.m from [5f59d41afd] to [7e8b70e4f0].

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
	    @"$c", [OFData dataWithItems: "xyz"
				   count: 3],
	    nil]];
	[stmt step];

	stmt = [conn prepareStatement: @"SELECT * FROM test"];
	for (size_t i = 0; [stmt step]; i++) {




		OF_ENSURE([stmt columnCount] == 3);
		OF_ENSURE([[stmt nameForColumn: 0] isEqual: @"a"]);
		OF_ENSURE([[stmt nameForColumn: 1] isEqual: @"b"]);
		OF_ENSURE([[stmt nameForColumn: 2] isEqual: @"c"]);

		switch (i) {
		case 0:
			OF_ENSURE([[stmt objectForColumn: 0]
			    isEqual: [OFNumber numberWithInt: 5]]);
			OF_ENSURE([[stmt objectForColumn: 1]
			    isEqual: @"String"]);
			OF_ENSURE([[stmt objectForColumn: 2]
			    isEqual: [OFData dataWithItems: "abc"
						     count: 3]]);
			break;
		case 1:
			OF_ENSURE([[stmt objectForColumn: 0]
			    isEqual: [OFNumber numberWithInt: 7]]);
			OF_ENSURE([[stmt objectForColumn: 1]
			    isEqual: @"Test"]);
			OF_ENSURE([[stmt objectForColumn: 2]
			    isEqual: [OFData dataWithItems: "xyz"
						     count: 3]]);
			break;
		default:
			OF_ENSURE(0);
		}










	}

	[OFApplication terminate];
}
@end







>
>
>
>







<
|
<
|
<
|
|


<
|
<
|
<
|
|




>
>
>
>
>
>
>
>
>
>





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
	    @"$c", [OFData dataWithItems: "xyz"
				   count: 3],
	    nil]];
	[stmt step];

	stmt = [conn prepareStatement: @"SELECT * FROM test"];
	for (size_t i = 0; [stmt step]; i++) {
		OFNumber *a;
		OFString *b;
		OFData *c;

		OF_ENSURE([stmt columnCount] == 3);
		OF_ENSURE([[stmt nameForColumn: 0] isEqual: @"a"]);
		OF_ENSURE([[stmt nameForColumn: 1] isEqual: @"b"]);
		OF_ENSURE([[stmt nameForColumn: 2] isEqual: @"c"]);

		switch (i) {
		case 0:

			a = [OFNumber numberWithInt: 5];

			b = @"String";

			c = [OFData dataWithItems: "abc"
					    count: 3];
			break;
		case 1:

			a = [OFNumber numberWithInt: 7];

			b = @"Test";

			c = [OFData dataWithItems: "xyz"
					    count: 3];
			break;
		default:
			OF_ENSURE(0);
		}

		OF_ENSURE([[stmt objectForColumn: 0] isEqual: a]);
		OF_ENSURE([[stmt objectForColumn: 1] isEqual: b]);
		OF_ENSURE([[stmt objectForColumn: 2] isEqual: c]);

		OF_ENSURE([[stmt rowArray] isEqual: ([OFArray arrayWithObjects:
		    a, b, c, nil])]);
		OF_ENSURE([[stmt rowDictionary] isEqual:
		    ([OFDictionary dictionaryWithKeysAndObjects:
		    @"a", a, @"b", b, @"c", c, nil])]);
	}

	[OFApplication terminate];
}
@end