discontinuedPackage connect_database has been discontinued.
open method
Implementation
Future<Result<Unit>> open() async {
try {
SqlValidCommand.validateOpen(_isConnected, commandText);
} catch (e) {
return Failure(e is Exception ? e : Exception(e.toString()));
}
_currentIndex = -1;
_currentRecord = {};
var queryToProcess = commandText!;
if (SqlValidCommand.isSelectQuery(queryToProcess) &&
!_disableInterceptorForOpen) {
final interceptedResult =
await _selectInterceptor.interceptSelect(queryToProcess);
if (interceptedResult.isError()) {
return Failure(interceptedResult.exceptionOrNull()!);
}
queryToProcess = interceptedResult.getOrThrow();
}
return _substituteParameters(queryToProcess).fold(
(prepared) async {
if (_useReadUncommitted) {
await odbc.execute(_getReadUncommittedCommand());
}
final resultRows =
await odbc.execute(prepared.sql, params: prepared.params);
if (_useReadUncommitted) {
await odbc.execute(_getReadCommittedCommand());
}
return resultRows.map((rows) {
_result = rows;
if (_result.isNotEmpty) {
_currentIndex = 0;
_currentRecord = Map<String, dynamic>.from(_result[_currentIndex]);
}
return unit;
});
},
(error) async {
if (_useReadUncommitted) {
try {
await odbc.execute(_getReadCommittedCommand());
} catch (_) {}
}
return Failure(error);
},
);
}