module PLSQL::SQLStatements
Public Instance Methods
Execute COMMIT in current database session. Use beforehand
plsql.connection.autocommit = false
to turn off automatic commits after each statement.
# File lib/plsql/sql_statements.rb, line 50 def commit @connection.commit end
Execute SQL statement. Example:
plsql.execute "DROP TABLE employees"
# File lib/plsql/sql_statements.rb, line 40 def execute(*args) @connection.exec(*args) end
Execute ROLLBACK in current database session. Use beforehand
plsql.connection.autocommit = false
to turn off automatic commits after each statement.
# File lib/plsql/sql_statements.rb, line 60 def rollback @connection.rollback end
Roll back changes to specified savepoint (that was created using savepoint
method) Use beforehand
plsql.connection.autocommit = false
to turn off automatic commits after each statement.
# File lib/plsql/sql_statements.rb, line 81 def rollback_to(name) execute "ROLLBACK TO #{name}" end
Create SAVEPOINT with specified name. Later use rollback_to
method to roll changes back to specified savepoint. Use beforehand
plsql.connection.autocommit = false
to turn off automatic commits after each statement.
# File lib/plsql/sql_statements.rb, line 71 def savepoint(name) execute "SAVEPOINT #{name}" end
Select :first or :all values. Examples:
plsql.select :first, "SELECT * FROM employees WHERE employee_id = :1", 1 plsql.select :all, "SELECT * FROM employees ORDER BY employee_id"
# File lib/plsql/sql_statements.rb, line 22 def select(*args) case args[0] when nil raise ArgumentError, "Not enough arguments" when :first args.shift @connection.select_hash_first(*args) when :all args.shift @connection.select_hash_all(*args) else @connection.select_hash_all(*args) end end
Select all rows as array or values (without column names)
# File lib/plsql/sql_statements.rb, line 9 def select_all(sql, *bindvars, &block) @connection.select_all(sql, *bindvars, &block) end
Select first row as array or values (without column names)
# File lib/plsql/sql_statements.rb, line 4 def select_first(sql, *bindvars) @connection.select_first(sql, *bindvars) end
Select one value (use if only one row with one value is selected)
# File lib/plsql/sql_statements.rb, line 14 def select_one(sql, *bindvars) (row = @connection.select_first(sql, *bindvars)) && row[0] end