MySqlResult class
Wrapper class for MySQL query results with convenient access methods.
This class encapsulates MySQL query results and provides a consistent
interface for accessing result data, metadata, and handling errors.
It wraps the native MySQL client's IResultSet with additional
convenience methods and error handling.
The class provides both low-level access to result set data and
high-level convenience methods for common operations like getting
associative arrays and checking success status.
Example:
var result = await table.select(conn, query);
if (result.success) {
for (var row in result.assoc) {
print('User: ${row['name']} - ${row['email']}');
}
} else {
print('Query failed: ${result.errorMsg}');
}
- Implemented types
-
- SqlDatabaseResult<
MySQLConnection, IResultSet, ResultSetRow>
- SqlDatabaseResult<
Constructors
- MySqlResult({required MySQLConnection database, required IResultSet resultSet, String errorMsg = ''})
- Creates a new MySqlResult instance. Parameters:
Properties
- affectedRows → int
-
Returns the number of rows affected by the last INSERT, UPDATE, or DELETE.
This is useful for determining how many records were modified by
data manipulation operations.
no setteroverride
-
assoc
→ List<
Map< String, String?> > -
Returns all rows as a list of associative arrays.
This is the most common way to access query results, providing
column names as map keys for easy data access.
Example:
no setteroverride
-
assocFirst
→ Map<
String, String?> ? -
Returns the first row as an associative array, or null if no rows exist.
This is convenient for queries that are expected to return a single
row, such as SELECT queries with LIMIT 1 or aggregate functions.
Example:
no setteroverride
- countRecords → int
-
Returns the count of records from results with the field
count_records. This method is specifically designed to work with COUNT queries where the result includes a field named 'count_records'. It extracts and converts this value to an integer. Returns 0 if the field doesn't exist, can't be parsed, or if there are no results. Example:no setteroverride - database ↔ MySQLConnection
-
getter/setter pairoverride
- error → bool
-
Returns
trueif the query failed (has an error message).no setteroverride - errorMsg ↔ String
-
Error message if the query failed, empty string if successful.
getter/setter pairoverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- insertId → int
-
Returns the auto-generated ID from the last INSERT operation.
This is particularly useful when inserting records into tables
with auto-increment primary keys.
no setteroverride
- numFields → int
-
Returns the number of columns in the result set.
no setteroverride
- numRows → int
-
Returns the number of rows in the result set.
no setteroverride
- resultSet → IResultSet
-
The underlying MySQL result set from the database driver.
final
-
rows
→ List<
ResultSetRow> -
Returns an iterable of result set rows.
Use this for direct access to the MySQL client's row objects.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- success → bool
-
Returns
trueif the query executed successfully (no error message).no setteroverride
Methods
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited