Permalink
Browse files

Sort out interfaces for queries

  • Loading branch information...
1 parent 3ccb40d commit df0586fd7a988e4b08ae0f7b497d14a25d340186 James Ots committed Apr 13, 2012
Showing with 36 additions and 13 deletions.
  1. +22 −11 lib/connection.dart
  2. +14 −2 lib/interfaces.dart
View
33 lib/connection.dart
@@ -47,7 +47,7 @@ class AsyncMySqlConnection extends MySqlConnection implements AsyncConnection {
Future<PreparedQuery> future = _transport.processHandler(handler);
Completer c = new Completer();
future.then((preparedQuery) {
- MySqlQuery q = new MySqlQuery._internal(this, preparedQuery);
+ MySqlQuery q = new AsyncMySqlQuery._internal(this, preparedQuery);
_queries.add(q);
c.complete(q);
});
@@ -64,7 +64,7 @@ class SyncMySqlConnection extends MySqlConnection implements SyncConnection {
Query prepare (String sql) {
var handler = new PrepareHandler(sql);
PreparedQuery preparedQuery = _transport.processHandler(handler);
- MySqlQuery q = new MySqlQuery._internal(this, preparedQuery);
+ MySqlQuery q = new SyncMySqlQuery._internal(this, preparedQuery);
_queries.add(q);
return q;
}
@@ -75,27 +75,22 @@ class MySqlQuery implements Query {
PreparedQuery _preparedQuery;
List<Dynamic> _values;
bool _executed = false;
-
- MySqlQuery._internal(MySqlConnection this._cnx,
- PreparedQuery this._preparedQuery) {
- _values = new List<Dynamic>(_preparedQuery.parameters.length);
- }
-
+
int get statementId() => _preparedQuery.statementHandlerId;
Dynamic close() {
return _cnx._closeQuery(this);
}
- Future<Results> execute() {
+ Dynamic execute() {
var handler = new ExecuteQueryHandler(_preparedQuery, _executed, _values);
return _cnx._transport.processHandler(handler);
}
- Future<int> executeUpdate() {
+ Dynamic executeUpdate() {
}
-
+
Dynamic operator [](int pos) {
return _values[pos];
}
@@ -105,3 +100,19 @@ class MySqlQuery implements Query {
_executed = false;
}
}
+
+class AsyncMySqlQuery extends MySqlQuery implements AsyncQuery {
+ AsyncMySqlQuery._internal(MySqlConnection cnx, PreparedQuery preparedQuery) {
+ _cnx = cnx;
+ _preparedQuery = preparedQuery;
+ _values = new List<Dynamic>(_preparedQuery.parameters.length);
+ }
+}
+
+class SyncMySqlQuery extends MySqlQuery implements AsyncQuery {
+ SyncMySqlQuery._internal(MySqlConnection cnx, PreparedQuery preparedQuery) {
+ _cnx = cnx;
+ _preparedQuery = preparedQuery;
+ _values = new List<Dynamic>(_preparedQuery.parameters.length);
+ }
+}
View
16 lib/interfaces.dart
@@ -12,7 +12,7 @@ interface SyncConnection extends Connection {
void useDatabase(String dbName);
Results query(String sql);
int update(String sql);
- Query prepare(String sql);
+ SyncQuery prepare(String sql);
void close();
}
@@ -21,7 +21,7 @@ interface AsyncConnection extends Connection {
Future useDatabase(String dbName);
Future<Results> query(String sql);
Future<int> update(String sql);
- Future<MySqlQuery> prepare(String sql);
+ Future<AsyncQuery> prepare(String sql);
void close();
}
@@ -33,6 +33,18 @@ interface Query {
void operator []=(int index, Dynamic value);
}
+interface SyncQuery extends Query {
+ Results execute();
+ int executeUpdate();
+ void close();
+}
+
+interface AsyncQuery extends Query {
+ Future<Results> execute();
+ Future<int> executeUpdate();
+ Future close();
+}
+
interface Field {
String get name();
String get table();

0 comments on commit df0586f

Please sign in to comment.