method
transaction
![Some documentation Importance_1](https://d2vfyqvduarcvs.cloudfront.net/images/importance_1.png?1349367920)
v2.2.1 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1 (0)
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
Related methods
- Class methods (9)
-
create_unlogged_tables (>= v6.0.0)
-
database_exists? (>= v6.0.0)
-
datetime_type (>= v7.0.0)
-
dbconsole (>= v7.1.3.2)
-
initialize_type_map (>= v7.0.0)
-
native_database_types (>= v7.0.0)
-
new
-
new_client (>= v6.1.3.1)
-
visitor_for (>= v3.1.0)
- Instance methods (196)
-
active?
-
active_threadsafe? (>= v4.1.8)
-
adapter_name
-
add_column
-
add_enum_value (>= v7.1.3.2)
-
add_oid
(>= v4.1.8)
-
add_order_by_for_associatio...
-
add_pg_decoders
(>= v5.0.0.1)
-
add_pg_encoders
(>= v5.0.0.1)
-
arel_visitor (>= v5.0.0.1)
-
begin_db_transaction
-
build_insert_sql (>= v6.0.0)
-
build_statement_pool
(>= v6.0.0)
-
can_perform_case_insensitiv...
(>= v5.0.0.1)
-
cast_to_time
(<= v1.2.6)
-
change_column
-
change_column_default
-
change_column_null
-
check_version (>= v6.0.0)
-
clear_cache! (>= v3.1.0)
-
client_min_messages
-
client_min_messages=
-
column_definitions
-
column_name_for_operation (>= v4.2.1)
-
columns
-
commit_db_transaction
-
configure_connection
-
connect
-
construct_coder
(>= v5.0.0.1)
-
create (>= v3.0.0)
-
create_database
-
create_enum (>= v7.0.0)
-
create_savepoint (>= v2.3.8)
-
create_table_definition
(>= v4.0.2)
-
current_database
-
current_schema (>= v3.2.1)
-
default_index_type? (>= v5.1.7)
-
default_sequence_name
-
default_value
(<= v1.2.6)
-
disable_extension (>= v4.0.2)
-
disable_referential_integrity
-
discard! (>= v5.2.3)
-
disconnect!
-
distinct
-
drop_database
-
drop_enum (>= v7.1.3.2)
-
enable_extension (>= v4.0.2)
-
encoding
-
enum_types (>= v7.0.0)
-
escape_bytea
-
exec_cache
(>= v3.1.0)
-
exec_delete (>= v3.1.0)
-
exec_no_cache
(>= v3.1.0)
-
exec_query (>= v3.1.0)
-
exec_update (>= v3.1.0)
-
execute
-
execute_and_clear
(>= v4.2.1)
-
explain (>= v3.2.1)
-
extension_available? (>= v6.0.0)
-
extension_enabled? (>= v4.0.2)
-
extensions (>= v4.0.2)
-
extract_default_function
(>= v4.2.1)
-
extract_limit
(>= v4.2.1)
-
extract_pg_identifier_from_...
(>= v2.3.8)
-
extract_schema_and_table (>= v3.1.0)
-
extract_table_ref_from_inse...
(>= v3.2.1)
-
extract_value_from_default
(>= v4.2.1)
-
get_advisory_lock (>= v5.0.0.1)
-
get_database_version (>= v6.0.0)
-
get_oid_type
(>= v4.1.8)
-
has_default_function?
(>= v4.2.1)
-
index_algorithms (>= v4.0.2)
-
indexes
-
index_name_length (>= v2.3.8)
-
initialize_type_map
(>= v4.0.2)
-
insert
-
insert_sql (>= v3.1.0)
-
in_transaction?
(>= v5.0.0.1)
-
is_cached_plan_failure?
(>= v5.0.0.1)
-
last_insert_id
-
last_insert_id_result
(>= v4.0.2)
-
last_insert_id_value
(>= v4.0.2)
-
load_additional_types
(>= v4.2.1)
-
load_types_queries
(>= v7.0.0)
-
lookup_cast_type (>= v4.2.1)
-
max_identifier_length (>= v5.1.7)
-
migration_keys (>= v4.0.2)
-
native_database_types
-
outside_transaction? (>= v2.3.8)
-
pk_and_sequence_for
-
postgresql_version
-
prepare_column_options (>= v4.0.2)
-
prepare_statement
(>= v3.2.1)
-
primary_key (>= v2.3.8)
-
query
-
quote
-
quote_column_name
-
quoted_date
-
quote_string
-
quote_table_name (>= v2.3.8)
-
reconfigure_connection_time...
(>= v7.1.3.2)
-
reconnect
(>= v7.1.3.2)
-
reconnect!
-
recreate_database
-
release_advisory_lock (>= v5.0.0.1)
-
release_savepoint (>= v2.3.8)
-
reload_type_map
(>= v4.0.2)
-
remove_index
-
remove_index! (>= v2.3.8)
-
rename_column
-
rename_enum (>= v7.1.3.2)
-
rename_enum_value (>= v7.1.3.2)
-
rename_index (>= v3.1.0)
-
rename_table
-
reset! (>= v3.1.0)
-
reset_pk_sequence!
-
result_as_array
-
retryable_query_error?
(>= v7.1.3.2)
-
return_value_after_insert? (>= v7.1.3.2)
-
rollback_db_transaction
-
rollback_to_savepoint (>= v2.3.8)
-
schema_creation (>= v4.0.2)
-
schema_exists? (>= v3.2.1)
-
schema_search_path
-
schema_search_path=
-
select
-
select_raw
-
select_rows
-
serial_sequence (>= v3.1.0)
-
session_auth= (>= v3.1.0)
-
set_standard_conforming_str... (>= v2.3.8)
-
sql_for_insert (>= v3.1.0)
-
sql_key
(>= v3.2.1)
-
substitute_at (>= v3.1.0)
-
supports_advisory_locks? (>= v5.0.0.1)
-
supports_bulk_alter? (>= v5.2.3)
-
supports_check_constraints? (>= v6.1.3.1)
-
supports_comments? (>= v5.0.0.1)
-
supports_common_table_expre... (>= v6.1.3.1)
-
supports_datetime_with_prec... (>= v5.0.0.1)
-
supports_ddl_transactions?
-
supports_deferrable_constra... (>= v7.0.0)
-
supports_disable_referentia...
-
supports_exclusion_constrai... (>= v7.1.3.2)
-
supports_explain? (>= v3.2.1)
-
supports_expression_index? (>= v5.0.0.1)
-
supports_extensions? (>= v4.0.2)
-
supports_foreign_keys? (>= v4.2.1)
-
supports_foreign_tables? (>= v5.2.3)
-
supports_identity_columns? (>= v7.1.3.2)
-
supports_index_include? (>= v7.1.3.2)
-
supports_index_sort_order? (>= v3.2.1)
-
supports_insert_conflict_ta... (>= v6.0.0)
-
supports_insert_on_conflict? (>= v6.0.0)
-
supports_insert_on_duplicat... (>= v6.0.0)
-
supports_insert_on_duplicat... (>= v6.0.0)
-
supports_insert_returning? (>= v6.0.0)
-
supports_insert_with_return...
-
supports_json? (>= v5.0.0.1)
-
supports_lazy_transactions? (>= v6.0.0)
-
supports_materialized_views? (>= v4.2.1)
-
supports_migrations?
-
supports_nulls_not_distinct? (>= v7.1.3.2)
-
supports_optimizer_hints? (>= v6.0.0)
-
supports_partial_index? (>= v4.0.2)
-
supports_partitioned_indexes? (>= v6.1.3.1)
-
supports_pgcrypto_uuid? (>= v5.1.7)
-
supports_primary_key? (>= v2.3.8)
-
supports_ranges? (>= v4.0.2)
-
supports_restart_db_transac... (>= v7.1.3.2)
-
supports_savepoints? (>= v2.3.8)
-
supports_standard_conformin...
-
supports_statement_cache? (>= v3.1.0)
-
supports_transaction_isolat... (>= v4.0.2)
-
supports_unique_constraints? (>= v7.1.3.2)
-
supports_validate_constraints? (>= v5.2.3)
-
supports_views? (>= v4.2.1)
-
supports_virtual_columns? (>= v7.0.0)
-
table_alias_length
-
table_definition
(>= v3.1.0)
-
table_exists? (>= v3.0.0)
-
tables
-
transaction
-
transaction_active?
-
translate_exception
(>= v3.0.0)
-
translate_field_type
(<= v1.2.6)
-
truncate (>= v4.2.1)
-
type_cast (>= v3.1.0)
-
type_map
(>= v4.1.8)
-
type_to_sql
-
unescape_bytea
-
update_sql
-
update_table_definition
(>= v4.0.2)
-
update_typemap_for_default_...
(>= v6.0.0)
-
use_insert_returning? (>= v4.0.2)
-
valid_type? (>= v4.0.2)
= private
= protected
transaction(start_db_transaction = true)
public
Wrap a block in a transaction. Returns result of block.
Show source
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 542 def transaction(start_db_transaction = true) transaction_open = false begin if block_given? if start_db_transaction begin_db_transaction transaction_open = true end yield end rescue Exception => database_transaction_rollback if transaction_open && transaction_active? transaction_open = false rollback_db_transaction end raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback end ensure if transaction_open && transaction_active? begin commit_db_transaction rescue Exception => database_transaction_rollback rollback_db_transaction raise end end end