Skip to content

Unexpected Behavior: Need to Run Query Twice to Get Results #152

@habr

Description

@habr

Hello,

I am encountering an unexpected behavior when trying to query my MySQL database using the mysql1 Dart package. When I execute a query to show all tables in the database, it seems like I need to run the query twice to get the expected results. The first query doesn't return any result, but the second query returns the expected result. Here's a simplified version of my code to demonstrate the issue:

import 'dart:async';
import 'package:mysql1/mysql1.dart';

Future main() async {
  // Open a connection (testdb should already exist)
  final conn = await MySqlConnection.connect(ConnectionSettings(
    host: '127.0.0.1',
    port: 3306,
    user: 'username',
    password: 'password',
    db: 'database_name',
  ),);

  // Show tables
  var results2 = await conn.query('SHOW TABLES');  // First query
  var results = await conn.query('SHOW TABLES');   // Second query

  for (var row in results) {
    print('Table: ${row[0]}');
  }

  // Finally, close the connection
  await conn.close();
}

In the code above, results2 ends up being empty, but results contains the list of tables as expected. I have verified the connection settings and the database state, and everything seems to be in order. I have also checked the MySQL logs and found that both queries are indeed reaching the MySQL server.

Is this a known issue, or am I missing something in my implementation? Any help or guidance would be greatly appreciated.

Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions