From 27cd16f1b2a9a284fce87225ff48fd2a48663cb7 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 12 Dec 2019 17:28:49 +0800 Subject: [PATCH 1/3] prepare with close --- lib/internal/connection/impl.dart | 25 +++++++++++++++++++++++-- lib/public/connection/connection.dart | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/internal/connection/impl.dart b/lib/internal/connection/impl.dart index 4fc8bd4..c76d240 100644 --- a/lib/internal/connection/impl.dart +++ b/lib/internal/connection/impl.dart @@ -11,6 +11,19 @@ import 'package:sqljocky5/internal/prepared_statement_handler/prepare_handler.da import 'package:sqljocky5/internal/query_handler/query_stream_handler.dart'; import 'package:sqljocky5/internal/comm/comm.dart'; +class PrepareResult { + final Comm _socket; + final Duration _timeout; + PreparedQuery query; + StreamedResults results; + PrepareResult(this._socket, this._timeout, this.query, results); + + close() async { + await _socket.execHandlerNoResponse( + CloseStatementHandler(query.statementHandlerId), _timeout); + } +} + class MySqlConnectionImpl implements MySqlConnection { final Duration _timeout; @@ -68,7 +81,7 @@ class MySqlConnectionImpl implements MySqlConnection { Future prepare(String sql) async { PreparedQuery query = await _socket.execHandler(PrepareHandler(sql), _timeout); - return PreparedImpl._(this, query); + return PreparedImpl._(_socket, _timeout, this, query); } Future begin() => Transaction.begin(this); @@ -120,8 +133,10 @@ class MySqlConnectionImpl implements MySqlConnection { class PreparedImpl implements Prepared { final MySqlConnectionImpl _conn; final PreparedQuery _query; + final Comm _socket; + final Duration _timeout; - PreparedImpl._(this._conn, this._query); + PreparedImpl._(this._socket, this._timeout, this._conn, this._query); @override Future execute(Iterable values) => @@ -143,6 +158,12 @@ class PreparedImpl implements Prepared { return controller.stream; } + @override + Future close() async { + await _socket.execHandlerNoResponse( + CloseStatementHandler(_query.statementHandlerId), _timeout); + } + @override Future deallocate() => throw UnimplementedError(); } diff --git a/lib/public/connection/connection.dart b/lib/public/connection/connection.dart index 48af953..9fe943e 100644 --- a/lib/public/connection/connection.dart +++ b/lib/public/connection/connection.dart @@ -83,6 +83,8 @@ abstract class Prepared { /// Executes the statement multiple times with the given [values]. Stream executeAll(Iterable values); + Future close(); + /// Releases the prepared statement. Future deallocate(); } From cade6394a5b4db5ad81598296d7447a0342314b5 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 12 Dec 2019 17:42:01 +0800 Subject: [PATCH 2/3] removed unused result --- lib/internal/connection/impl.dart | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/internal/connection/impl.dart b/lib/internal/connection/impl.dart index c76d240..fa573b6 100644 --- a/lib/internal/connection/impl.dart +++ b/lib/internal/connection/impl.dart @@ -11,19 +11,6 @@ import 'package:sqljocky5/internal/prepared_statement_handler/prepare_handler.da import 'package:sqljocky5/internal/query_handler/query_stream_handler.dart'; import 'package:sqljocky5/internal/comm/comm.dart'; -class PrepareResult { - final Comm _socket; - final Duration _timeout; - PreparedQuery query; - StreamedResults results; - PrepareResult(this._socket, this._timeout, this.query, results); - - close() async { - await _socket.execHandlerNoResponse( - CloseStatementHandler(query.statementHandlerId), _timeout); - } -} - class MySqlConnectionImpl implements MySqlConnection { final Duration _timeout; From a31840a8c6dc1294d21dcb990404c8df765a778a Mon Sep 17 00:00:00 2001 From: james Date: Fri, 13 Dec 2019 10:18:17 +0800 Subject: [PATCH 3/3] uses deallocate --- lib/internal/connection/impl.dart | 5 +---- lib/public/connection/connection.dart | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/internal/connection/impl.dart b/lib/internal/connection/impl.dart index fa573b6..a4e5648 100644 --- a/lib/internal/connection/impl.dart +++ b/lib/internal/connection/impl.dart @@ -146,11 +146,8 @@ class PreparedImpl implements Prepared { } @override - Future close() async { + Future deallocate() async { await _socket.execHandlerNoResponse( CloseStatementHandler(_query.statementHandlerId), _timeout); } - - @override - Future deallocate() => throw UnimplementedError(); } diff --git a/lib/public/connection/connection.dart b/lib/public/connection/connection.dart index 9fe943e..48af953 100644 --- a/lib/public/connection/connection.dart +++ b/lib/public/connection/connection.dart @@ -83,8 +83,6 @@ abstract class Prepared { /// Executes the statement multiple times with the given [values]. Stream executeAll(Iterable values); - Future close(); - /// Releases the prepared statement. Future deallocate(); }