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

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

Open
normidar opened this issue Aug 21, 2020 · 9 comments
Open

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

normidar opened this issue Aug 21, 2020 · 9 comments

Comments

@normidar
Copy link

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
Copy link
Author

the image

@isoos
Copy link
Collaborator

isoos commented Aug 21, 2020

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

@normidar
Copy link
Author

normidar commented Aug 22, 2020

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
Copy link
Collaborator

isoos commented Aug 22, 2020

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

@normidar
Copy link
Author

normidar commented Aug 22, 2020

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
Copy link
Author

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

@isoos
Copy link
Collaborator

isoos commented Aug 22, 2020

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

@normidar
Copy link
Author

normidar commented Aug 22, 2020

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
Copy link
Collaborator

isoos commented Aug 22, 2020

  • You have shared the DB password, I'd suggest to change it for good.
  • You have a missing return in deleteTable, e.g. return _getRows('DROP TABLE ' + table + ';');

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants