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

Analysis fix #11

Merged
merged 2 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 10 additions & 8 deletions lib/src/single_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MySqlConnection {
/// Run [sql] query on the database using [values] as positional sql parameters.
///
/// eg. ```query("SELECT FROM users WHERE id = ?", [userId])```.
Future<Results> query(String sql, [Iterable<Object> values]) async {
Future<Results> query(String sql, [List<Object> values]) async {
if (values == null || values.isEmpty) {
return _conn.processHandlerWithResults(
new QueryStreamHandler(sql), _timeout);
Expand All @@ -159,15 +159,15 @@ class MySqlConnection {
///
/// e.g. ```queryMulti("INSERT INTO USERS (name) VALUES (?)", ["Adam", "Eve"])```.
Future<List<Results>> queryMulti(
String sql, Iterable<Iterable<Object>> values) async {
String sql, Iterable<List<Object>> values) async {
PreparedQuery prepared;
var ret = <Results>[];
try {
prepared = await _conn.processHandler<PreparedQuery>(
new PrepareHandler(sql), _timeout);
_log.fine("Prepared queryMulti query for: $sql");

for (List v in values) {
for (final v in values) {
if (v.length != prepared.parameterCount) {
throw new MySqlClientError(
"Length of parameters (${v.length}) does not match parameter count in query (${prepared.parameterCount})");
Expand Down Expand Up @@ -429,18 +429,19 @@ class ReqRespConnection {
* Processes a handler, from sending the initial request to handling any packets returned from
* mysql
*/
Future _processHandler(Handler handler) async {
Future<T> _processHandler<T>(Handler handler) async {
if (_handler != null) {
throw new MySqlClientError(
"Connection cannot process a request for $handler while a request is already in progress for $_handler");
}
_log.fine("start handler $handler");
_packetNumber = -1;
_compressedPacketNumber = -1;
_completer = new Completer<dynamic>();
final c = new Completer<T>();
_completer = c;
_handler = handler;
await sendBuffer(handler.createRequest());
return _completer.future;
return c.future;
}

final Pool pool = new Pool(1);
Expand All @@ -452,7 +453,7 @@ class ReqRespConnection {
Future<T> processHandler<T>(Handler handler, Duration timeout) {
return pool.withResource(() async {
try {
T ret = await _processHandler(handler).timeout(timeout);
T ret = await _processHandler<T>(handler).timeout(timeout);
return ret;
} finally {
_handler = null;
Expand All @@ -463,7 +464,8 @@ class ReqRespConnection {
Future<Results> processHandlerWithResults(Handler handler, Duration timeout) {
return pool.withResource(() async {
try {
ResultsStream results = await _processHandler(handler).timeout(timeout);
ResultsStream results =
await _processHandler<ResultsStream>(handler).timeout(timeout);
// Read all of the results. This is so we can close the handler before returning to the
// user. Obviously this is not super efficient but it guarantees correct api use.
Results ret = await Results._read(results).timeout(timeout);
Expand Down
14 changes: 7 additions & 7 deletions test/integration/one_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ void main() {
results = await conn.query("select adatetime from test1");

// Normal
DateTime dt = results.first[0];
DateTime dt = results.first[0] as DateTime;
expect(dt.isUtc, isTrue);

// Binary packet
results = await conn
.query("select adatetime from test1 WHERE atinyint = ?", [126]);
DateTime dt2 = results.first[0];
DateTime dt2 = results.first[0] as DateTime;
expect(dt2.isUtc, isTrue);

expect(dt, equals(dt2));
Expand All @@ -400,16 +400,16 @@ void main() {

// Normal
results = await conn.query('select atinyint from test1');
int v1 = results.first.fields['atinyint'];
int v2 = results.first['atinyint'];
int v1 = results.first.fields['atinyint'] as int;
int v2 = results.first['atinyint'] as int;
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'];
int v3 = results.first.fields['atinyint'] as int;
int v4 = results.first['atinyint'] as int;
expect(v3, isNotNull);
expect(v4, equals(v3));

Expand All @@ -421,7 +421,7 @@ void main() {
var results = await conn.query(
"insert into test1 (adatetime) values (?)", [new DateTime.now()]);
results = await conn.query("select adatetime from test1");
DateTime dt = results.first[0];
DateTime dt = results.first[0] as DateTime;
expect(dt.isUtc, isTrue);
}, throwsA(TypeMatcher<MySqlClientError>()));
});
Expand Down