prepare method

Future<OracleStatement> prepare(
  1. String sql, {
  2. bool scrollable = false,
})

Prepare a SQL statement without executing it.

This method is useful for batch operations with OracleStatement.executemany where you want to prepare the statement once and execute it multiple times with different parameter sets.

Parameters:

  • sql: The SQL statement to prepare
  • scrollable: Whether the cursor should be scrollable (default: false)

Returns: A prepared OracleStatement that can be executed with OracleStatement.executemany or by calling OracleStatement.bindByPos followed by OracleStatement.executeStatement.

Example - Batch Insert:

final stmt = await connection.prepare(
  'INSERT INTO users (id, name, email) VALUES (:1, :2, :3)',
);

try {
  final rowsAffected = await stmt.executemany([
    [1, 'Alice', 'alice@example.com'],
    [2, 'Bob', 'bob@example.com'],
    [3, 'Charlie', 'charlie@example.com'],
  ]);
  await connection.commit();
  print('Inserted $rowsAffected rows');
} finally {
  await stmt.close();
}

IMPORTANT: Always close the statement when done to free resources.

See also:

Implementation

Future<OracleStatement> prepare(String sql, {bool scrollable = false}) async {
  _ensureConnected();

  return OracleStatement.prepare(
    dpiOracle: _dpiOracle,
    connection: _connectionPtr.value,
    context: _context,
    sql: sql,
    scrollable: scrollable,
  );
}