Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make result field values accessible by name on BinaryDataPackets, too #8

Merged
merged 3 commits into from
Apr 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make fields accessible by name in BinaryDataPackets, too
bobjackman committed Apr 18, 2019
commit 3dc7af8d93511258a8f3a3cde6fb7baedf9dccd8
1 change: 1 addition & 0 deletions lib/src/prepared_statements/binary_data_packet.dart
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ class BinaryDataPacket extends Row {
}
var field = fieldPackets[i];
values[i] = readField(field, buffer);
fields[field.name] = values[i];
}
}

2 changes: 1 addition & 1 deletion lib/src/results/row.dart
Original file line number Diff line number Diff line change
@@ -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
@@ -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(