stablekernel / postgresql-dart

Dart PostgreSQL driver: supports extended query format, binary protocol and statement reuse.
https://www.dartdocs.org/documentation/postgres/latest
BSD 3-Clause "New" or "Revised" License
127 stars 32 forks source link

when i run the delete from ccc where id=1 an throw a error. #140

Open normidar opened 4 years ago

normidar commented 4 years ago

delete from ccc where id=1; when I run the delete from ccc where id=1 and throw an error. it is like this: ERROR: Bad state: StreamSink is closed

delete from ccc where id=1;
ERROR: Bad state: StreamSink is closed
dart:io                                                    _Socket.add
package:postgres/src/query.dart 95:12                      Query.sendExtended
package:postgres/src/connection_fsm.dart 197:9             _PostgreSQLConnectionStateIdle.processQuery
package:postgres/src/connection_fsm.dart 183:14            _PostgreSQLConnectionStateIdle.awake
package:postgres/src/connection_fsm.dart 214:12            _PostgreSQLConnectionStateIdle.onEnter
package:postgres/src/connection.dart 234:41                PostgreSQLConnection._transitionToState
package:postgres/src/connection.dart 263:11                PostgreSQLConnection._readData
===== asynchronous gap ===========================
dart:async                                                 _Completer.completeError
package:postgres/src/query.dart 169:17                     Query.completeError
package:postgres/src/connection_fsm.dart 202:11            _PostgreSQLConnectionStateIdle.processQuery.<fn>
===== asynchronous gap ===========================
dart:async                                                 scheduleMicrotask
package:postgres/src/connection_fsm.dart 201:7             _PostgreSQLConnectionStateIdle.processQuery
package:postgres/src/connection_fsm.dart 183:14            _PostgreSQLConnectionStateIdle.awake
package:postgres/src/connection_fsm.dart 214:12            _PostgreSQLConnectionStateIdle.onEnter
package:postgres/src/connection.dart 234:41                PostgreSQLConnection._transitionToState
package:postgres/src/connection.dart 263:11                PostgreSQLConnection._readData
===== asynchronous gap ===========================
dart:io                                                    _Socket.listen
package:postgres/src/connection.dart 149:15                PostgreSQLConnection.open
===== asynchronous gap ===========================
dart:async                                                 _asyncThenWrapperHelper
package:fig_database_linker/dataLinkerPostgres.dart 57:17  DataLinkerPostgres.getConn
test/postgres_test.dart 67:16                              main.<fn>
normidar commented 4 years ago

the image

isoos commented 4 years ago

Can you open a connection and run SELECT 1; on it?

normidar commented 4 years ago

Can you open a connection and run SELECT 1; on it?

when I run SELECT 1;, it is no error.

And when I unclose the database link it is no error too. is it can not close after DELETE?

isoos commented 4 years ago

At one point you are closing the connection. Could you please share how you are using calling it?

normidar commented 4 years ago

At one point you are closing the connection. Could you please share how you are using calling it?

my code is:

.....
var sql = 'DELETE FROM $table WHERE "' + idName +'" = ' + id +';';
await _conn.query(sql)
if(!_conn.isClosed)await _conn.close();

the _conn is PostgreSQLConnection class.

I'm using Postgres in this website https://www.elephantsql.com/

normidar commented 4 years ago

is it can not close after the drop and the delete? when I close after the drop it has an error too.

isoos commented 4 years ago

Do you do anything else between opening the connection and querying it? Please provide full example (without the connection string).

normidar commented 4 years ago

Do you do anything else between opening the connection and querying it? Please provide full example (without the connection string).


LinkSets card = LinkSets(
'raja.db.elephantsql.com',
'5432',
'wabjtpfp',
'Q5q05nP9mcDUY9V3bWidtwegWxU9IO_J',
'wabjtpfp',
);
Future<String> getConn() async{
_conn = PostgreSQLConnection(
card.host,
int.parse(card.port ?? 5432),
card.db,
username: card.user,
password: card.psw,
);
await _conn.open();
return _conn.isClosed.toString();
}
Future deleteTable(String table)async{
_getRows('DROP TABLE ' + table + ';');
}
Future<List<List<dynamic>>> _getRows(String sql)async{
List<List<dynamic>> results = await _getRealRows(sql);
return results;
}
Future<PostgreSQLResult> _getRealRows(String sql){
return _conn.query(sql);
}
Future closeDatabase()async{
if(!_conn.isClosed)await _conn.close();
}
await link.getConn();
await link.deleteTable('ccc');
await link.closeDatabase();


you can link it whit this setting, maybe it is wrong in the server, I do not know.
isoos commented 4 years ago

I'd suggest to add unawaited_futures to you analysis_options.yaml as an extra lint.