Method: Libsql::Database#savepoint
- Defined in:
- lib/libsql/database.rb
#savepoint(name) ⇒ Object
call-seq:
db.savepoint( 'mypoint' ) -> db
db.savepoint( 'mypoint' ) do |db_in_savepoint|
...
end
Much of the following documentation is para-phrased from sqlite.org/lang_savepoint.html
Savepoints are a method of creating transactions, similar to transaction except that they may be nested.
-
Every savepoint must have a name,
to_sis called on the method argument -
A savepoint does not need to be initialized inside a transaction. If it is not inside a transaction it behaves exactly as if a DEFERRED transaction had been started.
-
If a block is passed to saveponit then when the block exists, it is guaranteed that either a ‘RELEASE’ or ‘ROLLBACK TO name’ has been executed.
-
If any exception happens during the savepoint transaction, then a ‘ROLLOBACK TO’ is issued when the block closes.
-
If no exception happens during the transaction then a ‘RELEASE name’ is issued upon leaving the block
If no block is passed in then you are on your own.
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/libsql/database.rb', line 574 def savepoint( name ) point_name = name.to_s.strip raise ::Libsql::Error, "Invalid savepoint name '#{name}'" unless point_name and point_name.length > 1 execute( "SAVEPOINT #{point_name};") if block_given? then begin return ( yield self ) ensure if $! then rollback_to( point_name ) raise $! else release( point_name ) end end else return in_transaction? end end |