execute method

Future<MySqlResult> execute(
  1. MySQLConnection conn,
  2. String sql
)

Executes a SQL query against the MySQL database connection.

This is a low-level method that executes raw SQL queries. It handles exceptions and wraps results in a MySqlResult object for consistent error handling across the application.

Parameters:

  • conn - The active MySQL database connection
  • sql - The SQL query string to execute

Returns a MySqlResult containing either the query results or error information if the query failed.

Example:

var result = await table.execute(conn, 'SELECT * FROM users');
if (result.success) {
  print('Query executed successfully');
}

Implementation

Future<MySqlResult> execute(
  MySQLConnection conn,
  String sql,
) async {
  try {
    var resultSet = await conn.execute(sql);
    return MySqlResult(resultSet);
  } catch (e) {
    return MySqlResult(
      EmptyResultSet(
          okPacket: MySQLPacketOK(
        header: 0,
        affectedRows: BigInt.zero,
        lastInsertID: BigInt.zero,
      )),
      errorMsg: e.toString(),
    );
  }
}