Skip to content

Commit

Permalink
Make fields accessible by name in BinaryDataPackets, too
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjackman committed Apr 18, 2019
1 parent 1723b6d commit 3dc7af8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/src/prepared_statements/binary_data_packet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BinaryDataPacket extends Row {
}
var field = fieldPackets[i];
values[i] = readField(field, buffer);
fields[field.name] = values[i];
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/results/row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class Row extends ListBase<dynamic> {
throw new UnsupportedError("Cannot modify row");
}

String toString() => "Value: $values";
String toString() => "Fields: $fields";

Object readField(Field field, Buffer buffer);
}
35 changes: 35 additions & 0 deletions test/integration/one_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,41 @@ void main() {
expect(dt, equals(dt2));
});

test('result fields are accessible by name', () async {
var results = await conn.query(
"insert into test1 (atinyint, asmallint, amediumint, abigint, aint, "
"adecimal, afloat, adouble, areal, "
"aboolean, abit, aserial, "
"adate, adatetime, atimestamp, atime, ayear, "
"achar, avarchar, atinytext, atext, amediumtext, alongtext, "
"abinary, avarbinary, atinyblob, amediumblob, ablob, alongblob, "
"aenum, aset) values"
"(?, ?, ?, ?, ?, "
"?, ?, ?, ?, "
"?, ?, ?, "
"?, ?, ?, ?, ?, "
"?, ?, ?, ?, ?, ?, "
"?, ?, ?, ?, ?, ?, "
"?, ?)",
insertValues);

// Normal
results = await conn.query('select atinyint from test1');
int v1 = results.first.fields['atinyint'];
int v2 = results.first['atinyint'];
expect(v1, isNotNull);
expect(v2, equals(v1));

// Binary packet
results = await conn.query('select atinyint from test1 WHERE ? = ?', [1, 1]);
int v3 = results.first.fields['atinyint'];
int v4 = results.first['atinyint'];
expect(v3, isNotNull);
expect(v4, equals(v3));

expect(v1, equals(v3));
});

test('disallow non-utc datetime serialization', () async {
expect(() async {
var results = await conn.query(
Expand Down

0 comments on commit 3dc7af8

Please sign in to comment.