query method
Query the db.
The query to be run with the passed values
var userId = 1;
var results = await conn.query('select name, email from users
where id = ?', [userId]);
Implementation
Future<IResultSet> query(String query, [ValueList? values]) async {
logger.fine(() => 'Db: $id qid: $queryCount ${_colour(query)}, '
'values:[${_expandValues(values)}]');
try {
final statement = await connection.prepare(query);
List<dynamic> params;
if (values == null) {
params = <dynamic>[];
} else {
params = values;
}
final results = await statement.execute(params);
logger.fine(() => 'Db: $id qid: $queryCount '
'Rows encountered: ${results.affectedRows}');
queryCount++;
return results;
} on MySqlException catch (e) {
/// We don't want to use the stack trace from the exception
/// as it is a useless async callback that does the results
/// processing and gives the user no context.
final stack = StackTrace.current;
logger.severe('''
Db: $id qid: $queryCount ${_colour(query)}, values:[${_expandValues(values)}]');
Error: ${e.message}''', e.errorNumber);
Error.throwWithStackTrace(e, stack);
}
}