query method

Result query(
  1. String query
)

Evaluate a query and return the resulting rows as an iterable.

Implementation

Result query(String query) {
  Pointer<Pointer<Statement>> statementOut = calloc();
  Pointer<Utf8> queryC = query.toNativeUtf8();
  int resultCode = bindings.sqlite3_prepare_v2(
      _database, queryC, -1, statementOut, nullptr);
  Pointer<Statement> statement = statementOut.value;
  calloc.free(statementOut);
  calloc.free(queryC);

  if (resultCode != Errors.SQLITE_OK) {
    bindings.sqlite3_finalize(statement);
    throw _loadError(resultCode);
  }

  Map<String, int> columnIndices = {};
  int columnCount = bindings.sqlite3_column_count(statement);
  for (int i = 0; i < columnCount; i++) {
    String columnName =
        bindings.sqlite3_column_name(statement, i).toDartString();
    columnIndices[columnName] = i;
  }

  return Result._(this, statement, columnIndices);
}