query method
Implementation
@override
Future<RawTableData> query(String sql, FieldData fieldData) async {
if (_conn == null)
throw ArgumentError("connect() must be called before query");
Results results;
List<List<Object>> rowList = [];
try {
results = await _conn!.query(sql);
} catch (e) {
if (getErrorCode(e.toString()) == 1050) {
throw SqlException(SqlExceptionEnum.TABLE_ALREADY_EXISTS,
cause: e.toString());
} else if (getErrorCode(e.toString()) == 1051) {
throw SqlException(SqlExceptionEnum.TABLE_NOT_FOUND,
cause: e.toString());
} else if (getErrorCode(e.toString()) == 1146) {
throw SqlException(SqlExceptionEnum.TABLE_NOT_FOUND,
cause: e.toString());
} else if (e
.toString()
.startsWith("Bad state: Cannot write to socket, it is closed")) {
throw SqlException(SqlExceptionEnum.SOCKET_CLOSED,
cause: e.toString());
} else {
print(e.toString());
throw SqlException(SqlExceptionEnum.SQL_SYNTAX_ERROR,
cause: e.toString());
}
}
if (results != null) {
for (ResultRow row in results) {
List<Object> fieldList = [];
row.forEach((e) {
fieldList.add(e);
});
rowList.add(fieldList);
}
}
return RawTableData(fieldData.table_id, rowList, fieldData.getFieldNameList);
}