Method: Extralite::Database#execute

Defined in:
ext/extralite/database.c

#execute(sql, *parameters) ⇒ Integer?

Runs a query returning the total changes effected. This method should be used for data- or schema-manipulation queries.

Query parameters to be bound to placeholders in the query can be specified as a list of values or as a hash mapping parameter names to values. When parameters are given as an array, the query should specify parameters using ?:

db.execute('update foo set x = ? where y = ?', 42, 43)

Named placeholders are specified using :. The placeholder values are specified using keyword arguments:

db.execute('update foo set x = :bar', bar: 42)

Parameters:

  • sql (String)

    query SQL

  • parameters (Array, Hash)

    parameters to run query with

Returns:

  • (Integer, nil)

    Total number of changes effected or nil if the query ends with a comment.



497
498
499
# File 'ext/extralite/database.c', line 497

VALUE Database_execute(int argc, VALUE *argv, VALUE self) {
  return Database_perform_query(argc, argv, self, safe_query_changes, QUERY_HASH);
}