SL3PreparedStatement: Add -[row{Array,Dictionary}]
FossilOrigin-Name: 7a52167702278bdd7c5f3aac48771cba8ac5a77abfac4d1664b05a507fe8236e
This commit is contained in:
parent
5967ebf3b7
commit
9f22b628f2
3 changed files with 53 additions and 15 deletions
|
@ -41,10 +41,12 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
- (void)bindWithDictionary:
|
- (void)bindWithDictionary:
|
||||||
(OFDictionary OF_GENERIC(OFString *, id) *)dictionary;
|
(OFDictionary OF_GENERIC(OFString *, id) *)dictionary;
|
||||||
- (void)clearBindings;
|
- (void)clearBindings;
|
||||||
|
- (bool)step;
|
||||||
- (id)objectForColumn: (size_t)column;
|
- (id)objectForColumn: (size_t)column;
|
||||||
- (size_t)columnCount;
|
- (size_t)columnCount;
|
||||||
- (OFString *)nameForColumn: (size_t)column;
|
- (OFString *)nameForColumn: (size_t)column;
|
||||||
- (bool)step;
|
- (OFArray *)rowArray;
|
||||||
|
- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary;
|
||||||
- (void)reset;
|
- (void)reset;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -217,6 +217,34 @@ bindObject(SL3PreparedStatement *statement, int column, id object)
|
||||||
return [OFString stringWithUTF8String: name];
|
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
|
- (void)reset
|
||||||
{
|
{
|
||||||
int code = sqlite3_reset(_stmt);
|
int code = sqlite3_reset(_stmt);
|
||||||
|
|
|
@ -66,6 +66,10 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
|
|
||||||
stmt = [conn prepareStatement: @"SELECT * FROM test"];
|
stmt = [conn prepareStatement: @"SELECT * FROM test"];
|
||||||
for (size_t i = 0; [stmt step]; i++) {
|
for (size_t i = 0; [stmt step]; i++) {
|
||||||
|
OFNumber *a;
|
||||||
|
OFString *b;
|
||||||
|
OFData *c;
|
||||||
|
|
||||||
OF_ENSURE([stmt columnCount] == 3);
|
OF_ENSURE([stmt columnCount] == 3);
|
||||||
OF_ENSURE([[stmt nameForColumn: 0] isEqual: @"a"]);
|
OF_ENSURE([[stmt nameForColumn: 0] isEqual: @"a"]);
|
||||||
OF_ENSURE([[stmt nameForColumn: 1] isEqual: @"b"]);
|
OF_ENSURE([[stmt nameForColumn: 1] isEqual: @"b"]);
|
||||||
|
@ -73,26 +77,30 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
OF_ENSURE([[stmt objectForColumn: 0]
|
a = [OFNumber numberWithInt: 5];
|
||||||
isEqual: [OFNumber numberWithInt: 5]]);
|
b = @"String";
|
||||||
OF_ENSURE([[stmt objectForColumn: 1]
|
c = [OFData dataWithItems: "abc"
|
||||||
isEqual: @"String"]);
|
count: 3];
|
||||||
OF_ENSURE([[stmt objectForColumn: 2]
|
|
||||||
isEqual: [OFData dataWithItems: "abc"
|
|
||||||
count: 3]]);
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
OF_ENSURE([[stmt objectForColumn: 0]
|
a = [OFNumber numberWithInt: 7];
|
||||||
isEqual: [OFNumber numberWithInt: 7]]);
|
b = @"Test";
|
||||||
OF_ENSURE([[stmt objectForColumn: 1]
|
c = [OFData dataWithItems: "xyz"
|
||||||
isEqual: @"Test"]);
|
count: 3];
|
||||||
OF_ENSURE([[stmt objectForColumn: 2]
|
|
||||||
isEqual: [OFData dataWithItems: "xyz"
|
|
||||||
count: 3]]);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
OF_ENSURE(0);
|
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];
|
[OFApplication terminate];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue