### Home Classes Methods

### In Files

- lib/sequel/adapters/mysql.rb
- lib/sequel/adapters/postgres.rb
- lib/sequel/adapters/sqlite.rb
- lib/sequel/database.rb
- lib/sequel/database/schema_methods.rb
- lib/sequel/database/connecting.rb
- lib/sequel/database/dataset.rb
- lib/sequel/database/dataset_defaults.rb
- lib/sequel/database/logging.rb
- lib/sequel/database/misc.rb
- lib/sequel/database/query.rb
- lib/sequel/extensions/query.rb
- lib/sequel/extensions/schema_dumper.rb

### Parent

Sequel::Database

### Namespace

- CLASS Sequel::Dataset

### Methods

- ::adapter_class
- ::adapter_scheme
- ::connect
- ::identifier_input_method
- ::identifier_input_method=
- ::identifier_output_method
- ::identifier_output_method=
- ::new
- ::new
- ::new
- ::new
- ::quote_identifiers=
- ::single_threaded=
- ::uri_to_options
- #<<
- #[]
- #_execute
- #_table_exists?
- #_transaction
- #adapter_scheme
- #add_column
- #add_index
- #add_servers
- #add_transaction
- #after_commit
- #after_rollback
- #after_transaction_commit
- #after_transaction_rollback
- #already_in_transaction?
- #alter_table
- #alter_table_sql
- #alter_table_sql_list
- #apply_alter_table
- #auto_increment_sql
- #begin_new_transaction
- #begin_savepoint_sql
- #begin_transaction
- #begin_transaction_sql
- #blank_object?
- #call
- #cast_type_literal
- #check_database_errors
- #column_definition_auto_increment_sql
- #column_definition_collate_sql
- #column_definition_default_sql
- #column_definition_null_sql
- #column_definition_order
- #column_definition_primary_key_sql
- #column_definition_references_sql
- #column_definition_sql
- #column_definition_unique_sql
- #column_list_sql
- #column_references_column_constraint_sql
- #column_references_sql
- #column_references_table_constraint_sql
- #column_schema_to_generator_opts
- #column_schema_to_ruby_default
- #column_schema_to_ruby_default_fallback
- #column_schema_to_ruby_type
- #commit_or_rollback_transaction
- #commit_savepoint_sql
- #commit_transaction
- #commit_transaction_sql
- #connect
- #connection_execute_method
- #connection_pool_default_options
- #constraint_definition_sql
- #convert_date_time
- #convert_invalid_date_time=
- #convert_tinyint_to_bool=
- #copy_table
- #create_or_replace_view
- #create_table
- #create_table!
- #create_table?
- #create_table_from_generator
- #create_table_indexes_from_generator
- #create_table_sql
- #create_view
- #database_error_classes
- #database_name
- #database_type
- #dataset
- #dataset_class=
- #dataset_class_default
- #default_index_name
- #default_schema_default
- #disconnect
- #disconnect_connection
- #disconnect_error?
- #drop_column
- #drop_index
- #drop_index_sql
- #drop_table
- #drop_table_sql
- #drop_view
- #drop_view_sql
- #dump_indexes_migration
- #dump_schema_migration
- #dump_table_indexes
- #dump_table_schema
- #each_server
- #execute
- #execute_ddl
- #execute_dui
- #execute_insert
- #execute_prepared_statement
- #extend_datasets
- #fetch
- #filter_expr
- #from
- #from_application_timestamp
- #get
- #get_conversion_procs
- #identifier_input_method
- #identifier_input_method=
- #identifier_input_method_default
- #identifier_output_method
- #identifier_output_method=
- #identifier_output_method_default
- #in_transaction?
- #index_definition_sql
- #index_sql_list
- #index_to_generator_opts
- #indexes
- #input_identifier_meth
- #inspect
- #listen
- #literal
- #log_connection_execute
- #log_duration
- #log_each
- #log_info
- #log_yield
- #logger=
- #metadata_dataset
- #on_delete_clause
- #output_identifier_meth
- #query
- #quote_identifier
- #quote_identifiers=
- #quote_identifiers?
- #quote_identifiers_default
- #quote_schema_table
- #raise_error
- #remove_cached_schema
- #remove_servers
- #remove_transaction
- #rename_column
- #rename_table
- #rename_table_sql
- #reset_schema_utility_dataset
- #rollback_savepoint_sql
- #rollback_transaction
- #rollback_transaction_sql
- #run
- #schema
- #schema_and_table
- #schema_autoincrementing_primary_key?
- #schema_column_type
- #schema_utility_dataset
- #select
- #serial_primary_key_options
- #server_opts
- #server_version
- #servers
- #set_column_default
- #set_column_type
- #set_transaction_isolation
- #set_transaction_isolation_sql
- #single_threaded?
- #supports_create_table_if_not_exists?
- #supports_prepared_transactions?
- #supports_savepoints?
- #supports_savepoints_in_prepared_transactions?
- #supports_transaction_isolation_levels?
- #synchronize
- #table_exists?
- #tables
- #temporary_table_sql
- #test_connection
- #timezone
- #to_application_timestamp
- #transaction
- #transaction_error
- #type_literal
- #type_literal_generic
- #type_literal_generic_bigdecimal
- #type_literal_generic_bignum
- #type_literal_generic_date
- #type_literal_generic_datetime
- #type_literal_generic_falseclass
- #type_literal_generic_file
- #type_literal_generic_fixnum
- #type_literal_generic_float
- #type_literal_generic_integer
- #type_literal_generic_numeric
- #type_literal_generic_string
- #type_literal_generic_time
- #type_literal_generic_trueclass
- #type_literal_specific
- #typecast_value
- #typecast_value_blob
- #typecast_value_boolean
- #typecast_value_date
- #typecast_value_datetime
- #typecast_value_decimal
- #typecast_value_float
- #typecast_value_integer
- #typecast_value_string
- #typecast_value_time
- #uri
- #url
- #use_column_schema_to_ruby_default_fallback?
- #views

### Included Modules

- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::Postgres::DatabaseMethods
- ::Sequel::SQLite::DatabaseMethods
- Metaprogramming

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- schema_modification.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::Adapter
- Sequel::AdapterNotFound
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::BindArgumentMethods
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::TYPE_TRANSLATOR
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::HookFailed
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::Firebird::Dataset
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::Informix::Dataset
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLServer::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::DatasetMethods::StoredProcedureMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- Sequel::ODBC::DB2
- Sequel::ODBC::DB2::DatabaseMethods
- Sequel::ODBC::DB2::Dataset
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationAutoreloading::ClassMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::Rollback
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ServerBlock
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::AdapterMethods
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::Postgres::Dataset
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- Dataset
- Dataset::ArgumentMapper
- Dataset::BindArgumentMethods
- Dataset::PreparedStatementMethods
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel::Database

Database class for MySQL databases used with Sequel.

Database class for PostgreSQL databases used with Sequel and the pg, postgres, or postgres-pr driver.

Database class for SQLite databases used with Sequel and the ruby-sqlite3 driver.

A Database object represents a virtual connection to a database. The Database class is meant to be subclassed by database adapters in order to provide the functionality needed for executing queries.

### Constants

MYSQL_DATABASE_DISCONNECT_ERRORS

  Mysql::Error messages that indicate the current connection should be disconnected

AUTOINCREMENT
CASCADE
COMMA_SEPARATOR
NO_ACTION
NOT_NULL
NULL
PRIMARY_KEY
RESTRICT
SET_DEFAULT
SET_NULL
TEMPORARY
UNDERSCORE
UNIQUE
UNSIGNED
COLUMN_DEFINITION_ORDER

  The order of column modifiers to use when defining a column.

ADAPTERS

  Array of supported database adapters

DatasetClass

  The default class to use for datasets

LEADING_ZERO_RE

  Used for checking/removing leading zeroes from strings so they don’t get interpreted as octal.

LEADING_ZERO_REP

  Replacement string when replacing leading zeroes.

SQL_BEGIN
SQL_COMMIT
SQL_RELEASE_SAVEPOINT
SQL_ROLLBACK
SQL_ROLLBACK_TO_SAVEPOINT
SQL_SAVEPOINT
TRANSACTION_BEGIN
TRANSACTION_COMMIT
TRANSACTION_ROLLBACK
TRANSACTION_ISOLATION_LEVELS
POSTGRES_DEFAULT_RE
MSSQL_DEFAULT_RE
MYSQL_TIMESTAMP_RE
STRING_DEFAULT_RE

### Attributes

conversion_procs[R]

Hash of conversion procs for the current database

convert_tinyint_to_bool[R]

Whether to convert tinyint columns to bool for the current database

convert_invalid_date_time[R]

By default, Sequel raises an exception if in invalid date or time is used. However, if this is set to nil or :nil, the adapter treats dates like 0000-00-00 and times like 838:00:00 as nil values. If set to :string, it returns the strings as is.

conversion_procs[R]

A hash of conversion procs, keyed by type integer (oid) and having callable values for the conversion proc for that type.

conversion_procs[R]

The conversion procs to use for this database

pool[R]

The connection pool for this Database instance. All Database instances have their own connection pools.

dataset_class[R]

The class to use for creating datasets. Should respond to new with the Database argument as the first argument, and an optional options hash.

default_schema[RW]

The default schema to use, generally should be nil.

log_warn_duration[RW]

Numeric specifying the duration beyond which queries are logged at warn level instead of info level.

loggers[RW]

Array of SQL loggers to use for this database.

sql_log_level[RW]

Log level at which to log SQL queries. This is actually the method sent to the logger, so it should be the method name symbol. The default is :info, it can be set to :debug to log at DEBUG level.

opts[R]

The options hash for this database

timezone[W]

Set the timezone to use for this database, overridding `Sequel.database_timezone`.

prepared_statements[R]

The prepared statement object hash for this database, keyed by name symbol

transaction_isolation_level[RW]

The default transaction isolation level for this database, used for all future transactions. For MSSQL, this should be set to something if you ever plan to use the :isolation option to Database#transaction, as on MSSQL if affects all future transactions on the same connection.

### Public Class Methods

adapter_class(scheme) click to toggle source

The Database subclass for the given adapter scheme. Raises Sequel::AdapterNotFound if the adapter could not be loaded.

        # File lib/sequel/database/connecting.rb, line 17
    17:     def self.adapter_class(scheme)
    18:       return scheme if scheme.is_a?(Class)
    19:
    20:       scheme = scheme.to_s.gsub('-', '_').to_sym
    21:
    22:       unless klass = ADAPTER_MAP[scheme]
    23:         # attempt to load the adapter file
    24:         begin
    25:           Sequel.tsk_require "sequel/adapters/#{scheme}"
    26:         rescue LoadError => e
    27:           raise Sequel.convert_exception_class(e, AdapterNotFound)
    28:         end
    29:
    30:         # make sure we actually loaded the adapter
    31:         unless klass = ADAPTER_MAP[scheme]
    32:           raise AdapterNotFound, "Could not load #{scheme} adapter: adapter class not registered in ADAPTER_MAP"
    33:         end
    34:       end
    35:       klass
    36:     end

adapter_scheme() click to toggle source

Returns the scheme symbol for the Database class.

        # File lib/sequel/database/connecting.rb, line 39
    39:     def self.adapter_scheme
    40:       @scheme
    41:     end

connect(conn_string, opts = {}) click to toggle source

Connects to a database. See Sequel.connect.

        # File lib/sequel/database/connecting.rb, line 44
    44:     def self.connect(conn_string, opts = {})
    45:       case conn_string
    46:       when String
    47:         if match = /\A(jdbc|do):/.match(conn_string)
    48:           c = adapter_class(match[1].to_sym)
    49:           opts = {:uri=>conn_string}.merge(opts)
    50:         else
    51:           uri = URI.parse(conn_string)
    52:           scheme = uri.scheme
    53:           scheme = :dbi if scheme =~ /\Adbi-/
    54:           c = adapter_class(scheme)
    55:           uri_options = c.send(:uri_to_options, uri)
    56:           uri.query.split('&').collect{|s| s.split('=')}.each{|k,v| uri_options[k.to_sym] = v if k && !k.empty?} unless uri.query.to_s.strip.empty?
    57:           uri_options.to_a.each{|k,v| uri_options[k] = URI.unescape(v) if v.is_a?(String)}
    58:           opts = uri_options.merge(opts)
    59:           opts[:adapter] = scheme
    60:         end
    61:       when Hash
    62:         opts = conn_string.merge(opts)
    63:         c = adapter_class(opts[:adapter_class] || opts[:adapter] || opts['adapter'])
    64:       else
    65:         raise Error, "Sequel::Database.connect takes either a Hash or a String, given: #{conn_string.inspect}"
    66:       end
    67:       # process opts a bit
    68:       opts = opts.inject({}) do |m, (k,v)|
    69:         k = :user if k.to_s == 'username'
    70:         m[k.to_sym] = v
    71:         m
    72:       end
    73:       begin
    74:         db = c.new(opts)
    75:         db.test_connection if opts[:test] && db.send(:typecast_value_boolean, opts[:test])
    76:         result = yield(db) if block_given?
    77:       ensure
    78:         if block_given?
    79:           db.disconnect if db
    80:           ::Sequel::DATABASES.delete(db)
    81:         end
    82:       end
    83:       block_given? ? result : db
    84:     end

identifier_input_method() click to toggle source

The method to call on identifiers going into the database

        # File lib/sequel/database/dataset_defaults.rb, line 21
    21:     def self.identifier_input_method
    22:       @@identifier_input_method
    23:     end

identifier_input_method=(v) click to toggle source

Set the method to call on identifiers going into the database See Sequel.identifier_input_method=.

        # File lib/sequel/database/dataset_defaults.rb, line 27
    27:     def self.identifier_input_method=(v)
    28:       @@identifier_input_method = v || ""
    29:     end

identifier_output_method() click to toggle source

The method to call on identifiers coming from the database

        # File lib/sequel/database/dataset_defaults.rb, line 32
    32:     def self.identifier_output_method
    33:       @@identifier_output_method
    34:     end

identifier_output_method=(v) click to toggle source

Set the method to call on identifiers coming from the database See Sequel.identifier_output_method=.

        # File lib/sequel/database/dataset_defaults.rb, line 38
    38:     def self.identifier_output_method=(v)
    39:       @@identifier_output_method = v || ""
    40:     end

new(opts = {}, &block) click to toggle source

Constructs a new instance of a database connection with the specified options hash.

Accepts the following options:

:default_schema | The default schema to use, should generally be nil
:disconnection_proc | A proc used to disconnect the connection
:identifier_input_method | A string method symbol to call on identifiers going into the database
:identifier_output_method | A string method symbol to call on identifiers coming from the database
:logger | A specific logger to use
:loggers | An array of loggers to use
:quote_identifiers | Whether to quote identifiers
:servers | A hash specifying a server/shard specific options, keyed by shard symbol
:single_threaded | Whether to use a single-threaded connection pool
:sql_log_level | Method to use to log SQL to a logger, :info by default.

All options given are also passed to the connection pool. If a block is given, it is used as the connection_proc for the ConnectionPool.

        # File lib/sequel/database/misc.rb, line 42
    42:     def initialize(opts = {}, &block)
    43:       @opts ||= opts
    44:       @opts = connection_pool_default_options.merge(@opts)
    45:       @loggers = Array(@opts[:logger]) + Array(@opts[:loggers])
    46:       self.log_warn_duration = @opts[:log_warn_duration]
    47:       @opts[:disconnection_proc] ||= proc{|conn| disconnect_connection(conn)}
    48:       block ||= proc{|server| connect(server)}
    49:       @opts[:servers] = {} if @opts[:servers].is_a?(String)
    50:       @opts[:adapter_class] = self.class
    51:
    52:       @opts[:single_threaded] = @single_threaded = typecast_value_boolean(@opts.fetch(:single_threaded, @@single_threaded))
    53:       @schemas = {}
    54:       @default_schema = @opts.fetch(:default_schema, default_schema_default)
    55:       @prepared_statements = {}
    56:       @transactions = {}
    57:       @identifier_input_method = nil
    58:       @identifier_output_method = nil
    59:       @quote_identifiers = nil
    60:       @timezone = nil
    61:       @dataset_class = dataset_class_default
    62:       @dataset_modules = []
    63:       self.sql_log_level = @opts[:sql_log_level] ? @opts[:sql_log_level].to_sym : :info
    64:       @pool = ConnectionPool.get_pool(@opts, &block)
    65:
    66:       ::Sequel::DATABASES.push(self)
    67:     end

new(opts={}) click to toggle source

        # File lib/sequel/adapters/sqlite.rb, line 94
    94:       def initialize(opts={})
    95:         super
    96:         @conversion_procs = SQLITE_TYPES.dup
    97:         @conversion_procs['datetime'] = @conversion_procs['timestamp'] = method(:to_application_timestamp)
    98:         set_integer_booleans
    99:       end

new(*args) click to toggle source

Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.

         # File lib/sequel/adapters/postgres.rb, line 225
    225:       def initialize(*args)
    226:         super
    227:         @primary_keys = {}
    228:         @primary_key_sequences = {}
    229:       end

new(opts={}) click to toggle source

        # File lib/sequel/adapters/mysql.rb, line 61
    61:       def initialize(opts={})
    62:         super
    63:         @conversion_procs = MYSQL_TYPES.dup
    64:         self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
    65:         self.convert_invalid_date_time = Sequel::MySQL.convert_invalid_date_time
    66:       end

quote_identifiers=(value) click to toggle source

Sets the default quote_identifiers mode for new databases. See Sequel.quote_identifiers=.

        # File lib/sequel/database/dataset_defaults.rb, line 44
    44:     def self.quote_identifiers=(value)
    45:       @@quote_identifiers = value
    46:     end

single_threaded=(value) click to toggle source

Sets the default single_threaded mode for new databases. See Sequel.single_threaded=.

        # File lib/sequel/database/connecting.rb, line 88
    88:     def self.single_threaded=(value)
    89:       @@single_threaded = value
    90:     end

### Private Class Methods

uri_to_options(uri) click to toggle source

Converts a uri to an options hash. These options are then passed to a newly created database object.

        # File lib/sequel/database/misc.rb, line 10
    10:     def self.uri_to_options(uri)
    11:       { :user => uri.user,
    12:         :password => uri.password,
    13:         :host => uri.host,
    14:         :port => uri.port,
    15:         :database => (m = /\/(.*)/.match(uri.path)) && (m[1]) }
    16:     end

### Public Instance Methods

<<(sql) click to toggle source

Runs the supplied SQL statement string on the database server. Returns self so it can be safely chained:

      DB << "UPDATE albums SET artist_id = NULL" << "DROP TABLE artists"

        # File lib/sequel/database/query.rb, line 43
    43:     def <<(sql)
    44:       run(sql)
    45:       self
    46:     end

[](*args) click to toggle source

Returns a dataset for the database. If the first argument is a string, the method acts as an alias for Database#fetch, returning a dataset for arbitrary SQL, with or without placeholders:

      DB['SELECT * FROM items'].all
      DB['SELECT * FROM items WHERE name = ?', my_name].all

Otherwise, acts as an alias for Database#from, setting the primary table for the dataset:

      DB[:items].sql #=> "SELECT * FROM items"

        # File lib/sequel/database/dataset.rb, line 19
    19:     def [](*args)
    20:       (String === args.first) ? fetch(*args) : from(*args)
    21:     end

adapter_scheme() click to toggle source

Returns the scheme symbol for this instance’s class, which reflects which adapter is being used. In some cases, this can be the same as the `database_type` (for native adapters), in others (i.e. adapters with subadapters), it will be different.

      Sequel.connect('jdbc:postgres://...').adapter_scheme # => :jdbc

         # File lib/sequel/database/connecting.rb, line 120
    120:     def adapter_scheme
    121:       self.class.adapter_scheme
    122:     end

add_column(table, *args) click to toggle source

Adds a column to the specified table. This method expects a column name, a datatype and optionally a hash with additional constraints and options:

      DB.add_column :items, :name, :text, :unique => true, :null => false
      DB.add_column :items, :category, :text, :default => 'ruby'

See `alter_table`.

        # File lib/sequel/database/schema_methods.rb, line 33
    33:     def add_column(table, *args)
    34:       alter_table(table) {add_column(*args)}
    35:     end

add_index(table, columns, options={}) click to toggle source

Adds an index to a table for the given columns:

      DB.add_index :posts, :title
      DB.add_index :posts, [:author, :title], :unique => true

Options:

:ignore_errors | Ignore any DatabaseErrors that are raised

See `alter_table`.

        # File lib/sequel/database/schema_methods.rb, line 46
    46:     def add_index(table, columns, options={})
    47:       e = options[:ignore_errors]
    48:       begin
    49:         alter_table(table){add_index(columns, options)}
    50:       rescue DatabaseError
    51:         raise unless e
    52:       end
    53:     end

add_servers(servers) click to toggle source

Dynamically add new servers or modify server options at runtime. Also adds new servers to the connection pool. Intended for use with master/slave or shard configurations where it is useful to add new server hosts at runtime.

servers argument should be a hash with server name symbol keys and hash or proc values. If a servers key is already in use, it’s value is overridden with the value provided.

      DB.add_servers(:f=>{:host=>"hash_host_f"})

         # File lib/sequel/database/connecting.rb, line 133
    133:     def add_servers(servers)
    134:       @opts[:servers] = @opts[:servers] ? @opts[:servers].merge(servers) : servers
    135:       @pool.add_servers(servers.keys)
    136:     end

after_commit(opts={}, &block) click to toggle source

If a transaction is not currently in process, yield to the block immediately. Otherwise, add the block to the list of blocks to call after the currently in progress transaction commits (and only if it commits). Options:

:server | The server/shard to use.

        # File lib/sequel/database/misc.rb, line 74
    74:     def after_commit(opts={}, &block)
    75:       raise Error, "must provide block to after_commit" unless block
    76:       synchronize(opts[:server]) do |conn|
    77:         if h = @transactions[conn]
    78:           raise Error, "cannot call after_commit in a prepared transaction" if h[:prepare]
    79:           (h[:after_commit] ||= []) << block
    80:         else
    81:           yield
    82:         end
    83:       end
    84:     end

after_rollback(opts={}, &block) click to toggle source

If a transaction is not currently in progress, ignore the block. Otherwise, add the block to the list of the blocks to call after the currently in progress transaction rolls back (and only if it rolls back). Options:

:server | The server/shard to use.

        # File lib/sequel/database/misc.rb, line 91
    91:     def after_rollback(opts={}, &block)
    92:       raise Error, "must provide block to after_rollback" unless block
    93:       synchronize(opts[:server]) do |conn|
    94:         if h = @transactions[conn]
    95:           raise Error, "cannot call after_rollback in a prepared transaction" if h[:prepare]
    96:           (h[:after_rollback] ||= []) << block
    97:         end
    98:       end
    99:     end

alter_table(name, generator=nil, &block) click to toggle source

Alters the given table with the specified block. Example:

      DB.alter_table :items do
        add_column :category, :text, :default => 'ruby'
        drop_column :category
        rename_column :cntr, :counter
        set_column_type :value, :float
        set_column_default :value, :float
        add_index [:group, :category]
        drop_index [:group, :category]
      end

Note that `add_column` accepts all the options available for column definitions using `create_table`, and `add_index` accepts all the options available for index definition.

See `Schema::AlterTableGenerator` and the "Migrations and Schema Modification" guide.

        # File lib/sequel/database/schema_methods.rb, line 72
    72:     def alter_table(name, generator=nil, &block)
    73:       generator ||= Schema::AlterTableGenerator.new(self, &block)
    74:       remove_cached_schema(name)
    75:       apply_alter_table(name, generator.operations)
    76:       nil
    77:     end

call(ps_name, hash={}) click to toggle source

Call the prepared statement with the given name with the given hash of arguments.

      DB[:items].filter(:id=>1).prepare(:first, :sa)
      DB.call(:sa) # SELECT * FROM items WHERE id = 1

        # File lib/sequel/database/query.rb, line 53
    53:     def call(ps_name, hash={})
    54:       prepared_statements[ps_name].call(hash)
    55:     end

cast_type_literal(type) click to toggle source

Cast the given type to a literal type

      DB.cast_type_literal(Float) # double precision
      DB.cast_type_literal(:foo) # foo

         # File lib/sequel/database/misc.rb, line 105
    105:     def cast_type_literal(type)
    106:       type_literal(:type=>type)
    107:     end

connect(server) click to toggle source

Connect to the database. Since SQLite is a file based database, the only options available are :database (to specify the database name), and :timeout, to specify how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000).

         # File lib/sequel/adapters/sqlite.rb, line 105
    105:       def connect(server)
    106:         opts = server_opts(server)
    107:         opts[:database] = ':memory:' if blank_object?(opts[:database])
    108:         db = ::SQLite3::Database.new(opts[:database])
    109:         db.busy_timeout(opts.fetch(:timeout, 5000))
    110:
    111:         connection_pragmas.each{|s| log_yield(s){db.execute_batch(s)}}
    112:
    113:         class << db
    114:           attr_reader :prepared_statements
    115:         end

connect(server) click to toggle source

Connect to the database. In addition to the usual database options, the following options have effect:

- :auto_is_null - Set to true to use MySQL default behavior of having a filter for an autoincrement column equals NULL to return the last inserted row.

- :charset - Same as :encoding (:encoding takes precendence)

- :compress - Set to false to not compress results from the server

- :config_default_group - The default group to read from the in the MySQL config file.

- :config_local_infile - If provided, sets the Mysql::OPT_LOCAL_INFILE option on the connection with the given value.

- :connect_timeout - Set the timeout in seconds before a connection attempt is abandoned.

- :encoding - Set all the related character sets for this connection (connection, client, database, server, and results).

- :read_timeout - Set the timeout in seconds for reading back results to a query.

- :socket - Use a unix socket file instead of connecting via TCP/IP.

- :timeout - Set the timeout in seconds before the server will disconnect this connection (a.k.a @@wait_timeout).

         # File lib/sequel/adapters/mysql.rb, line 89
     89:       def connect(server)
     90:         opts = server_opts(server)
     91:         conn = Mysql.init
     92:         conn.options(Mysql::READ_DEFAULT_GROUP, opts[:config_default_group] || "client")
     93:         conn.options(Mysql::OPT_LOCAL_INFILE, opts[:config_local_infile]) if opts.has_key?(:config_local_infile)
     94:         conn.ssl_set(opts[:sslkey], opts[:sslcert], opts[:sslca], opts[:sslcapath], opts[:sslcipher]) if opts[:sslca] || opts[:sslkey]
     95:         if encoding = opts[:encoding] || opts[:charset]
     96:           # Set encoding before connecting so that the mysql driver knows what
     97:           # encoding we want to use, but this can be overridden by READ_DEFAULT_GROUP.
     98:           conn.options(Mysql::SET_CHARSET_NAME, encoding)
     99:         end
    100:         if read_timeout = opts[:read_timeout] and defined? Mysql::OPT_READ_TIMEOUT
    101:           conn.options(Mysql::OPT_READ_TIMEOUT, read_timeout)
    102:         end
    103:         if connect_timeout = opts[:connect_timeout] and defined? Mysql::OPT_CONNECT_TIMEOUT
    104:           conn.options(Mysql::OPT_CONNECT_TIMEOUT, connect_timeout)
    105:         end
    106:         conn.real_connect(
    107:           opts[:host] || 'localhost',
    108:           opts[:user],
    109:           opts[:password],
    110:           opts[:database],
    111:           (opts[:port].to_i if opts[:port]),
    112:           opts[:socket],
    113:           Mysql::CLIENT_MULTI_RESULTS +
    114:           Mysql::CLIENT_MULTI_STATEMENTS +
    115:           (opts[:compress] == false ? 0 : Mysql::CLIENT_COMPRESS)
    116:         )
    117:         sqls = []
    118:         # Set encoding a slightly different way after connecting,
    119:         # in case the READ_DEFAULT_GROUP overrode the provided encoding.
    120:         # Doesn't work across implicit reconnects, but Sequel doesn't turn on
    121:         # that feature.
    122:         sqls << "SET NAMES #{literal(encoding.to_s)}" if encoding
    123:
    124:         # Increase timeout so mysql server doesn't disconnect us
    125:         # Value used by default is maximum allowed value on Windows.
    126:         sqls << "SET @@wait_timeout = #{opts[:timeout] || 2147483}"
    127:
    128:         # By default, MySQL 'where id is null' selects the last inserted id
    129:         sqls << "SET SQL_AUTO_IS_NULL=0" unless opts[:auto_is_null]
    130:
    131:         sqls.each{|sql| log_yield(sql){conn.query(sql)}}
    132:
    133:         add_prepared_statements_cache(conn)
    134:         conn
    135:       end

connect(server) click to toggle source

Connects to the database. This method should be overridden by descendants.

         # File lib/sequel/database/connecting.rb, line 139
    139:     def connect(server)
    140:       raise NotImplemented, "#connect should be overridden by adapters"
    141:     end

connect(server) click to toggle source

Connects to the database. In addition to the standard database options, using the :encoding or :charset option changes the client encoding for the connection, :connect_timeout is a connection timeout in seconds, and :sslmode sets whether postgres’s sslmode. :connect_timeout and :ssl_mode are only supported if the pg driver is used.

         # File lib/sequel/adapters/postgres.rb, line 237
    237:       def connect(server)
    238:         opts = server_opts(server)
    239:         conn = if SEQUEL_POSTGRES_USES_PG
    240:           connection_params = {
    241:             :host => opts[:host],
    242:             :port => opts[:port] || 5432,
    243:             :dbname => opts[:database],
    244:             :user => opts[:user],
    245:             :password => opts[:password],
    246:             :connect_timeout => opts[:connect_timeout] || 20,
    247:             :sslmode => opts[:sslmode]
    248:           }.delete_if { |key, value| blank_object?(value) }
    249:           Adapter.connect(connection_params)
    250:         else
    251:           Adapter.connect(
    252:             (opts[:host] unless blank_object?(opts[:host])),
    253:             opts[:port] || 5432,
    254:             nil, '',
    255:             opts[:database],
    256:             opts[:user],
    257:             opts[:password]
    258:           )
    259:         end
    260:         if encoding = opts[:encoding] || opts[:charset]
    261:           if conn.respond_to?(:set_client_encoding)
    262:             conn.set_client_encoding(encoding)
    263:           else
    264:             conn.async_exec("set client_encoding to '#{encoding}'")
    265:           end
    266:         end
    267:         conn.db = self
    268:         conn.apply_connection_settings
    269:         @conversion_procs ||= get_conversion_procs(conn)
    270:         conn
    271:       end

convert_invalid_date_time=(v) click to toggle source

Modify the type translators for the date, time, and timestamp types depending on the value given.

         # File lib/sequel/adapters/mysql.rb, line 139
    139:       def convert_invalid_date_time=(v)
    140:         m0 = ::Sequel.method(:string_to_time)
    141:         @conversion_procs[11] = (v != false) ?  lambda{|v| convert_date_time(v, &m0)} : m0
    142:         m1 = ::Sequel.method(:string_to_date)
    143:         m = (v != false) ? lambda{|v| convert_date_time(v, &m1)} : m1
    144:         [10, 14].each{|i| @conversion_procs[i] = m}
    145:         m2 = method(:to_application_timestamp)
    146:         m = (v != false) ? lambda{|v| convert_date_time(v, &m2)} : m2
    147:         [7, 12].each{|i| @conversion_procs[i] = m}
    148:         @convert_invalid_date_time = v
    149:       end

convert_tinyint_to_bool=(v) click to toggle source

Modify the type translator used for the tinyint type based on the value given.

         # File lib/sequel/adapters/mysql.rb, line 153
    153:       def convert_tinyint_to_bool=(v)
    154:         @conversion_procs[1] = TYPE_TRANSLATOR.method(v ? :boolean : :integer)
    155:         @convert_tinyint_to_bool = v
    156:       end

copy_table(table, opts={}) click to toggle source

`copy_table` uses PostgreSQL’s `COPY` SQL statement to return formatted results directly to the caller. This method is only supported if pg is the underlying ruby driver. This method should only be called if you want results returned to the client. If you are using +COPY FROM+ or +COPY TO+ with a filename, you should just use `run` instead of this method. This method does not currently support +COPY FROM STDIN+, but that may be supported in the future.

The table argument supports the following types:

String | Uses the first argument directly as literal SQL. If you are using a version of PostgreSQL before 9.0, you will probably want to use a string if you are using any options at all, as the syntax Sequel uses for options is only compatible with PostgreSQL 9.0+.
Dataset | Uses a query instead of a table name when copying.
other | Uses a table name (usually a symbol) when copying.

The following options are respected:

:format | The format to use. text is the default, so this should be :csv or :binary.
:options | An options SQL string to use, which should contain comma separated options.
:server | The server on which to run the query.

If a block is provided, the method continually yields to the block, one yield per row. If a block is not provided, a single string is returned with all of the data.

         # File lib/sequel/adapters/postgres.rb, line 320
    320:         def copy_table(table, opts={})
    321:           sql = if table.is_a?(String)
    322:             sql = table
    323:           else
    324:             if opts[:options] || opts[:format]
    325:               options = " ("
    326:               options << "FORMAT #{opts[:format]}" if opts[:format]
    327:               options << "#{', ' if opts[:format]}#{opts[:options]}" if opts[:options]
    328:               options << ')'
    329:             end
    330:             table = if table.is_a?(::Sequel::Dataset)
    331:               "(#{table.sql})"
    332:             else
    333:               literal(table)
    334:             end
    335:            sql = "COPY #{table} TO STDOUT#{options}"
    336:           end
    337:           synchronize(opts[:server]) do |conn|
    338:             conn.execute(sql)
    339:             begin
    340:               if block_given?
    341:                 while buf = conn.get_copy_data
    342:                   yield buf
    343:                 end
    344:                 nil
    345:               else
    346:                 b = ''
    347:                 b << buf while buf = conn.get_copy_data
    348:                 b
    349:               end
    350:             ensure
    351:               raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" if buf
    352:             end
    353:           end
    354:         end

create_or_replace_view(name, source) click to toggle source

Creates a view, replacing it if it already exists:

      DB.create_or_replace_view(:cheap_items, "SELECT * FROM items WHERE price < 100")
      DB.create_or_replace_view(:ruby_items, DB[:items].filter(:category => 'ruby'))

         # File lib/sequel/database/schema_methods.rb, line 130
    130:     def create_or_replace_view(name, source)
    131:       source = source.sql if source.is_a?(Dataset)
    132:       execute_ddl("CREATE OR REPLACE VIEW #{quote_schema_table(name)} AS #{source}")
    133:       remove_cached_schema(name)
    134:       nil
    135:     end

create_table(name, options={}, &block) click to toggle source

Creates a table with the columns given in the provided block:

      DB.create_table :posts do
        primary_key :id
        column :title, :text
        String :content
        index :title
      end

Options:

:temp | Create the table as a temporary table.
:ignore_index_errors | Ignore any errors when creating indexes.

See `Schema::Generator` and the "Migrations and Schema Modification" guide.

         # File lib/sequel/database/schema_methods.rb, line 93
     93:     def create_table(name, options={}, &block)
     94:       remove_cached_schema(name)
     95:       options = {:generator=>options} if options.is_a?(Schema::Generator)
     96:       generator = options[:generator] || Schema::Generator.new(self, &block)
     97:       create_table_from_generator(name, generator, options)
     98:       create_table_indexes_from_generator(name, generator, options)
     99:       nil
    100:     end

create_table!(name, options={}, &block) click to toggle source

Forcibly create a table, attempting to drop it if it already exists, then creating it.

      DB.create_table!(:a){Integer :a}
      # SELECT * FROM a LIMIT a -- check existence
      # DROP TABLE a -- drop table if already exists
      # CREATE TABLE a (a integer)

         # File lib/sequel/database/schema_methods.rb, line 108
    108:     def create_table!(name, options={}, &block)
    109:       drop_table(name) if table_exists?(name)
    110:       create_table(name, options, &block)
    111:     end

create_table?(name, options={}, &block) click to toggle source

Creates the table unless the table already exists.

      DB.create_table?(:a){Integer :a}
      # SELECT * FROM a LIMIT a -- check existence
      # CREATE TABLE a (a integer) -- if it doesn't already exist

         # File lib/sequel/database/schema_methods.rb, line 118
    118:     def create_table?(name, options={}, &block)
    119:       if supports_create_table_if_not_exists?
    120:         create_table(name, options.merge(:if_not_exists=>true), &block)
    121:       elsif !table_exists?(name)
    122:         create_table(name, options, &block)
    123:       end
    124:     end

create_view(name, source) click to toggle source

Creates a view based on a dataset or an SQL string:

      DB.create_view(:cheap_items, "SELECT * FROM items WHERE price < 100")
      DB.create_view(:ruby_items, DB[:items].filter(:category => 'ruby'))

         # File lib/sequel/database/schema_methods.rb, line 141
    141:     def create_view(name, source)
    142:       source = source.sql if source.is_a?(Dataset)
    143:       execute_ddl("CREATE VIEW #{quote_schema_table(name)} AS #{source}")
    144:     end

database_type() click to toggle source

The database type for this database object, the same as the adapter scheme by default. Should be overridden in adapters (especially shared adapters) to be the correct type, so that even if two separate Database objects are using different adapters you can tell that they are using the same database type. Even better, you can tell that two Database objects that are using the same adapter are connecting to different database types (think JDBC or DataObjects).

      Sequel.connect('jdbc:postgres://...').database_type # => :postgres

         # File lib/sequel/database/connecting.rb, line 152
    152:     def database_type
    153:       adapter_scheme
    154:     end

dataset(opts=nil) click to toggle source

Returns a blank dataset for this database.

      DB.dataset # SELECT *
      DB.dataset.from(:items) # SELECT * FROM items

        # File lib/sequel/database/dataset.rb, line 27
    27:     def dataset(opts=nil)
    28:       @dataset_class.new(self, opts)
    29:     end

dataset_class=(c) click to toggle source

If the database has any dataset modules associated with it, use a subclass of the given class that includes the modules as the dataset class.

        # File lib/sequel/database/dataset_defaults.rb, line 59
    59:     def dataset_class=(c)
    60:       unless @dataset_modules.empty?
    61:         c = Class.new(c)
    62:         @dataset_modules.each{|m| c.send(:include, m)}
    63:       end
    64:       @dataset_class = c
    65:     end

disconnect(opts = {}) click to toggle source

Disconnects all available connections from the connection pool. Any connections currently in use will not be disconnected. Options:

:servers | Should be a symbol specifing the server to disconnect from, or an array of symbols to specify multiple servers.

Example:

      DB.disconnect # All servers
      DB.disconnect(:servers=>:server1) # Single server
      DB.disconnect(:servers=>[:server1, :server2]) # Multiple servers

         # File lib/sequel/database/connecting.rb, line 166
    166:     def disconnect(opts = {})
    167:       pool.disconnect(opts)
    168:     end

drop_column(table, *args) click to toggle source

Removes a column from the specified table:

      DB.drop_column :items, :category

See `alter_table`.

         # File lib/sequel/database/schema_methods.rb, line 151
    151:     def drop_column(table, *args)
    152:       alter_table(table) {drop_column(*args)}
    153:     end

drop_index(table, columns, options={}) click to toggle source

Removes an index for the given table and column/s:

      DB.drop_index :posts, :title
      DB.drop_index :posts, [:author, :title]

See `alter_table`.

         # File lib/sequel/database/schema_methods.rb, line 161
    161:     def drop_index(table, columns, options={})
    162:       alter_table(table){drop_index(columns, options)}
    163:     end

drop_table(*names) click to toggle source

Drops one or more tables corresponding to the given names:

      DB.drop_table(:posts)
      DB.drop_table(:posts, :comments)
      DB.drop_table(:posts, :comments, :cascade=>true)

         # File lib/sequel/database/schema_methods.rb, line 170
    170:     def drop_table(*names)
    171:       options = names.last.is_a?(Hash) ? names.pop : {}
    172:       names.each do |n|
    173:         execute_ddl(drop_table_sql(n, options))
    174:         remove_cached_schema(n)
    175:       end
    176:       nil
    177:     end

drop_view(*names) click to toggle source

Drops one or more views corresponding to the given names:

      DB.drop_view(:cheap_items)
      DB.drop_view(:cheap_items, :pricey_items)
      DB.drop_view(:cheap_items, :pricey_items, :cascade=>true)

         # File lib/sequel/database/schema_methods.rb, line 184
    184:     def drop_view(*names)
    185:       options = names.last.is_a?(Hash) ? names.pop : {}
    186:       names.each do |n|
    187:         execute_ddl(drop_view_sql(n, options))
    188:         remove_cached_schema(n)
    189:       end
    190:       nil
    191:     end

dump_indexes_migration(options={}) click to toggle source

Dump indexes for all tables as a migration. This complements the :indexes=>false option to dump_schema_migration. Options:

- :same_db - Create a dump for the same database type, so don’t ignore errors if the index statements fail.

        # File lib/sequel/extensions/schema_dumper.rb, line 13
    13:     def dump_indexes_migration(options={})
    14:       ts = tables(options)
    15:       Sequel.migration do  up do#{ts.sort_by{|t| t.to_s}.map{|t| dump_table_indexes(t, :add_index, options)}.reject{|x| x == ''}.join("\n\n").gsub(/^/o, '    ')}  end    down do#{ts.sort_by{|t| t.to_s}.map{|t| dump_table_indexes(t, :drop_index, options)}.reject{|x| x == ''}.join("\n\n").gsub(/^/o, '    ')}  endend
    16:     end

dump_schema_migration(options={}) click to toggle source

Return a string that contains a Sequel::Migration subclass that when run would recreate the database structure. Options:

- :same_db - Don’t attempt to translate database types to ruby types. If this isn’t set to true, all database types will be translated to ruby types, but there is no guarantee that the migration generated will yield the same type. Without this set, types that aren’t recognized will be translated to a string-like type.

- :indexes - If set to false, don’t dump indexes (they can be added later via dump_index_migration).

        # File lib/sequel/extensions/schema_dumper.rb, line 37
    37:     def dump_schema_migration(options={})
    38:       ts = tables(options)
    39:       Sequel.migration do  up do#{ts.sort_by{|t| t.to_s}.map{|t| dump_table_schema(t, options)}.join("\n\n").gsub(/^/o, '    ')}  end    down do    drop_table(#{ts.sort_by{|t| t.to_s}.inspect[1...-1]})  endend
    40:     end

dump_table_schema(table, options={}) click to toggle source

Return a string with a create table block that will recreate the given table’s schema. Takes the same options as dump_schema_migration.

        # File lib/sequel/extensions/schema_dumper.rb, line 54
    54:     def dump_table_schema(table, options={})
    55:       table = table.value.to_s if table.is_a?(SQL::Identifier)
    56:       raise(Error, "must provide table as a Symbol, String, or Sequel::SQL::Identifier") unless [String, Symbol].any?{|c| table.is_a?(c)}
    57:       s = schema(table).dup
    58:       pks = s.find_all{|x| x.last[:primary_key] == true}.map{|x| x.first}
    59:       options = options.merge(:single_pk=>true) if pks.length == 1
    60:       m = method(:column_schema_to_generator_opts)
    61:       im = method(:index_to_generator_opts)
    62:       begin
    63:         indexes = indexes(table).sort_by{|k,v| k.to_s} if options[:indexes] != false
    64:       rescue Sequel::NotImplemented
    65:         nil
    66:       end
    67:       gen = Schema::Generator.new(self) do
    68:         s.each{|name, info| send(*m.call(name, info, options))}
    69:         primary_key(pks) if !@primary_key && pks.length > 0
    70:         indexes.each{|iname, iopts| send(:index, iopts[:columns], im.call(table, iname, iopts))} if indexes
    71:       end
    72:       commands = [gen.dump_columns, gen.dump_constraints, gen.dump_indexes].reject{|x| x == ''}.join("\n\n")
    73:       "create_table(#{table.inspect}#{', :ignore_index_errors=>true' if !options[:same_db] && options[:indexes] != false && indexes && !indexes.empty?}) do\n#{commands.gsub(/^/o, '  ')}\nend"
    74:     end

each_server(&block) click to toggle source

Yield a new Database instance for every server in the connection pool. Intended for use in sharded environments where there is a need to make schema modifications (DDL queries) on each shard.

      DB.each_server{|db| db.create_table(:users){primary_key :id; String :name}}

         # File lib/sequel/database/connecting.rb, line 175
    175:     def each_server(&block)
    176:       servers.each{|s| self.class.connect(server_opts(s), &block)}
    177:     end

execute(sql, opts={}, &block) click to toggle source

Execute the given SQL with the given args on an available connection.

         # File lib/sequel/adapters/postgres.rb, line 274
    274:       def execute(sql, opts={}, &block)
    275:         check_database_errors do
    276:           return execute_prepared_statement(sql, opts, &block) if Symbol === sql
    277:           synchronize(opts[:server]){|conn| conn.execute(sql, opts[:arguments], &block)}
    278:         end
    279:       end

execute(sql, opts={}) click to toggle source

Executes the given SQL on the database. This method should be overridden in descendants. This method should not be called directly by user code.

        # File lib/sequel/database/query.rb, line 59
    59:     def execute(sql, opts={})
    60:       raise NotImplemented, "#execute should be overridden by adapters"
    61:     end

execute_ddl(sql, opts={}, &block) click to toggle source

Method that should be used when submitting any DDL (Data Definition Language) SQL, such as `create_table`. By default, calls `execute_dui`. This method should not be called directly by user code.

        # File lib/sequel/database/query.rb, line 66
    66:     def execute_ddl(sql, opts={}, &block)
    67:       execute_dui(sql, opts, &block)
    68:     end

execute_dui(sql, opts={}, &block) click to toggle source

Method that should be used when issuing a DELETE, UPDATE, or INSERT statement. By default, calls execute. This method should not be called directly by user code.

        # File lib/sequel/database/query.rb, line 73
    73:     def execute_dui(sql, opts={}, &block)
    74:       execute(sql, opts, &block)
    75:     end

execute_insert(sql, opts={}, &block) click to toggle source

Method that should be used when issuing a INSERT statement. By default, calls execute_dui. This method should not be called directly by user code.

        # File lib/sequel/database/query.rb, line 80
    80:     def execute_insert(sql, opts={}, &block)
    81:       execute_dui(sql, opts, &block)
    82:     end

execute_insert(sql, opts={}) click to toggle source

Insert the values into the table and return the primary key (if automatically generated).

         # File lib/sequel/adapters/postgres.rb, line 283
    283:       def execute_insert(sql, opts={})
    284:         return execute(sql, opts) if Symbol === sql
    285:         check_database_errors do
    286:           synchronize(opts[:server]) do |conn|
    287:             conn.execute(sql, opts[:arguments])
    288:             insert_result(conn, opts[:table], opts[:values])
    289:           end
    290:         end
    291:       end

extend_datasets(mod=nil, &block) click to toggle source

Equivalent to extending all datasets produced by the database with a module. What it actually does is use a subclass of the current dataset_class as the new dataset_class, and include the module in the subclass. Instead of a module, you can provide a block that is used to create an anonymous module.

This allows you to override any of the dataset methods even if they are defined directly on the dataset class that this Database object uses.

Examples:

      # Introspec columns for all of DB's datasets
      DB.extend_datasets(Sequel::ColumnsIntrospection)

      # Trace all SELECT queries by printing the SQL and the full backtrace
      DB.extend_datasets do
        def fetch_rows(sql)
          puts sql
          puts caller
          super
        end
      end

        # File lib/sequel/database/dataset_defaults.rb, line 89
    89:     def extend_datasets(mod=nil, &block)
    90:       raise(Error, "must provide either mod or block, not both") if mod && block
    91:       mod = Module.new(&block) if block
    92:       if @dataset_modules.empty?
    93:        @dataset_modules = [mod]
    94:        @dataset_class = Class.new(@dataset_class)
    95:       else
    96:        @dataset_modules << mod
    97:       end
    98:       @dataset_class.send(:include, mod)
    99:     end

fetch(sql, *args, &block) click to toggle source

Fetches records for an arbitrary SQL statement. If a block is given, it is used to iterate over the records:

      DB.fetch('SELECT * FROM items'){|r| p r}

The `fetch` method returns a dataset instance:

      DB.fetch('SELECT * FROM items').all

`fetch` can also perform parameterized queries for protection against SQL injection:

      DB.fetch('SELECT * FROM items WHERE name = ?', my_name).all

        # File lib/sequel/database/dataset.rb, line 44
    44:     def fetch(sql, *args, &block)
    45:       ds = dataset.with_sql(sql, *args)
    46:       ds.each(&block) if block
    47:       ds
    48:     end

from(*args, &block) click to toggle source

Returns a new dataset with the `from` method invoked. If a block is given, it is used as a filter on the dataset.

      DB.from(:items) # SELECT * FROM items
      DB.from(:items){id > 2} # SELECT * FROM items WHERE (id > 2)

        # File lib/sequel/database/dataset.rb, line 55
    55:     def from(*args, &block)
    56:       ds = dataset.from(*args)
    57:       block ? ds.filter(&block) : ds
    58:     end

from_application_timestamp(v) click to toggle source

Convert the given timestamp from the application’s timezone, to the databases’s timezone or the default database timezone if the database does not have a timezone.

         # File lib/sequel/database/misc.rb, line 112
    112:     def from_application_timestamp(v)
    113:       Sequel.convert_output_timestamp(v, timezone)
    114:     end

get(*args, &block) click to toggle source

Returns a single value from the database, e.g.:

      DB.get(1) # SELECT 1
      # => 1
      DB.get{server_version{}} # SELECT server_version()

        # File lib/sequel/database/query.rb, line 89
    89:     def get(*args, &block)
    90:       dataset.get(*args, &block)
    91:     end

identifier_input_method() click to toggle source

The method to call on identifiers going into the database

         # File lib/sequel/database/dataset_defaults.rb, line 102
    102:     def identifier_input_method
    103:       case @identifier_input_method
    104:       when nil
    105:         @identifier_input_method = @opts.fetch(:identifier_input_method, (@@identifier_input_method.nil? ? identifier_input_method_default : @@identifier_input_method))
    106:         @identifier_input_method == "" ? nil : @identifier_input_method
    107:       when ""
    108:         nil
    109:       else
    110:         @identifier_input_method
    111:       end
    112:     end

identifier_input_method=(v) click to toggle source

Set the method to call on identifiers going into the database:

      DB[:items] # SELECT * FROM items
      DB.identifier_input_method = :upcase
      DB[:items] # SELECT * FROM ITEMS

         # File lib/sequel/database/dataset_defaults.rb, line 119
    119:     def identifier_input_method=(v)
    120:       reset_schema_utility_dataset
    121:       @identifier_input_method = v || ""
    122:     end

identifier_output_method() click to toggle source

The method to call on identifiers coming from the database

         # File lib/sequel/database/dataset_defaults.rb, line 125
    125:     def identifier_output_method
    126:       case @identifier_output_method
    127:       when nil
    128:         @identifier_output_method = @opts.fetch(:identifier_output_method, (@@identifier_output_method.nil? ? identifier_output_method_default : @@identifier_output_method))
    129:         @identifier_output_method == "" ? nil : @identifier_output_method
    130:       when ""
    131:         nil
    132:       else
    133:         @identifier_output_method
    134:       end
    135:     end

identifier_output_method=(v) click to toggle source

Set the method to call on identifiers coming from the database:

      DB[:items].first # {:id=>1, :name=>'foo'}
      DB.identifier_output_method = :upcase
      DB[:items].first # {:ID=>1, :NAME=>'foo'}

         # File lib/sequel/database/dataset_defaults.rb, line 142
    142:     def identifier_output_method=(v)
    143:       reset_schema_utility_dataset
    144:       @identifier_output_method = v || ""
    145:     end

in_transaction?(opts={}) click to toggle source

Return true if already in a transaction given the options, false otherwise. Respects the :server option for selecting a shard.

         # File lib/sequel/database/misc.rb, line 119
    119:     def in_transaction?(opts={})
    120:       synchronize(opts[:server]){|conn| !!@transactions[conn]}
    121:     end

indexes(table, opts={}) click to toggle source

Return a hash containing index information for the table. Hash keys are index name symbols. Values are subhashes with two keys, :columns and :unique. The value of :columns is an array of symbols of column names. The value of :unique is true or false depending on if the index is unique.

Should not include the primary key index, functional indexes, or partial indexes.

      DB.indexes(:artists)
      # => {:artists_name_ukey=>{:columns=>[:name], :unique=>true}}

         # File lib/sequel/database/query.rb, line 102
    102:     def indexes(table, opts={})
    103:       raise NotImplemented, "#indexes should be overridden by adapters"
    104:     end

inspect() click to toggle source

Returns a string representation of the database object including the class name and the connection URI (or the opts if the URI cannot be constructed).

         # File lib/sequel/database/misc.rb, line 126
    126:     def inspect
    127:       "#<#{self.class}: #{(uri rescue opts).inspect}>"
    128:     end

listen(channels, opts={}, &block) click to toggle source

Listens on the given channel (or multiple channels if channel is an array), waiting for notifications. After a notification is received, or the timeout has passed, stops listening to the channel. Options:

:after_listen | An object that responds to `call` that is called with the underlying connection after the LISTEN statement is sent, but before the connection starts waiting for notifications.
:loop | Whether to continually wait for notifications, instead of just waiting for a single notification. If this option is given, a block must be provided. If this object responds to call, it is called with the underlying connection after each notification is received (after the block is called). If a :timeout option is used, and a callable object is given, the object will also be called if the timeout expires. If :loop is used and you want to stop listening, you can either break from inside the block given to #, or you can throw :stop from inside the :loop object’s call method or the block.
:server | The server on which to listen, if the sharding support is being used.
:timeout | How long to wait for a notification, in seconds (can provide a float value for fractional seconds). If not given or nil, waits indefinitely.

This method is only supported if pg is used as the underlying ruby driver. It returns the channel the notification was sent to (as a string), unless :loop was used, in which case it returns nil. If a block is given, it is yielded 3 arguments:

- the channel the notification was sent to (as a string)

- the backend pid of the notifier (as an integer),

- and the payload of the notification (as a string or nil).

         # File lib/sequel/adapters/postgres.rb, line 377
    377:         def listen(channels, opts={}, &block)
    378:           check_database_errors do
    379:             synchronize(opts[:server]) do |conn|
    380:               begin
    381:                 channels = Array(channels)
    382:                 channels.each{|channel| conn.execute("LISTEN #{channel}")}
    383:                 opts[:after_listen].call(conn) if opts[:after_listen]
    384:                 timeout = opts[:timeout] ? [opts[:timeout]] : []
    385:                 if l = opts[:loop]
    386:                   raise Error, 'calling #listen with :loop requires a block' unless block
    387:                   loop_call = l.respond_to?(:call)
    388:                   catch(:stop) do
    389:                     loop do
    390:                       conn.wait_for_notify(*timeout, &block)
    391:                       l.call(conn) if loop_call
    392:                     end
    393:                   end
    394:                   nil
    395:                 else
    396:                   conn.wait_for_notify(*timeout, &block)
    397:                 end
    398:               ensure
    399:                 conn.execute("UNLISTEN *")
    400:               end
    401:             end
    402:           end
    403:         end

literal(v) click to toggle source

Proxy the literal call to the dataset.

      DB.literal(1) # 1
      DB.literal(:a) # a
      DB.literal('a') # 'a'

         # File lib/sequel/database/misc.rb, line 135
    135:     def literal(v)
    136:       schema_utility_dataset.literal(v)
    137:     end

log_info(message, args=nil) click to toggle source

Log a message at level info to all loggers.

        # File lib/sequel/database/logging.rb, line 21
    21:     def log_info(message, args=nil)
    22:       log_each(:info, args ? "#{message}; #{args.inspect}" : message)
    23:     end

log_yield(sql, args=nil) click to toggle source

Yield to the block, logging any errors at error level to all loggers, and all other queries with the duration at warn or info level.

        # File lib/sequel/database/logging.rb, line 27
    27:     def log_yield(sql, args=nil)
    28:       return yield if @loggers.empty?
    29:       sql = "#{sql}; #{args.inspect}" if args
    30:       start = Time.now
    31:       begin
    32:         yield
    33:       rescue => e
    34:         log_each(:error, "#{e.class}: #{e.message.strip}: #{sql}")
    35:         raise
    36:       ensure
    37:         log_duration(Time.now - start, sql) unless e
    38:       end
    39:     end

logger=(logger) click to toggle source

Remove any existing loggers and just use the given logger:

      DB.logger = Logger.new($stdout)

        # File lib/sequel/database/logging.rb, line 44
    44:     def logger=(logger)
    45:       @loggers = Array(logger)
    46:     end

query(&block) click to toggle source

Return a dataset modified by the query block

        # File lib/sequel/extensions/query.rb, line 8
     8:     def query(&block)
     9:       dataset.query(&block)
    10:     end

quote_identifiers=(v) click to toggle source

Set whether to quote identifiers (columns and tables) for this database:

      DB[:items] # SELECT * FROM items
      DB.quote_identifiers = true
      DB[:items] # SELECT * FROM "items"

         # File lib/sequel/database/dataset_defaults.rb, line 152
    152:     def quote_identifiers=(v)
    153:       reset_schema_utility_dataset
    154:       @quote_identifiers = v
    155:     end

quote_identifiers?() click to toggle source

Returns true if the database quotes identifiers.

         # File lib/sequel/database/dataset_defaults.rb, line 158
    158:     def quote_identifiers?
    159:       return @quote_identifiers unless @quote_identifiers.nil?
    160:       @quote_identifiers = @opts.fetch(:quote_identifiers, (@@quote_identifiers.nil? ? quote_identifiers_default : @@quote_identifiers))
    161:     end

remove_servers(*servers) click to toggle source

Dynamically remove existing servers from the connection pool. Intended for use with master/slave or shard configurations where it is useful to remove existing server hosts at runtime.

servers should be symbols or arrays of symbols. If a nonexistent server is specified, it is ignored. If no servers have been specified for this database, no changes are made. If you attempt to remove the :default server, an error will be raised.

      DB.remove_servers(:f1, :f2)

         # File lib/sequel/database/connecting.rb, line 189
    189:     def remove_servers(*servers)
    190:       if @opts[:servers] && !@opts[:servers].empty?
    191:         servs = @opts[:servers].dup
    192:         servers.flatten!
    193:         servers.each{|s| servs.delete(s)}
    194:         @opts[:servers] = servs
    195:         @pool.remove_servers(servers)
    196:       end
    197:     end

rename_column(table, *args) click to toggle source

Renames a column in the specified table. This method expects the current column name and the new column name:

      DB.rename_column :items, :cntr, :counter

See `alter_table`.

         # File lib/sequel/database/schema_methods.rb, line 210
    210:     def rename_column(table, *args)
    211:       alter_table(table) {rename_column(*args)}
    212:     end

rename_table(name, new_name) click to toggle source

Renames a table:

      DB.tables #=> [:items]
      DB.rename_table :items, :old_items
      DB.tables #=> [:old_items]

         # File lib/sequel/database/schema_methods.rb, line 198
    198:     def rename_table(name, new_name)
    199:       execute_ddl(rename_table_sql(name, new_name))
    200:       remove_cached_schema(name)
    201:       nil
    202:     end

run(sql, opts={}) click to toggle source

Runs the supplied SQL statement string on the database server. Returns nil. Options:

:server | The server to run the SQL on.

      DB.run("SET some_server_variable = 42")

         # File lib/sequel/database/query.rb, line 111
    111:     def run(sql, opts={})
    112:       execute_ddl(sql, opts)
    113:       nil
    114:     end

schema(table, opts={}) click to toggle source

Returns the schema for the given table as an array with all members being arrays of length 2, the first member being the column name, and the second member being a hash of column information. The table argument can also be a dataset, as long as it only has one table. Available options are:

:reload | Ignore any cached results, and get fresh information from the database.
:schema | An explicit schema to use. It may also be implicitly provided via the table name.

If schema parsing is supported by the database, the column information should hash at least contain the following entries:

:allow_null | Whether NULL is an allowed value for the column.
:db_type | The database type for the column, as a database specific string.
:default | The database default for the column, as a database specific string.
:primary_key | Whether the columns is a primary key column. If this column is not present, it means that primary key information is unavailable, not that the column is not a primary key.
:ruby_default | The database default for the column, as a ruby object. In many cases, complex database defaults cannot be parsed into ruby objects, in which case nil will be used as the value.
:type | A symbol specifying the type, such as :integer or :string.

Example:

      DB.schema(:artists)
      # [[:id,
      #   {:type=>:integer,
      #    :primary_key=>true,
      #    :default=>"nextval('artist_id_seq'::regclass)",
      #    :ruby_default=>nil,
      #    :db_type=>"integer",
      #    :allow_null=>false}],
      #  [:name,
      #   {:type=>:string,
      #    :primary_key=>false,
      #    :default=>nil,
      #    :ruby_default=>nil,
      #    :db_type=>"text",
      #    :allow_null=>false}]]

         # File lib/sequel/database/query.rb, line 156
    156:     def schema(table, opts={})
    157:       raise(Error, 'schema parsing is not implemented on this database') unless respond_to?(:schema_parse_table, true)
    158:
    159:       opts = opts.dup
    160:       if table.is_a?(Dataset)
    161:         o = table.opts
    162:         from = o[:from]
    163:         raise(Error, "can only parse the schema for a dataset with a single from table") unless from && from.length == 1 && !o.include?(:join) && !o.include?(:sql)
    164:         tab = table.first_source_table
    165:         sch, table_name = schema_and_table(tab)
    166:         quoted_name = table.literal(tab)
    167:         opts[:dataset] = table
    168:       else
    169:         sch, table_name = schema_and_table(table)
    170:         quoted_name = quote_schema_table(table)
    171:       end
    172:       opts[:schema] = sch if sch && !opts.include?(:schema)
    173:
    174:       @schemas.delete(quoted_name) if opts[:reload]
    175:       return @schemas[quoted_name] if @schemas[quoted_name]
    176:
    177:       cols = schema_parse_table(table_name, opts)
    178:       raise(Error, 'schema parsing returned no columns, table probably doesn\t exist') if cols.nil? || cols.empty?
    179:       cols.each{|_,c| c[:ruby_default] = column_schema_to_ruby_default(c[:default], c[:type])}
    180:       @schemas[quoted_name] = cols
    181:     end

select(*args, &block) click to toggle source

Returns a new dataset with the select method invoked.

      DB.select(1) # SELECT 1
      DB.select{server_version{}} # SELECT server_version()
      DB.select(:id).from(:items) # SELECT id FROM items

        # File lib/sequel/database/dataset.rb, line 65
    65:     def select(*args, &block)
    66:       dataset.select(*args, &block)
    67:     end

serial_primary_key_options() click to toggle source

Default serial primary key options, used by the table creation code.

         # File lib/sequel/database/misc.rb, line 141
    141:     def serial_primary_key_options
    142:       {:primary_key => true, :type => Integer, :auto_increment => true}
    143:     end

server_version(server=nil) click to toggle source

Return the version of the MySQL server two which we are connecting.

         # File lib/sequel/adapters/mysql.rb, line 159
    159:       def server_version(server=nil)
    160:         @server_version ||= (synchronize(server){|conn| conn.server_version if conn.respond_to?(:server_version)} || super)
    161:       end

servers() click to toggle source

An array of servers/shards for this Database object.

      DB.servers # Unsharded: => [:default]
      DB.servers # Sharded:   => [:default, :server1, :server2]

         # File lib/sequel/database/connecting.rb, line 203
    203:     def servers
    204:       pool.servers
    205:     end

set_column_default(table, *args) click to toggle source

Sets the default value for the given column in the given table:

      DB.set_column_default :items, :category, 'perl!'

See `alter_table`.

         # File lib/sequel/database/schema_methods.rb, line 219
    219:     def set_column_default(table, *args)
    220:       alter_table(table) {set_column_default(*args)}
    221:     end

set_column_type(table, *args) click to toggle source

Set the data type for the given column in the given table:

      DB.set_column_type :items, :price, :float

See `alter_table`.

         # File lib/sequel/database/schema_methods.rb, line 228
    228:     def set_column_type(table, *args)
    229:       alter_table(table) {set_column_type(*args)}
    230:     end

single_threaded?() click to toggle source

Returns true if the database is using a single-threaded connection pool.

         # File lib/sequel/database/connecting.rb, line 208
    208:     def single_threaded?
    209:       @single_threaded
    210:     end

supports_create_table_if_not_exists?() click to toggle source

Whether the database supports CREATE TABLE IF NOT EXISTS syntax, false by default.

         # File lib/sequel/database/misc.rb, line 147
    147:     def supports_create_table_if_not_exists?
    148:       false
    149:     end

supports_prepared_transactions?() click to toggle source

Whether the database and adapter support prepared transactions (two-phase commit), false by default.

         # File lib/sequel/database/misc.rb, line 153
    153:     def supports_prepared_transactions?
    154:       false
    155:     end

supports_savepoints?() click to toggle source

Whether the database and adapter support savepoints, false by default.

         # File lib/sequel/database/misc.rb, line 158
    158:     def supports_savepoints?
    159:       false
    160:     end

supports_savepoints_in_prepared_transactions?() click to toggle source

Whether the database and adapter support savepoints inside prepared transactions (two-phase commit), default is false.

         # File lib/sequel/database/misc.rb, line 164
    164:     def supports_savepoints_in_prepared_transactions?
    165:       supports_prepared_transactions? && supports_savepoints?
    166:     end

supports_transaction_isolation_levels?() click to toggle source

Whether the database and adapter support transaction isolation levels, false by default.

         # File lib/sequel/database/misc.rb, line 169
    169:     def supports_transaction_isolation_levels?
    170:       false
    171:     end

synchronize(server=nil, &block) click to toggle source

Acquires a database connection, yielding it to the passed block. This is useful if you want to make sure the same connection is used for all database queries in the block. It is also useful if you want to gain direct access to the underlying connection object if you need to do something Sequel does not natively support.

If a server option is given, acquires a connection for that specific server, instead of the :default server.

      DB.synchronize do |conn|
        ...
      end

         # File lib/sequel/database/connecting.rb, line 224
    224:     def synchronize(server=nil, &block)
    225:       @pool.hold(server || :default, &block)
    226:     end

table_exists?(name) click to toggle source

Returns true if a table with the given name exists. This requires a query to the database.

      DB.table_exists?(:foo) # => false
      # SELECT NULL FROM foo LIMIT 1

Note that since this does a SELECT from the table, it can give false negatives if you don’t have permission to SELECT from the table.

         # File lib/sequel/database/query.rb, line 191
    191:     def table_exists?(name)
    192:       sch, table_name = schema_and_table(name)
    193:       name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
    194:       _table_exists?(from(name))
    195:       true
    196:     rescue DatabaseError
    197:       false
    198:     end

tables(opts={}) click to toggle source

Return all tables in the database as an array of symbols.

      DB.tables # => [:albums, :artists]

         # File lib/sequel/database/query.rb, line 203
    203:     def tables(opts={})
    204:       raise NotImplemented, "#tables should be overridden by adapters"
    205:     end

test_connection(server=nil) click to toggle source

Attempts to acquire a database connection. Returns true if successful. Will probably raise an Error if unsuccessful. If a server argument is given, attempts to acquire a database connection to the given server/shard.

         # File lib/sequel/database/connecting.rb, line 232
    232:     def test_connection(server=nil)
    233:       synchronize(server){|conn|}
    234:       true
    235:     end

timezone() click to toggle source

The timezone to use for this database, defaulting to `Sequel.database_timezone`.

         # File lib/sequel/database/misc.rb, line 174
    174:     def timezone
    175:       @timezone || Sequel.database_timezone
    176:     end

to_application_timestamp(v) click to toggle source

Convert the given timestamp to the application’s timezone, from the databases’s timezone or the default database timezone if the database does not have a timezone.

         # File lib/sequel/database/misc.rb, line 181
    181:     def to_application_timestamp(v)
    182:       Sequel.convert_timestamp(v, timezone)
    183:     end

transaction(opts={}, &block) click to toggle source

Starts a database transaction. When a database transaction is used, either all statements are successful or none of the statements are successful. Note that MySQL MyISAM tabels do not support transactions.

The following options are respected:

:isolation | The transaction isolation level to use for this transaction, should be :uncommitted, :committed, :repeatable, or :serializable, used if given and the database/adapter supports customizable transaction isolation levels.
:prepare | A string to use as the transaction identifier for a prepared transaction (two-phase commit), if the database/adapter supports prepared transactions.
:rollback | Can the set to :reraise to reraise any Sequel::Rollback exceptions raised, or :always to always rollback even if no exceptions occur (useful for testing).
:server | The server to use for the transaction.
:savepoint | Whether to create a new savepoint for this transaction, only respected if the database/adapter supports savepoints. By default Sequel will reuse an existing transaction, so if you want to use a savepoint you must use this option.

         # File lib/sequel/database/query.rb, line 228
    228:     def transaction(opts={}, &block)
    229:       synchronize(opts[:server]) do |conn|
    230:         return yield(conn) if already_in_transaction?(conn, opts)
    231:         _transaction(conn, opts, &block)
    232:       end
    233:     end

typecast_value(column_type, value) click to toggle source

Typecast the value to the given column_type. Calls typecast_value_#{column_type} if the method exists, otherwise returns the value. This method should raise Sequel::InvalidValue if assigned value is invalid.

         # File lib/sequel/database/misc.rb, line 190
    190:     def typecast_value(column_type, value)
    191:       return nil if value.nil?
    192:       meth = "typecast_value_#{column_type}"
    193:       begin
    194:         respond_to?(meth, true) ? send(meth, value) : value
    195:       rescue ArgumentError, TypeError => e
    196:         raise Sequel.convert_exception_class(e, InvalidValue)
    197:       end
    198:     end

uri() click to toggle source

Returns the URI identifying the database, which may not be the same as the URI used when connecting. This method can raise an error if the database used options instead of a connection string, and will not include uri parameters.

      Sequel.connect('postgres://localhost/db?user=billg').url
      # => "postgres://billg@localhost/db"

         # File lib/sequel/database/misc.rb, line 208
    208:     def uri
    209:       uri = URI::Generic.new(
    210:         adapter_scheme.to_s,
    211:         nil,
    212:         @opts[:host],
    213:         @opts[:port],
    214:         nil,
    215:         "/#{@opts[:database]}",
    216:         nil,
    217:         nil,
    218:         nil
    219:       )
    220:       uri.user = @opts[:user]
    221:       uri.password = @opts[:password] if uri.user
    222:       uri.to_s
    223:     end

url() click to toggle source

Explicit alias of uri for easier subclassing.

         # File lib/sequel/database/misc.rb, line 226
    226:     def url
    227:       uri
    228:     end

views(opts={}) click to toggle source

Return all views in the database as an array of symbols.

      DB.views # => [:gold_albums, :artists_with_many_albums]

         # File lib/sequel/database/query.rb, line 238
    238:     def views(opts={})
    239:       raise NotImplemented, "#views should be overridden by adapters"
    240:     end

### Private Instance Methods

_execute(conn, sql, opts) click to toggle source

Execute the given SQL on the given connection. If the :type option is :select, yield the result of the query, otherwise yield the connection if a block is given.

         # File lib/sequel/adapters/mysql.rb, line 168
    168:       def _execute(conn, sql, opts)
    169:         begin
    170:           r = log_yield(sql){conn.query(sql)}
    171:           if opts[:type] == :select
    172:             yield r if r
    173:           elsif block_given?
    174:             yield conn
    175:           end
    176:           if conn.respond_to?(:more_results?)
    177:             while conn.more_results? do
    178:               if r
    179:                 r.free
    180:                 r = nil
    181:               end
    182:               begin
    183:                 conn.next_result
    184:                 r = conn.use_result
    185:               rescue Mysql::Error => e
    186:                 raise_error(e, :disconnect=>true) if MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)
    187:                 break
    188:               end
    189:               yield r if opts[:type] == :select
    190:             end
    191:           end
    192:         rescue Mysql::Error => e
    193:           raise_error(e)
    194:         ensure
    195:           r.free if r
    196:           # Use up all results to avoid a commands out of sync message.
    197:           if conn.respond_to?(:more_results?)
    198:             while conn.more_results? do
    199:               begin
    200:                 conn.next_result
    201:                 r = conn.use_result
    202:               rescue Mysql::Error => e
    203:                 raise_error(e, :disconnect=>true) if MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)
    204:                 break
    205:               end
    206:               r.free if r
    207:             end
    208:           end
    209:         end
    210:       end

_table_exists?(ds) click to toggle source

Should raise an error if the table doesn’t not exist, and not raise an error if the table does exist.

         # File lib/sequel/database/query.rb, line 246
    246:     def _table_exists?(ds)
    247:       ds.get(Sequel::NULL)
    248:     end

_transaction(conn, opts={}) click to toggle source

Internal generic transaction method. Any exception raised by the given block will cause the transaction to be rolled back. If the exception is not a Sequel::Rollback, the error will be reraised. If no exception occurs inside the block, the transaction is commited.

         # File lib/sequel/database/query.rb, line 254
    254:     def _transaction(conn, opts={})
    255:       rollback = opts[:rollback]
    256:       begin
    257:         add_transaction(conn, opts)
    258:         begin_transaction(conn, opts)
    259:         if rollback == :always
    260:           begin
    261:             yield(conn)
    262:           rescue Exception => e1
    263:             raise e1
    264:           ensure
    265:             raise ::Sequel::Rollback unless e1
    266:           end
    267:         else
    268:           yield(conn)
    269:         end
    270:       rescue Exception => e
    271:         rollback_transaction(conn, opts)
    272:         transaction_error(e, :conn=>conn, :rollback=>rollback)
    273:       ensure
    274:         begin
    275:           committed = commit_or_rollback_transaction(e, conn, opts)
    276:         rescue Exception => e2
    277:           raise_error(e2, :classes=>database_error_classes, :conn=>conn)
    278:         ensure
    279:           remove_transaction(conn, committed)
    280:         end
    281:       end
    282:     end

add_transaction(conn, opts) click to toggle source

Add the current thread to the list of active transactions

         # File lib/sequel/database/query.rb, line 285
    285:     def add_transaction(conn, opts)
    286:       if supports_savepoints?
    287:         unless @transactions[conn]
    288:           @transactions[conn] = {:savepoint_level=>0}
    289:           @transactions[conn][:prepare] = opts[:prepare] if supports_prepared_transactions?
    290:         end
    291:       else
    292:         @transactions[conn] = {}
    293:         @transactions[conn][:prepare] = opts[:prepare] if supports_prepared_transactions?
    294:       end
    295:     end

after_transaction_commit(conn) click to toggle source

Call all stored after_commit blocks for the given transaction

         # File lib/sequel/database/query.rb, line 298
    298:     def after_transaction_commit(conn)
    299:       if ary = @transactions[conn][:after_commit]
    300:         ary.each{|b| b.call}
    301:       end
    302:     end

after_transaction_rollback(conn) click to toggle source

Call all stored after_rollback blocks for the given transaction

         # File lib/sequel/database/query.rb, line 305
    305:     def after_transaction_rollback(conn)
    306:       if ary = @transactions[conn][:after_rollback]
    307:         ary.each{|b| b.call}
    308:       end
    309:     end

already_in_transaction?(conn, opts) click to toggle source

Whether the current thread/connection is already inside a transaction

         # File lib/sequel/database/query.rb, line 312
    312:     def already_in_transaction?(conn, opts)
    313:       @transactions.has_key?(conn) && (!supports_savepoints? || !opts[:savepoint])
    314:     end

alter_table_sql(table, op) click to toggle source

The SQL to execute to modify the DDL for the given table name. op should be one of the operations returned by the AlterTableGenerator.

         # File lib/sequel/database/schema_methods.rb, line 241
    241:     def alter_table_sql(table, op)
    242:       quoted_name = quote_identifier(op[:name]) if op[:name]
    243:       alter_table_op = case op[:op]
    244:       when :add_column
    245:         "ADD COLUMN #{column_definition_sql(op)}"
    246:       when :drop_column
    247:         "DROP COLUMN #{quoted_name}#{' CASCADE' if op[:cascade]}"
    248:       when :rename_column
    249:         "RENAME COLUMN #{quoted_name} TO #{quote_identifier(op[:new_name])}"
    250:       when :set_column_type
    251:         "ALTER COLUMN #{quoted_name} TYPE #{type_literal(op)}"
    252:       when :set_column_default
    253:         "ALTER COLUMN #{quoted_name} SET DEFAULT #{literal(op[:default])}"
    254:       when :set_column_null
    255:         "ALTER COLUMN #{quoted_name} #{op[:null] ? 'DROP' : 'SET'} NOT NULL"
    256:       when :add_index
    257:         return index_definition_sql(table, op)
    258:       when :drop_index
    259:         return drop_index_sql(table, op)
    260:       when :add_constraint
    261:         "ADD #{constraint_definition_sql(op)}"
    262:       when :drop_constraint
    263:         "DROP CONSTRAINT #{quoted_name}#{' CASCADE' if op[:cascade]}"
    264:       else
    265:         raise Error, "Unsupported ALTER TABLE operation"
    266:       end
    267:       "ALTER TABLE #{quote_schema_table(table)} #{alter_table_op}"
    268:     end

alter_table_sql_list(table, operations) click to toggle source

Array of SQL DDL modification statements for the given table, corresponding to the DDL changes specified by the operations.

         # File lib/sequel/database/schema_methods.rb, line 272
    272:     def alter_table_sql_list(table, operations)
    273:       operations.map{|op| alter_table_sql(table, op)}
    274:     end

apply_alter_table(name, ops) click to toggle source

Apply the changes in the given alter table ops to the table given by name.

         # File lib/sequel/database/schema_methods.rb, line 235
    235:     def apply_alter_table(name, ops)
    236:       alter_table_sql_list(name, ops).flatten.each{|sql| execute_ddl(sql)}
    237:     end

auto_increment_sql() click to toggle source

The SQL string specify the autoincrement property, generally used by primary keys.

         # File lib/sequel/database/schema_methods.rb, line 278
    278:     def auto_increment_sql
    279:       AUTOINCREMENT
    280:     end

begin_new_transaction(conn, opts) click to toggle source

Start a new database connection on the given connection

         # File lib/sequel/database/query.rb, line 322
    322:     def begin_new_transaction(conn, opts)
    323:       log_connection_execute(conn, begin_transaction_sql)
    324:       set_transaction_isolation(conn, opts)
    325:     end

begin_savepoint_sql(depth) click to toggle source

SQL to start a new savepoint

         # File lib/sequel/database/query.rb, line 317
    317:     def begin_savepoint_sql(depth)
    318:       SQL_SAVEPOINT % depth
    319:     end

begin_transaction(conn, opts={}) click to toggle source

Start a new database transaction or a new savepoint on the given connection.

         # File lib/sequel/database/query.rb, line 328
    328:     def begin_transaction(conn, opts={})
    329:       if supports_savepoints?
    330:         th = @transactions[conn]
    331:         if (depth = th[:savepoint_level]) > 0
    332:           log_connection_execute(conn, begin_savepoint_sql(depth))
    333:         else
    334:           begin_new_transaction(conn, opts)
    335:         end
    336:         th[:savepoint_level] += 1
    337:       else
    338:         begin_new_transaction(conn, opts)
    339:       end
    340:     end

begin_transaction_sql() click to toggle source

SQL to BEGIN a transaction.

         # File lib/sequel/database/query.rb, line 343
    343:     def begin_transaction_sql
    344:       SQL_BEGIN
    345:     end

blank_object?(obj) click to toggle source

Returns true when the object is considered blank. The only objects that are blank are nil, false, strings with all whitespace, and ones that respond true to empty?

         # File lib/sequel/database/misc.rb, line 236
    236:     def blank_object?(obj)
    237:       return obj.blank? if obj.respond_to?(:blank?)
    238:       case obj
    239:       when NilClass, FalseClass
    240:         true
    241:       when Numeric, TrueClass
    242:         false
    243:       when String
    244:         obj.strip.empty?
    245:       else
    246:         obj.respond_to?(:empty?) ? obj.empty? : false
    247:       end
    248:     end

check_database_errors() click to toggle source

Convert exceptions raised from the block into DatabaseErrors.

         # File lib/sequel/adapters/postgres.rb, line 409
    409:       def check_database_errors
    410:         begin
    411:           yield
    412:         rescue => e
    413:           raise_error(e, :classes=>CONVERTED_EXCEPTIONS)
    414:         end
    415:       end

column_definition_auto_increment_sql(sql, column) click to toggle source

Add auto increment SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 295
    295:     def column_definition_auto_increment_sql(sql, column)
    296:       sql << " #{auto_increment_sql}" if column[:auto_increment]
    297:     end

column_definition_collate_sql(sql, column) click to toggle source

Add collate SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 300
    300:     def column_definition_collate_sql(sql, column)
    301:       sql << " COLLATE #{column[:collate]}" if column[:collate]
    302:     end

column_definition_default_sql(sql, column) click to toggle source

Add default SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 305
    305:     def column_definition_default_sql(sql, column)
    306:       sql << " DEFAULT #{literal(column[:default])}" if column.include?(:default)
    307:     end

column_definition_null_sql(sql, column) click to toggle source

Add null/not null SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 310
    310:     def column_definition_null_sql(sql, column)
    311:       null = column.fetch(:null, column[:allow_null])
    312:       sql << NOT_NULL if null == false
    313:       sql << NULL if null == true
    314:     end

column_definition_order() click to toggle source

The order of the column definition, as an array of symbols.

         # File lib/sequel/database/schema_methods.rb, line 283
    283:     def column_definition_order
    284:       self.class.const_get(:COLUMN_DEFINITION_ORDER)
    285:     end

column_definition_primary_key_sql(sql, column) click to toggle source

Add primary key SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 317
    317:     def column_definition_primary_key_sql(sql, column)
    318:       sql << PRIMARY_KEY if column[:primary_key]
    319:     end

column_definition_references_sql(sql, column) click to toggle source

Add foreign key reference SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 322
    322:     def column_definition_references_sql(sql, column)
    323:       sql << column_references_column_constraint_sql(column) if column[:table]
    324:     end

column_definition_sql(column) click to toggle source

SQL DDL fragment containing the column creation SQL for the given column.

         # File lib/sequel/database/schema_methods.rb, line 288
    288:     def column_definition_sql(column)
    289:       sql = "#{quote_identifier(column[:name])} #{type_literal(column)}"
    290:       column_definition_order.each{|m| send(:"column_definition_#{m}_sql", sql, column)}
    291:       sql
    292:     end

column_definition_unique_sql(sql, column) click to toggle source

Add unique constraint SQL fragment to column creation SQL.

         # File lib/sequel/database/schema_methods.rb, line 327
    327:     def column_definition_unique_sql(sql, column)
    328:       sql << UNIQUE if column[:unique]
    329:     end

column_list_sql(generator) click to toggle source

SQL for all given columns, used inside a CREATE TABLE block.

         # File lib/sequel/database/schema_methods.rb, line 332
    332:     def column_list_sql(generator)
    333:       (generator.columns.map{|c| column_definition_sql(c)} + generator.constraints.map{|c| constraint_definition_sql(c)}).join(COMMA_SEPARATOR)
    334:     end

column_references_column_constraint_sql(column) click to toggle source

SQL DDL fragment for column foreign key references (column constraints)

         # File lib/sequel/database/schema_methods.rb, line 337
    337:     def column_references_column_constraint_sql(column)
    338:       column_references_sql(column)
    339:     end

column_references_sql(column) click to toggle source

SQL DDL fragment for column foreign key references

         # File lib/sequel/database/schema_methods.rb, line 342
    342:     def column_references_sql(column)
    343:       sql = " REFERENCES #{quote_schema_table(column[:table])}"
    344:       sql << "(#{Array(column[:key]).map{|x| quote_identifier(x)}.join(COMMA_SEPARATOR)})" if column[:key]
    345:       sql << " ON DELETE #{on_delete_clause(column[:on_delete])}" if column[:on_delete]
    346:       sql << " ON UPDATE #{on_delete_clause(column[:on_update])}" if column[:on_update]
    347:       sql << " DEFERRABLE INITIALLY DEFERRED" if column[:deferrable]
    348:       sql
    349:     end

column_references_table_constraint_sql(constraint) click to toggle source

SQL DDL fragment for table foreign key references (table constraints)

         # File lib/sequel/database/schema_methods.rb, line 352
    352:     def column_references_table_constraint_sql(constraint)
    353:       "FOREIGN KEY #{literal(constraint[:columns])}#{column_references_sql(constraint)}"
    354:     end

column_schema_to_generator_opts(name, schema, options) click to toggle source

Convert the given name and parsed database schema into an array with a method name and arguments to it to pass to a Schema::Generator to recreate the column.

         # File lib/sequel/extensions/schema_dumper.rb, line 93
     93:     def column_schema_to_generator_opts(name, schema, options)
     94:       if options[:single_pk] && schema_autoincrementing_primary_key?(schema)
     95:         type_hash = options[:same_db] ? {:type=>schema[:db_type]} : column_schema_to_ruby_type(schema)
     96:         if type_hash == {:type=>Integer} || type_hash == {:type=>"integer"}
     97:           [:primary_key, name]
     98:         else
     99:           [:primary_key, name, type_hash]
    100:         end
    101:       else
    102:         col_opts = options[:same_db] ? {:type=>schema[:db_type]} : column_schema_to_ruby_type(schema)
    103:         type = col_opts.delete(:type)
    104:         col_opts.delete(:size) if col_opts[:size].nil?
    105:         col_opts[:default] = if schema[:ruby_default].nil?
    106:           column_schema_to_ruby_default_fallback(schema[:default], options)
    107:         else
    108:           schema[:ruby_default]
    109:         end
    110:         col_opts.delete(:default) if col_opts[:default].nil?
    111:         col_opts[:null] = false if schema[:allow_null] == false
    112:         [:column, name, type, col_opts]
    113:       end
    114:     end

column_schema_to_ruby_default(default, type) click to toggle source

Convert the given default, which should be a database specific string, into a ruby object.

         # File lib/sequel/database/query.rb, line 349
    349:     def column_schema_to_ruby_default(default, type)
    350:       return if default.nil?
    351:       orig_default = default
    352:       if database_type == :postgres and m = POSTGRES_DEFAULT_RE.match(default)
    353:         default = m[1] || m[2]
    354:       end
    355:       if database_type == :mssql and m = MSSQL_DEFAULT_RE.match(default)
    356:         default = m[1] || m[2]
    357:       end
    358:       if [:string, :blob, :date, :datetime, :time, :enum].include?(type)
    359:         if database_type == :mysql
    360:           return if [:date, :datetime, :time].include?(type) && MYSQL_TIMESTAMP_RE.match(default)
    361:           orig_default = default = "'#{default.gsub("'", "''").gsub('\\', '\\\\')}'"
    362:         end
    363:         return unless m = STRING_DEFAULT_RE.match(default)
    364:         default = m[1].gsub("''", "'")
    365:       end
    366:       res = begin
    367:         case type
    368:         when :boolean
    369:           case default
    370:           when /[f0]/
    371:             false
    372:           when /[t1]/
    373:             true
    374:           end
    375:         when :string, :enum
    376:           default
    377:         when :blob
    378:           Sequel::SQL::Blob.new(default)
    379:         when :integer
    380:           Integer(default)
    381:         when :float
    382:           Float(default)
    383:         when :date
    384:           Sequel.string_to_date(default)
    385:         when :datetime
    386:           DateTime.parse(default)
    387:         when :time
    388:           Sequel.string_to_time(default)
    389:         when :decimal
    390:           BigDecimal.new(default)
    391:         end
    392:       rescue
    393:         nil
    394:       end
    395:     end

column_schema_to_ruby_default_fallback(default, options) click to toggle source

If a database default exists and can’t be converted, return the string with the inspect method modified so that .lit is always appended after it, only if the :same_db option is used.

        # File lib/sequel/extensions/schema_dumper.rb, line 81
    81:     def column_schema_to_ruby_default_fallback(default, options)
    82:       if default.is_a?(String) && options[:same_db] && use_column_schema_to_ruby_default_fallback?
    83:         default = default.to_s
    84:         def default.inspect
    85:           "#{super}.lit"
    86:         end
    87:         default
    88:       end
    89:     end

column_schema_to_ruby_type(schema) click to toggle source

Convert the column schema information to a hash of column options, one of which must be :type. The other options added should modify that type (e.g. :size). If a database type is not recognized, return it as a String type.

         # File lib/sequel/extensions/schema_dumper.rb, line 119
    119:     def column_schema_to_ruby_type(schema)
    120:       case t = schema[:db_type].downcase
    121:       when /\A(?:medium|small)?int(?:eger)?(?:\((?:\d+)\))?(?: unsigned)?\z/
    122:         {:type=>Integer}
    123:       when /\Atinyint(?:\((\d+)\))?\z/
    124:         {:type =>schema[:type] == :boolean ? TrueClass : Integer}
    125:       when /\Abigint(?:\((?:\d+)\))?(?: unsigned)?\z/
    126:         {:type=>Bignum}
    127:       when /\A(?:real|float|double(?: precision)?)\z/
    128:         {:type=>Float}
    129:       when 'boolean'
    130:         {:type=>TrueClass}
    131:       when /\A(?:(?:tiny|medium|long|n)?text|clob)\z/
    132:         {:type=>String, :text=>true}
    133:       when 'date'
    134:         {:type=>Date}
    135:       when /\A(?:small)?datetime\z/
    136:         {:type=>DateTime}
    137:       when /\Atimestamp(?:\((\d+)\))?(?: with(?:out)? time zone)?\z/
    138:         {:type=>DateTime, :size=>($1.to_i if $1)}
    139:       when /\Atime(?: with(?:out)? time zone)?\z/
    140:         {:type=>Time, :only_time=>true}
    141:       when /\An?char(?:acter)?(?:\((\d+)\))?\z/
    142:         {:type=>String, :size=>($1.to_i if $1), :fixed=>true}
    143:       when /\A(?:n?varchar|character varying|bpchar|string)(?:\((\d+)\))?\z/
    144:         {:type=>String, :size=>($1.to_i if $1)}
    145:       when /\A(?:small)?money\z/
    146:         {:type=>BigDecimal, :size=>[19,2]}
    147:       when /\A(?:decimal|numeric|number)(?:\((\d+)(?:,\s*(\d+))?\))?\z/
    148:         s = [($1.to_i if $1), ($2.to_i if $2)].compact
    149:         {:type=>BigDecimal, :size=>(s.empty? ? nil : s)}
    150:       when /\A(?:bytea|(?:tiny|medium|long)?blob|(?:var)?binary)(?:\((\d+)\))?\z/
    151:         {:type=>File, :size=>($1.to_i if $1)}
    152:       when 'year'
    153:         {:type=>Integer}
    154:       else
    155:         {:type=>String}
    156:       end
    157:     end

commit_or_rollback_transaction(exception, conn, opts) click to toggle source

Whether to commit the current transaction. On ruby 1.9 and JRuby, transactions will be committed if Thread#kill is used on an thread that has a transaction open, and there isn’t a work around.

         # File lib/sequel/database/query.rb, line 419
    419:       def commit_or_rollback_transaction(exception, conn, opts)
    420:         if exception
    421:           false
    422:         else
    423:           commit_transaction(conn, opts)
    424:           true
    425:         end
    426:       end

commit_or_rollback_transaction(exception, conn, opts) click to toggle source

Whether to commit the current transaction. On ruby 1.8 and rubinius, Thread.current.status is checked because Thread#kill skips rescue blocks (so exception would be nil), but the transaction should still be rolled back.

         # File lib/sequel/database/query.rb, line 402
    402:       def commit_or_rollback_transaction(exception, conn, opts)
    403:         if exception
    404:           false
    405:         else
    406:           if Thread.current.status == 'aborting'
    407:             rollback_transaction(conn, opts)
    408:             false
    409:           else
    410:             commit_transaction(conn, opts)
    411:             true
    412:           end
    413:         end
    414:       end

commit_savepoint_sql(depth) click to toggle source

SQL to commit a savepoint

         # File lib/sequel/database/query.rb, line 430
    430:     def commit_savepoint_sql(depth)
    431:       SQL_RELEASE_SAVEPOINT % depth
    432:     end

commit_transaction(conn, opts={}) click to toggle source

Commit the active transaction on the connection

         # File lib/sequel/database/query.rb, line 435
    435:     def commit_transaction(conn, opts={})
    436:       if supports_savepoints?
    437:         depth = @transactions[conn][:savepoint_level]
    438:         log_connection_execute(conn, depth > 1 ? commit_savepoint_sql(depth-1) : commit_transaction_sql)
    439:       else
    440:         log_connection_execute(conn, commit_transaction_sql)
    441:       end
    442:     end

commit_transaction_sql() click to toggle source

SQL to COMMIT a transaction.

         # File lib/sequel/database/query.rb, line 445
    445:     def commit_transaction_sql
    446:       SQL_COMMIT
    447:     end

connection_execute_method() click to toggle source

Method called on the connection object to execute SQL on the database, used by the transaction code.

         # File lib/sequel/database/query.rb, line 451
    451:     def connection_execute_method
    452:       :execute
    453:     end

connection_execute_method() click to toggle source

MySQL connections use the query method to execute SQL without a result

         # File lib/sequel/adapters/mysql.rb, line 213
    213:       def connection_execute_method
    214:         :query
    215:       end

connection_pool_default_options() click to toggle source

The default options for the connection pool.

         # File lib/sequel/database/connecting.rb, line 240
    240:     def connection_pool_default_options
    241:       {}
    242:     end

constraint_definition_sql(constraint) click to toggle source

SQL DDL fragment specifying a constraint on a table.

         # File lib/sequel/database/schema_methods.rb, line 357
    357:     def constraint_definition_sql(constraint)
    358:       sql = constraint[:name] ? "CONSTRAINT #{quote_identifier(constraint[:name])} " : ""
    359:       case constraint[:type]
    360:       when :check
    361:         check = constraint[:check]
    362:         sql << "CHECK #{filter_expr((check.is_a?(Array) && check.length == 1) ? check.first : check)}"
    363:       when :primary_key
    364:         sql << "PRIMARY KEY #{literal(constraint[:columns])}"
    365:       when :foreign_key
    366:         sql << column_references_table_constraint_sql(constraint)
    367:       when :unique
    368:         sql << "UNIQUE #{literal(constraint[:columns])}"
    369:       else
    370:         raise Error, "Invalid constriant type #{constraint[:type]}, should be :check, :primary_key, :foreign_key, or :unique"
    371:       end
    372:       sql
    373:     end

convert_date_time(v) click to toggle source

If convert_invalid_date_time is nil, :nil, or :string and the conversion raises an InvalidValue exception, return v if :string and nil otherwise.

         # File lib/sequel/adapters/mysql.rb, line 220
    220:       def convert_date_time(v)
    221:         begin
    222:           yield v
    223:         rescue InvalidValue
    224:           case @convert_invalid_date_time
    225:           when nil, :nil
    226:             nil
    227:           when :string
    228:             v
    229:           else
    230:             raise
    231:           end
    232:         end
    233:       end

create_table_from_generator(name, generator, options) click to toggle source

Execute the create table statements using the generator.

         # File lib/sequel/database/schema_methods.rb, line 376
    376:     def create_table_from_generator(name, generator, options)
    377:       execute_ddl(create_table_sql(name, generator, options))
    378:     end

create_table_indexes_from_generator(name, generator, options) click to toggle source

Execute the create index statements using the generator.

         # File lib/sequel/database/schema_methods.rb, line 381
    381:     def create_table_indexes_from_generator(name, generator, options)
    382:       e = options[:ignore_index_errors] || options[:if_not_exists]
    383:       generator.indexes.each do |index|
    384:         begin
    385:           index_sql_list(name, [index]).each{|sql| execute_ddl(sql)}
    386:         rescue Error
    387:           raise unless e
    388:         end
    389:       end
    390:     end

create_table_sql(name, generator, options) click to toggle source

DDL statement for creating a table with the given name, columns, and options

         # File lib/sequel/database/schema_methods.rb, line 393
    393:     def create_table_sql(name, generator, options)
    394:       "CREATE #{temporary_table_sql if options[:temp]}TABLE#{' IF NOT EXISTS' if options[:if_not_exists]} #{options[:temp] ? quote_identifier(name) : quote_schema_table(name)} (#{column_list_sql(generator)})"
    395:     end

database_error_classes() click to toggle source

The MySQL adapter main error class is Mysql::Error

         # File lib/sequel/adapters/mysql.rb, line 236
    236:       def database_error_classes
    237:         [Mysql::Error]
    238:       end

database_error_classes() click to toggle source

Which transaction errors to translate, blank by default.

         # File lib/sequel/database/misc.rb, line 251
    251:     def database_error_classes
    252:       []
    253:     end

database_name() click to toggle source

The database name when using the native adapter is always stored in the :database option.

         # File lib/sequel/adapters/mysql.rb, line 248
    248:       def database_name
    249:         @opts[:database]
    250:       end

dataset_class_default() click to toggle source

The default dataset class to use for the database

         # File lib/sequel/database/dataset_defaults.rb, line 166
    166:     def dataset_class_default
    167:       self.class.const_get(:DatasetClass)
    168:     end

default_index_name(table_name, columns) click to toggle source

Default index name for the table and columns, may be too long for certain databases.

         # File lib/sequel/database/schema_methods.rb, line 399
    399:     def default_index_name(table_name, columns)
    400:       schema, table = schema_and_table(table_name)
    401:       "#{"#{schema}_" if schema and schema != default_schema}#{table}_#{columns.map{|c| [String, Symbol].any?{|cl| c.is_a?(cl)} ? c : literal(c).gsub(/\W/, '_')}.join(UNDERSCORE)}_index"
    402:     end

default_schema_default() click to toggle source

The default value for default_schema.

         # File lib/sequel/database/dataset_defaults.rb, line 171
    171:     def default_schema_default
    172:       nil
    173:     end

disconnect_connection(c) click to toggle source

Closes given database connection.

         # File lib/sequel/adapters/mysql.rb, line 253
    253:       def disconnect_connection(c)
    254:         c.close
    255:       rescue Mysql::Error
    256:         nil
    257:       end

disconnect_connection(conn) click to toggle source

Disconnect given connection

         # File lib/sequel/adapters/postgres.rb, line 418
    418:       def disconnect_connection(conn)
    419:         begin
    420:           conn.finish
    421:         rescue PGError
    422:         end
    423:       end

disconnect_error?(exception, opts) click to toggle source

Return true if exception represents a disconnect error, false otherwise.

         # File lib/sequel/database/misc.rb, line 256
    256:     def disconnect_error?(exception, opts)
    257:       opts[:disconnect]
    258:     end

disconnect_error?(e, opts) click to toggle source

Raise a disconnect error if the exception message matches the list of recognized exceptions.

         # File lib/sequel/adapters/mysql.rb, line 242
    242:       def disconnect_error?(e, opts)
    243:         super || (e.is_a?(::Mysql::Error) && MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message))
    244:       end

drop_index_sql(table, op) click to toggle source

The SQL to drop an index for the table.

         # File lib/sequel/database/schema_methods.rb, line 405
    405:     def drop_index_sql(table, op)
    406:       "DROP INDEX #{quote_identifier(op[:name] || default_index_name(table, op[:columns]))}"
    407:     end

drop_table_sql(name, options) click to toggle source

SQL DDL statement to drop the table with the given name.

         # File lib/sequel/database/schema_methods.rb, line 410
    410:     def drop_table_sql(name, options)
    411:       "DROP TABLE #{quote_schema_table(name)}#{' CASCADE' if options[:cascade]}"
    412:     end

drop_view_sql(name, options) click to toggle source

SQL DDL statement to drop a view with the given name.

         # File lib/sequel/database/schema_methods.rb, line 415
    415:     def drop_view_sql(name, options)
    416:       "DROP VIEW #{quote_schema_table(name)}#{' CASCADE' if options[:cascade]}"
    417:     end

dump_table_indexes(table, meth, options={}) click to toggle source

Return a string that containing add_index/drop_index method calls for creating the index migration.

         # File lib/sequel/extensions/schema_dumper.rb, line 161
    161:     def dump_table_indexes(table, meth, options={})
    162:       return '' unless respond_to?(:indexes)
    163:       im = method(:index_to_generator_opts)
    164:       indexes = indexes(table).sort_by{|k,v| k.to_s}
    165:       gen = Schema::Generator.new(self) do
    166:         indexes.each{|iname, iopts| send(:index, iopts[:columns], im.call(table, iname, iopts))}
    167:       end
    168:       gen.dump_indexes(meth=>table, :ignore_errors=>!options[:same_db])
    169:     end

execute_prepared_statement(name, opts={}) click to toggle source

Execute the prepared statement with the given name on an available connection, using the given args. If the connection has not prepared a statement with the given name yet, prepare it. If the connection has prepared a statement with the same name and different SQL, deallocate that statement first and then prepare this statement. If a block is given, yield the result, otherwise, return the number of rows changed. If the :insert option is passed, return the value of the primary key for the last inserted row.

         # File lib/sequel/adapters/postgres.rb, line 433
    433:       def execute_prepared_statement(name, opts={})
    434:         ps = prepared_statements[name]
    435:         sql = ps.prepared_sql
    436:         ps_name = name.to_s
    437:         args = opts[:arguments]
    438:         synchronize(opts[:server]) do |conn|
    439:           unless conn.prepared_statements[ps_name] == sql
    440:             if conn.prepared_statements.include?(ps_name)
    441:               conn.execute("DEALLOCATE #{ps_name}") unless conn.prepared_statements[ps_name] == sql
    442:             end
    443:             conn.prepared_statements[ps_name] = sql
    444:             conn.check_disconnect_errors{log_yield("PREPARE #{ps_name} AS #{sql}"){conn.prepare(ps_name, sql)}}
    445:           end
    446:           q = conn.check_disconnect_errors{log_yield("EXECUTE #{ps_name}", args){conn.exec_prepared(ps_name, args)}}
    447:           if opts[:table] && opts[:values]
    448:             insert_result(conn, opts[:table], opts[:values])
    449:           else
    450:             begin
    451:               block_given? ? yield(q) : q.cmd_tuples
    452:             ensure
    453:               q.clear
    454:             end
    455:           end
    456:         end
    457:       end

filter_expr(*args, &block) click to toggle source

Proxy the filter_expr call to the dataset, used for creating constraints.

         # File lib/sequel/database/schema_methods.rb, line 420
    420:     def filter_expr(*args, &block)
    421:       schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr, *args, &block))
    422:     end

get_conversion_procs(conn) click to toggle source

Return the conversion procs hash to use for this database

         # File lib/sequel/adapters/postgres.rb, line 460
    460:       def get_conversion_procs(conn)
    461:         procs = PG_TYPES.dup
    462:         procs[1114] = method(:to_application_timestamp)
    463:         procs[1184] = method(:to_application_timestamp)
    464:         conn.execute("SELECT oid, typname FROM pg_type where typtype = 'b'") do |res|
    465:           res.ntuples.times do |recnum|
    466:             if pr = PG_NAMED_TYPES[res.getvalue(recnum, 1).untaint.to_sym]
    467:               procs[res.getvalue(recnum, 0).to_i] ||= pr
    468:             end
    469:           end
    470:         end
    471:         procs
    472:       end

identifier_input_method_default() click to toggle source

The method to apply to identifiers going into the database by default. Should be overridden in subclasses for databases that fold unquoted identifiers to lower case instead of uppercase, such as MySQL, PostgreSQL, and SQLite.

         # File lib/sequel/database/dataset_defaults.rb, line 179
    179:     def identifier_input_method_default
    180:       :upcase
    181:     end

identifier_output_method_default() click to toggle source

The method to apply to identifiers coming the database by default. Should be overridden in subclasses for databases that fold unquoted identifiers to lower case instead of uppercase, such as MySQL, PostgreSQL, and SQLite.

         # File lib/sequel/database/dataset_defaults.rb, line 187
    187:     def identifier_output_method_default
    188:       :downcase
    189:     end

index_definition_sql(table_name, index) click to toggle source

SQL DDL statement for creating an index for the table with the given name and index specifications.

         # File lib/sequel/database/schema_methods.rb, line 426
    426:     def index_definition_sql(table_name, index)
    427:       index_name = index[:name] || default_index_name(table_name, index[:columns])
    428:       if index[:type]
    429:         raise Error, "Index types are not supported for this database"
    430:       elsif index[:where]
    431:         raise Error, "Partial indexes are not supported for this database"
    432:       else
    433:         "CREATE #{'UNIQUE ' if index[:unique]}INDEX #{quote_identifier(index_name)} ON #{quote_schema_table(table_name)} #{literal(index[:columns])}"
    434:       end
    435:     end

index_sql_list(table_name, indexes) click to toggle source

Array of SQL DDL statements, one for each index specification, for the given table.

         # File lib/sequel/database/schema_methods.rb, line 439
    439:     def index_sql_list(table_name, indexes)
    440:       indexes.map{|i| index_definition_sql(table_name, i)}
    441:     end

index_to_generator_opts(table, name, index_opts) click to toggle source

Convert the parsed index information into options to the Generators index method.

         # File lib/sequel/extensions/schema_dumper.rb, line 172
    172:     def index_to_generator_opts(table, name, index_opts)
    173:       h = {}
    174:       h[:name] = name unless default_index_name(table, index_opts[:columns]) == name.to_s
    175:       h[:unique] = true if index_opts[:unique]
    176:       h
    177:     end

input_identifier_meth(ds=nil) click to toggle source

Return a Method object for the dataset’s output_identifier_method. Used in metadata parsing to make sure the returned information is in the correct format.

         # File lib/sequel/database/query.rb, line 458
    458:     def input_identifier_meth(ds=nil)
    459:       (ds || dataset).method(:input_identifier)
    460:     end

log_connection_execute(conn, sql) click to toggle source

Log the given SQL and then execute it on the connection, used by the transaction code.

        # File lib/sequel/database/logging.rb, line 52
    52:     def log_connection_execute(conn, sql)
    53:       log_yield(sql){conn.send(connection_execute_method, sql)}
    54:     end

log_duration(duration, message) click to toggle source

Log message with message prefixed by duration at info level, or warn level if duration is greater than log_warn_duration.

        # File lib/sequel/database/logging.rb, line 58
    58:     def log_duration(duration, message)
    59:       log_each((lwd = log_warn_duration and duration >= lwd) ? :warn : sql_log_level, "(#{sprintf('%0.6fs', duration)}) #{message}")
    60:     end

log_each(level, message) click to toggle source

Log message at level (which should be :error, :warn, or :info) to all loggers.

        # File lib/sequel/database/logging.rb, line 64
    64:     def log_each(level, message)
    65:       @loggers.each{|logger| logger.send(level, message)}
    66:     end

metadata_dataset() click to toggle source

Return a dataset that uses the default identifier input and output methods for this database. Used when parsing metadata so that column symbols are returned as expected.

         # File lib/sequel/database/query.rb, line 465
    465:     def metadata_dataset
    466:       return @metadata_dataset if @metadata_dataset
    467:       ds = dataset
    468:       ds.identifier_input_method = identifier_input_method_default
    469:       ds.identifier_output_method = identifier_output_method_default
    470:       @metadata_dataset = ds
    471:     end

on_delete_clause(action) click to toggle source

SQL DDL ON DELETE fragment to use, based on the given action. The following actions are recognized:

- :cascade - Delete rows referencing this row.

- :no_action (default) - Raise an error if other rows reference this row, allow deferring of the integrity check.

- :restrict - Raise an error if other rows reference this row, but do not allow deferring the integrity check.

- :set_default - Set columns referencing this row to their default value.

- :set_null - Set columns referencing this row to NULL.

         # File lib/sequel/database/schema_methods.rb, line 453
    453:     def on_delete_clause(action)
    454:       case action
    455:       when :restrict
    456:         RESTRICT
    457:       when :cascade
    458:         CASCADE
    459:       when :set_null
    460:         SET_NULL
    461:       when :set_default
    462:         SET_DEFAULT
    463:       else
    464:         NO_ACTION
    465:       end
    466:     end

output_identifier_meth(ds=nil) click to toggle source

Return a Method object for the dataset’s output_identifier_method. Used in metadata parsing to make sure the returned information is in the correct format.

         # File lib/sequel/database/query.rb, line 476
    476:     def output_identifier_meth(ds=nil)
    477:       (ds || dataset).method(:output_identifier)
    478:     end

quote_identifier(v) click to toggle source

Proxy the quote_identifier method to the dataset, used for quoting tables and columns.

         # File lib/sequel/database/schema_methods.rb, line 474
    474:     def quote_identifier(v)
    475:       schema_utility_dataset.quote_identifier(v)
    476:     end

quote_identifiers_default() click to toggle source

Whether to quote identifiers by default for this database, true by default.

         # File lib/sequel/database/dataset_defaults.rb, line 193
    193:     def quote_identifiers_default
    194:       true
    195:     end

quote_schema_table(table) click to toggle source

Proxy the quote_schema_table method to the dataset

         # File lib/sequel/database/schema_methods.rb, line 469
    469:     def quote_schema_table(table)
    470:       schema_utility_dataset.quote_schema_table(table)
    471:     end

raise_error(exception, opts={}) click to toggle source

Convert the given exception to a DatabaseError, keeping message and traceback.

         # File lib/sequel/database/misc.rb, line 262
    262:     def raise_error(exception, opts={})
    263:       if !opts[:classes] || Array(opts[:classes]).any?{|c| exception.is_a?(c)}
    264:         raise Sequel.convert_exception_class(exception, disconnect_error?(exception, opts) ? DatabaseDisconnectError : DatabaseError)
    265:       else
    266:         raise exception
    267:       end
    268:     end

remove_cached_schema(table) click to toggle source

Remove the cached schema for the given schema name

         # File lib/sequel/database/query.rb, line 481
    481:     def remove_cached_schema(table)
    482:       @schemas.delete(quote_schema_table(table)) if @schemas
    483:     end

remove_transaction(conn, committed) click to toggle source

Remove the current thread from the list of active transactions

         # File lib/sequel/database/query.rb, line 486
    486:     def remove_transaction(conn, committed)
    487:       if !supports_savepoints? || ((@transactions[conn][:savepoint_level] -= 1) <= 0)
    488:         begin
    489:           if committed
    490:             after_transaction_commit(conn)
    491:           else
    492:             after_transaction_rollback(conn)
    493:           end
    494:         ensure
    495:           @transactions.delete(conn)
    496:         end
    497:       end
    498:     end

rename_table_sql(name, new_name) click to toggle source

SQL DDL statement for renaming a table.

         # File lib/sequel/database/schema_methods.rb, line 479
    479:     def rename_table_sql(name, new_name)
    480:       "ALTER TABLE #{quote_schema_table(name)} RENAME TO #{quote_schema_table(new_name)}"
    481:     end

reset_schema_utility_dataset() click to toggle source

Remove the cached schema_utility_dataset, because the identifier quoting has changed.

         # File lib/sequel/database/schema_methods.rb, line 485
    485:     def reset_schema_utility_dataset
    486:       @schema_utility_dataset = nil
    487:     end

rollback_savepoint_sql(depth) click to toggle source

SQL to rollback to a savepoint

         # File lib/sequel/database/query.rb, line 501
    501:     def rollback_savepoint_sql(depth)
    502:       SQL_ROLLBACK_TO_SAVEPOINT % depth
    503:     end

rollback_transaction(conn, opts={}) click to toggle source

Rollback the active transaction on the connection

         # File lib/sequel/database/query.rb, line 506
    506:     def rollback_transaction(conn, opts={})
    507:       if supports_savepoints?
    508:         depth = @transactions[conn][:savepoint_level]
    509:         log_connection_execute(conn, depth > 1 ? rollback_savepoint_sql(depth-1) : rollback_transaction_sql)
    510:       else
    511:         log_connection_execute(conn, rollback_transaction_sql)
    512:       end
    513:     end

rollback_transaction_sql() click to toggle source

SQL to ROLLBACK a transaction.

         # File lib/sequel/database/query.rb, line 516
    516:     def rollback_transaction_sql
    517:       SQL_ROLLBACK
    518:     end

schema_and_table(table_name) click to toggle source

Split the schema information from the table

         # File lib/sequel/database/schema_methods.rb, line 490
    490:     def schema_and_table(table_name)
    491:       schema_utility_dataset.schema_and_table(table_name)
    492:     end

schema_autoincrementing_primary_key?(schema) click to toggle source

Return true if the given column schema represents an autoincrementing primary key.

         # File lib/sequel/database/schema_methods.rb, line 495
    495:     def schema_autoincrementing_primary_key?(schema)
    496:       !!schema[:primary_key]
    497:     end

schema_column_type(db_type) click to toggle source

Match the database’s column type to a ruby type via a regular expression, and return the ruby type as a symbol such as :integer or :string.

         # File lib/sequel/database/query.rb, line 523
    523:     def schema_column_type(db_type)
    524:       case db_type
    525:       when /\Ainterval\z/o
    526:         :interval
    527:       when /\A(character( varying)?|n?(var)?char|n?text)/o
    528:         :string
    529:       when /\A(int(eger)?|(big|small|tiny)int)/o
    530:         :integer
    531:       when /\Adate\z/o
    532:         :date
    533:       when /\A((small)?datetime|timestamp( with(out)? time zone)?)\z/o
    534:         :datetime
    535:       when /\Atime( with(out)? time zone)?\z/o
    536:         :time
    537:       when /\A(bool(ean)?)\z/o
    538:         :boolean
    539:       when /\A(real|float|double( precision)?)\z/o
    540:         :float
    541:       when /\A(?:(?:(?:num(?:ber|eric)?|decimal)(?:\(\d+,\s*(\d+|false|true)\))?)|(?:small)?money)\z/o
    542:         $1 && ['0', 'false'].include?($1) ? :integer : :decimal
    543:       when /bytea|[bc]lob|image|(var)?binary/o
    544:         :blob
    545:       when /\Aenum/o
    546:         :enum
    547:       end
    548:     end

schema_column_type(db_type) click to toggle source

Convert tinyint(1) type to boolean if convert_tinyint_to_bool is true

         # File lib/sequel/adapters/mysql.rb, line 260
    260:       def schema_column_type(db_type)
    261:         convert_tinyint_to_bool && db_type == 'tinyint(1)' ? :boolean : super
    262:       end

schema_utility_dataset() click to toggle source

The dataset to use for proxying certain schema methods.

         # File lib/sequel/database/schema_methods.rb, line 500
    500:     def schema_utility_dataset
    501:       @schema_utility_dataset ||= dataset
    502:     end

server_opts(server) click to toggle source

Return the options for the given server by merging the generic options for all server with the specific options for the given server specified in the :servers option.

         # File lib/sequel/database/connecting.rb, line 247
    247:     def server_opts(server)
    248:       opts = if @opts[:servers] and server_options = @opts[:servers][server]
    249:         case server_options
    250:         when Hash
    251:           @opts.merge(server_options)
    252:         when Proc
    253:           @opts.merge(server_options.call(self))
    254:         else
    255:           raise Error, 'Server opts should be a hash or proc'
    256:         end
    257:       elsif server.is_a?(Hash)
    258:         @opts.merge(server)
    259:       else
    260:         @opts.dup
    261:       end
    262:       opts.delete(:servers)
    263:       opts
    264:     end

set_transaction_isolation(conn, opts) click to toggle source

Set the transaction isolation level on the given connection

         # File lib/sequel/database/query.rb, line 551
    551:     def set_transaction_isolation(conn, opts)
    552:       if supports_transaction_isolation_levels? and level = opts.fetch(:isolation, transaction_isolation_level)
    553:         log_connection_execute(conn, set_transaction_isolation_sql(level))
    554:       end
    555:     end

set_transaction_isolation_sql(level) click to toggle source

SQL to set the transaction isolation level

         # File lib/sequel/database/query.rb, line 558
    558:     def set_transaction_isolation_sql(level)
    559:       "SET TRANSACTION ISOLATION LEVEL #{TRANSACTION_ISOLATION_LEVELS[level]}"
    560:     end

temporary_table_sql() click to toggle source

SQL DDL fragment for temporary table

         # File lib/sequel/database/schema_methods.rb, line 505
    505:     def temporary_table_sql
    506:       self.class.const_get(:TEMPORARY)
    507:     end

transaction_error(e, opts={}) click to toggle source

Raise a database error unless the exception is an Rollback.

         # File lib/sequel/database/query.rb, line 563
    563:     def transaction_error(e, opts={})
    564:       if e.is_a?(Rollback)
    565:         raise e if opts[:rollback] == :reraise
    566:       else
    567:         raise_error(e, opts.merge(:classes=>database_error_classes))
    568:       end
    569:     end

type_literal(column) click to toggle source

SQL fragment specifying the type of a given column.

         # File lib/sequel/database/schema_methods.rb, line 510
    510:     def type_literal(column)
    511:       column[:type].is_a?(Class) ? type_literal_generic(column) : type_literal_specific(column)
    512:     end

type_literal_generic(column) click to toggle source

SQL fragment specifying the full type of a column, consider the type with possible modifiers.

         # File lib/sequel/database/schema_methods.rb, line 516
    516:     def type_literal_generic(column)
    517:       meth = "type_literal_generic_#{column[:type].name.to_s.downcase}"
    518:       if respond_to?(meth, true)
    519:         send(meth, column)
    520:       else
    521:         raise Error, "Unsupported ruby class used as database type: #{column[:type]}"
    522:       end
    523:     end

type_literal_generic_bigdecimal(column) click to toggle source

Alias for type_literal_generic_numeric, to make overriding in a subclass easier.

         # File lib/sequel/database/schema_methods.rb, line 526
    526:     def type_literal_generic_bigdecimal(column)
    527:       type_literal_generic_numeric(column)
    528:     end

type_literal_generic_bignum(column) click to toggle source

Sequel uses the bigint type by default for Bignums.

         # File lib/sequel/database/schema_methods.rb, line 531
    531:     def type_literal_generic_bignum(column)
    532:       :bigint
    533:     end

type_literal_generic_date(column) click to toggle source

Sequel uses the date type by default for Dates.

         # File lib/sequel/database/schema_methods.rb, line 536
    536:     def type_literal_generic_date(column)
    537:       :date
    538:     end

type_literal_generic_datetime(column) click to toggle source

Sequel uses the timestamp type by default for DateTimes.

         # File lib/sequel/database/schema_methods.rb, line 541
    541:     def type_literal_generic_datetime(column)
    542:       :timestamp
    543:     end

type_literal_generic_falseclass(column) click to toggle source

Alias for type_literal_generic_trueclass, to make overriding in a subclass easier.

         # File lib/sequel/database/schema_methods.rb, line 546
    546:     def type_literal_generic_falseclass(column)
    547:       type_literal_generic_trueclass(column)
    548:     end

type_literal_generic_file(column) click to toggle source

Sequel uses the blob type by default for Files.

         # File lib/sequel/database/schema_methods.rb, line 551
    551:     def type_literal_generic_file(column)
    552:       :blob
    553:     end

type_literal_generic_fixnum(column) click to toggle source

Alias for type_literal_generic_integer, to make overriding in a subclass easier.

         # File lib/sequel/database/schema_methods.rb, line 556
    556:     def type_literal_generic_fixnum(column)
    557:       type_literal_generic_integer(column)
    558:     end

type_literal_generic_float(column) click to toggle source

Sequel uses the double precision type by default for Floats.

         # File lib/sequel/database/schema_methods.rb, line 561
    561:     def type_literal_generic_float(column)
    562:       :"double precision"
    563:     end

type_literal_generic_integer(column) click to toggle source

Sequel uses the integer type by default for integers

         # File lib/sequel/database/schema_methods.rb, line 566
    566:     def type_literal_generic_integer(column)
    567:       :integer
    568:     end

type_literal_generic_numeric(column) click to toggle source

Sequel uses the numeric type by default for Numerics and BigDecimals. If a size is given, it is used, otherwise, it will default to whatever the database default is for an unsized value.

         # File lib/sequel/database/schema_methods.rb, line 573
    573:     def type_literal_generic_numeric(column)
    574:       column[:size] ? "numeric(#{Array(column[:size]).join(', ')})" : :numeric
    575:     end

type_literal_generic_string(column) click to toggle source

Sequel uses the varchar type by default for Strings. If a size isn’t present, Sequel assumes a size of 255. If the :fixed option is used, Sequel uses the char type. If the :text option is used, Sequel uses the :text type.

         # File lib/sequel/database/schema_methods.rb, line 581
    581:     def type_literal_generic_string(column)
    582:       if column[:text]
    583:         :text
    584:       elsif column[:fixed]
    585:         "char(#{column[:size]||255})"
    586:       else
    587:         "varchar(#{column[:size]||255})"
    588:       end
    589:     end

type_literal_generic_time(column) click to toggle source

Sequel uses the timestamp type by default for Time values. If the :only_time option is used, the time type is used.

         # File lib/sequel/database/schema_methods.rb, line 593
    593:     def type_literal_generic_time(column)
    594:       column[:only_time] ? :time : :timestamp
    595:     end

type_literal_generic_trueclass(column) click to toggle source

Sequel uses the boolean type by default for TrueClass and FalseClass.

         # File lib/sequel/database/schema_methods.rb, line 598
    598:     def type_literal_generic_trueclass(column)
    599:       :boolean
    600:     end

type_literal_specific(column) click to toggle source

SQL fragment for the given type of a column if the column is not one of the generic types specified with a ruby class.

         # File lib/sequel/database/schema_methods.rb, line 604
    604:     def type_literal_specific(column)
    605:       type = column[:type]
    606:       type = "double precision" if type.to_s == 'double'
    607:       column[:size] ||= 255 if type.to_s == 'varchar'
    608:       elements = column[:size] || column[:elements]
    609:       "#{type}#{literal(Array(elements)) if elements}#{UNSIGNED if column[:unsigned]}"
    610:     end

typecast_value_blob(value) click to toggle source

Typecast the value to an SQL::Blob

         # File lib/sequel/database/misc.rb, line 271
    271:     def typecast_value_blob(value)
    272:       value.is_a?(Sequel::SQL::Blob) ? value : Sequel::SQL::Blob.new(value)
    273:     end

typecast_value_boolean(value) click to toggle source

Typecast the value to true, false, or nil

         # File lib/sequel/database/misc.rb, line 276
    276:     def typecast_value_boolean(value)
    277:       case value
    278:       when false, 0, "0", /\Af(alse)?\z/, /\Ano?\z/
    279:         false
    280:       else
    281:         blank_object?(value) ? nil : true
    282:       end
    283:     end

typecast_value_date(value) click to toggle source

Typecast the value to a Date

         # File lib/sequel/database/misc.rb, line 286
    286:     def typecast_value_date(value)
    287:       case value
    288:       when DateTime, Time
    289:         Date.new(value.year, value.month, value.day)
    290:       when Date
    291:         value
    292:       when String
    293:         Sequel.string_to_date(value)
    294:       when Hash
    295:         Date.new(*[:year, :month, :day].map{|x| (value[x] || value[x.to_s]).to_i})
    296:       else
    297:         raise InvalidValue, "invalid value for Date: #{value.inspect}"
    298:       end
    299:     end

typecast_value_datetime(value) click to toggle source

Typecast the value to a DateTime or Time depending on Sequel.datetime_class

         # File lib/sequel/database/misc.rb, line 302
    302:     def typecast_value_datetime(value)
    303:       Sequel.typecast_to_application_timestamp(value)
    304:     end

typecast_value_decimal(value) click to toggle source

Typecast the value to a BigDecimal

         # File lib/sequel/database/misc.rb, line 307
    307:     def typecast_value_decimal(value)
    308:       case value
    309:       when BigDecimal
    310:         value
    311:       when String, Numeric
    312:         BigDecimal.new(value.to_s)
    313:       else
    314:         raise InvalidValue, "invalid value for BigDecimal: #{value.inspect}"
    315:       end
    316:     end

typecast_value_float(value) click to toggle source

Typecast the value to a Float

         # File lib/sequel/database/misc.rb, line 319
    319:     def typecast_value_float(value)
    320:       Float(value)
    321:     end

typecast_value_integer(value) click to toggle source

Typecast the value to an Integer

         # File lib/sequel/database/misc.rb, line 335
    335:       def typecast_value_integer(value)
    336:         Integer(value.is_a?(String) ? value.sub(LEADING_ZERO_RE, LEADING_ZERO_REP) : value)
    337:       end

typecast_value_integer(value) click to toggle source

Typecast the value to an Integer

         # File lib/sequel/database/misc.rb, line 328
    328:       def typecast_value_integer(value)
    329:         (value.is_a?(String) && value =~ LEADING_ZERO_RE) ? Integer(value, 10) : Integer(value)
    330:       end

typecast_value_string(value) click to toggle source

Typecast the value to a String

         # File lib/sequel/database/misc.rb, line 341
    341:     def typecast_value_string(value)
    342:       value.to_s
    343:     end

typecast_value_time(value) click to toggle source

Typecast the value to a Time

         # File lib/sequel/database/misc.rb, line 346
    346:     def typecast_value_time(value)
    347:       case value
    348:       when Time
    349:         if value.is_a?(SQLTime)
    350:           value
    351:         else
    352:           SQLTime.create(value.hour, value.min, value.sec, value.respond_to?(:nsec) ? value.nsec/1000.0 : value.usec)
    353:         end
    354:       when String
    355:         Sequel.string_to_time(value)
    356:       when Hash
    357:         SQLTime.create(*[:hour, :minute, :second].map{|x| (value[x] || value[x.to_s]).to_i})
    358:       else
    359:         raise Sequel::InvalidValue, "invalid value for Time: #{value.inspect}"
    360:       end
    361:     end

use_column_schema_to_ruby_default_fallback?() click to toggle source

Don’t use the “…”.lit fallback on MySQL, since the defaults it uses aren’t valid literal SQL values.

         # File lib/sequel/extensions/schema_dumper.rb, line 181
    181:     def use_column_schema_to_ruby_default_fallback?
    182:       database_type != :mysql
    183:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.