- A
- C
- D
- N
- P
- Q
- R
- S
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 237 def compare_versions(v1, v2) v1_seg = v1.split(".") v2_seg = v2.split(".") 0.upto([v1_seg.length,v2_seg.length].min) do |i| step = (v1_seg[i].to_i <=> v2_seg[i].to_i) return step unless step == 0 end return v1_seg.length <=> v2_seg.length end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 248 def initialize(connection, logger, connection_options, config) super(connection, logger) @connection_options, @config = connection_options, config @transaction_mode = :pessimistic # Start out in auto-commit mode self.rollback_db_transaction # threaded_connections_test.rb will fail unless we set the session # to optimistic locking mode # set_pessimistic_transactions # execute "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, LOCKING OPTIMISTIC" end
CONNECTION MANAGEMENT ====================================
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 432 def active? true if @connection.status == 1 rescue => e false end
Adds a new column to the named table. See ActiveRecord::ConnectionAdapters::TableDefinition#column for details of the options you can use.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 789 def add_column(table_name, column_name, type, options = {}) add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}" options[:type] = type add_column_options!(add_column_sql, options) execute(add_column_sql) end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 625 def classes_for_table_name(table) ActiveRecord::Base.send(:subclasses).select {|klass| klass.table_name == table} end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 745 def create_table(name, options = {}) table_definition = TableDefinition.new(self) table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false yield table_definition if options[:force] drop_table(name) rescue nil end create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE " create_sql << "#{name} (" create_sql << table_definition.to_sql create_sql << ") #{options[:options]}" begin_db_transaction execute create_sql commit_db_transaction rescue ActiveRecord::StatementInvalid => e raise e unless e.message.match(%rTable name - \w* - exists/) end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 660 def current_database select_value('SELECT "CATALOG_NAME" FROM INFORMATION_SCHEMA.CATALOGS').downcase end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 611 def default_sequence_name(table, column) table end
Close this connection
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 444 def disconnect! @connection.close rescue nil @active = false end
Drops a table from the database.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 781 def drop_table(name, options = {}) execute "DROP TABLE #{name} RESTRICT" rescue ActiveRecord::StatementInvalid => e raise e unless e.message.match(%rReferenced TABLE - \w* - does not exist/) end
Returns the next sequence value from a sequence generator. Not generally called directly; used by ActiveRecord to get the next primary key value when inserting a new database record (see prefetch_primary_key?).
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 605 def next_sequence_value(sequence_name) unique = select_value("SELECT UNIQUE FROM #{sequence_name}","Next Sequence Value") # The test cases cannot handle a zero primary key unique.zero? ? select_value("SELECT UNIQUE FROM #{sequence_name}","Next Sequence Value") : unique end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 598 def prefetch_primary_key?(table_name = nil) true end
Quotes the column value to help prevent SQL injection attacks.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 297 def quote(value, column = nil) return value.quoted_id if value.respond_to?(:quoted_id) retvalue = "<INVALID>" puts "quote(#{value.inspect}(#{value.class}),#{column.type.inspect})" if FB_TRACE # If a column was passed in, use column type information unless value.nil? if column retvalue = case column.type when :string if value.kind_of?(String) "'#{quote_string(value.to_s)}'" # ' (for ruby-mode) else "'#{quote_string(value.to_yaml)}'" end when :integer if value.kind_of?(TrueClass) '1' elsif value.kind_of?(FalseClass) '0' else value.to_i.to_s end when :float value.to_f.to_s when :decimal value.to_d.to_s("F") when :datetime, :timestamp "TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'" when :time "TIME '#{value.strftime("%H:%M:%S")}'" when :date "DATE '#{value.strftime("%Y-%m-%d")}'" when :twelvebytekey value = value.to_s.unpack("H*").first unless value.kind_of?(TwelveByteKey) "X'#{value.to_s}'" when :boolean value = quoted_true if value.kind_of?(TrueClass) value = quoted_false if value.kind_of?(FalseClass) value when :binary blob_handle = @connection.create_blob(value.to_s) puts "SQL -> Insert #{value.to_s.length} byte blob as #{retvalue}" if FB_TRACE blob_handle.handle when :text if value.kind_of?(String) clobdata = value.to_s # ' (for ruby-mode) else clobdata = value.to_yaml end clob_handle = @connection.create_clob(clobdata) puts "SQL -> Insert #{value.to_s.length} byte clob as #{retvalue}" if FB_TRACE clob_handle.handle else raise "*** UNKNOWN TYPE: #{column.type.inspect}" end # case # Since we don't have column type info, make a best guess based # on the Ruby class of the value else retvalue = case value when ActiveRecord::ConnectionAdapters::TwelveByteKey s = value.unpack("H*").first "X'#{s}'" when String if column && column.type == :binary s = value.unpack("H*").first "X'#{s}'" elsif column && [:integer, :float, :decimal].include?(column.type) value.to_s else "'#{quote_string(value)}'" # ' (for ruby-mode) end when NilClass "NULL" when TrueClass (column && column.type == :integer ? '1' : quoted_true) when FalseClass (column && column.type == :integer ? '0' : quoted_false) when Float, Fixnum, Bignum, BigDecimal value.to_s when Time, Date, DateTime if column case column.type when :date "DATE '#{value.strftime("%Y-%m-%d")}'" when :time "TIME '#{value.strftime("%H:%M:%S")}'" when :timestamp "TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'" else raise NotImplementedError, "Unknown column type!" end # case else # Column wasn't passed in, so try to guess the right type if value.kind_of? Date "DATE '#{value.strftime("%Y-%m-%d")}'" else if [:hour, :min, :sec].all? {|part| value.send(:part).zero? } "TIME '#{value.strftime("%H:%M:%S")}'" else "TIMESTAMP '#{quoted_date(value)}'" end end end #if column else "'#{quote_string(value.to_yaml)}'" end #case end else retvalue = "NULL" end retvalue end
Quotes a string, escaping any ‘ (single quote) characters.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 413 def quote_string(s) s.gsub(%r'/, "''") # ' (for ruby-mode) end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 425 def quoted_false "false" end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 421 def quoted_true "true" end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 438 def reconnect! @connection.close rescue nil @connection = FBSQL_Connect.connect(*@connection_options.first(7)) end
Removes the column from the table definition.
Examples
remove_column(:suppliers, :qualification)
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 810 def remove_column(table_name, column_name) execute "ALTER TABLE #{table_name} DROP #{column_name} RESTRICT" end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 766 def rename_table(name, new_name) columns = columns(name) pkcol = columns.find {|c| c.fb_autogen} execute "ALTER TABLE NAME #{name} TO #{new_name}" if pkcol change_column_default(new_name,pkcol.name,"UNIQUE") begin_db_transaction mpk = select_value("SELECT MAX(#{pkcol.name}) FROM #{new_name}") mpk = 0 if mpk.nil? execute "SET UNIQUE=#{mpk} FOR #{new_name}" commit_db_transaction end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 629 def reset_pk_sequence!(table, pk = nil, sequence = nil) klasses = classes_for_table_name(table) klass = klasses.nil? ? nil : klasses.first pk = klass.primary_key unless klass.nil? if pk && klass.columns_hash[pk].type == :integer mpk = select_value("SELECT MAX(#{pk}) FROM #{table}") execute("SET UNIQUE FOR #{klass.table_name}(#{pk})") end end
Set the sequence to the max value of the table’s column.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 616 def reset_sequence!(table, column, sequence = nil) klasses = classes_for_table_name(table) klass = klasses.nil? ? nil : klasses.first pk = klass.primary_key unless klass.nil? if pk && klass.columns_hash[pk].type == :integer execute("SET UNIQUE FOR #{klass.table_name}(#{pk})") end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 544 def set_optimistic_transactions if @transaction_mode == :pessimistic execute "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, LOCKING OPTIMISTIC" @transaction_mode = :optimistic end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb, line 537 def set_pessimistic_transactions if @transaction_mode == :optimistic execute "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, LOCKING PESSIMISTIC, READ WRITE" @transaction_mode = :pessimistic end end