Class: ActiveRecord::ConnectionAdapters::InterBaseAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/interbase_adapter.rb

Overview

The InterBase adapter relies on the IBRuby extension, version 0.5.1 or later (available as a gem or from RubyForge). IBRuby works with InterBase 7.1, 7.5 and 2007 on Linux, Solaris and Win32 platforms.

Usage Notes

Sequence (Generator) Names

The InterBase adapter supports the same approach adopted for the Oracle & Firebird adapters. See ActiveRecord::Base#set_sequence_name for more details.

Note that in general there is no need to create a BEFORE INSERT trigger corresponding to a InterBase sequence generator when using ActiveRecord. In other words, you don’t have to try to make InterBase simulate an AUTO_INCREMENT or IDENTITY column. When saving a new record, ActiveRecord pre-fetches the next sequence value for the table and explicitly includes it in the INSERT statement. (Pre-fetching the next primary key value is the only reliable method for the InterBase adapter to report back the id after a successful insert.)

BLOB Elements

The InterBase adapter currently provides only limited support for BLOB columns. You cannot currently retrieve or insert a BLOB as an IO stream. When selecting a BLOB, the entire element is converted into a String. When inserting or updating a BLOB, the entire value is included in-line in the SQL statement, limiting you to values <= 32KB in size.

Column Name Case Semantics

InterBase and ActiveRecord have somewhat conflicting case semantics for column names.

InterBase

The standard practice is to use unquoted column names, which can be thought of as case-insensitive. (In fact, InterBase converts them to uppercase.) Quoted column names (not typically used) are case-sensitive.

ActiveRecord

Attribute accessors corresponding to column names are case-sensitive. The defaults for primary key and inheritance columns are lowercase, and in general, people use lowercase attribute names.

In order to map between the differing semantics in a way that conforms to common usage for both InterBase and ActiveRecord, uppercase column names in InterBase are converted to lowercase attribute names in ActiveRecord, and vice-versa. Mixed-case column names retain their case in both directions. Lowercase (quoted) InterBase column names are not supported. This is similar to the solutions adopted by other adapters.

In general, the best approach is to use unqouted (case-insensitive) column names in your InterBase DDL (or if you must quote, use uppercase column names). These will correspond to lowercase attributes in ActiveRecord.

For example, a InterBase table based on the following DDL:

CREATE TABLE products (
  id INTEGER NOT NULL PRIMARY KEY,
  "type" VARCHAR(50),
  name VARCHAR(255) );

…will correspond to an ActiveRecord model class called Product with the following attributes: id, type, name.

Quoting "TYPE" and other InterBase reserved words:

In ActiveRecord, the default inheritance column name is type. The word type is a InterBase reserved word, so it must be quoted in any InterBase SQL statements. Because of the case mapping described above, you should always reference this column using quoted-lowercase syntax ("type") within InterBase DDL or other SQL statements (as in the example above). This holds true for any other InterBase reserved words used as column names as well as this driver keeps a list of all reserved words and will ensure they are not mapped to upper case and they are always used quoted in the database.

Migrations

The InterBase adapter does support Migrations.

SQL

ActiveRecord has as part of its test suite syntax which is not strictly compliant with the SQL standard i.e. field IN (NULL). NULL is not valid in the IN clause, and where this particular part of SQL has appeared I change it to field IS NULL instead using Ruby’s pattern matching

The same is true of = NULL in the WHERE clause, this is also not SQL standard and in those cases, I break the SQL statement up into the before WHERE and after WHERE and replace all = NULL after the WHERE with IS NULL. This is clearly time consuming on the SQL so I really wish they wouldn’t do it.

Connection Options

The following options are supported by the InterBase adapter. None of the options have default values.

:database

Required option. Specifies one of: (i) a InterBase database alias; (ii) the full path of a database file; or (iii) a full InterBase connection string. Do not specify :host, :service or :port as separate options when using a full connection string.

:host

Set to "remote.host.name" for remote database connections. May be omitted for local connections if a full database path is specified for :database. Some platforms require a value of "localhost" for local connections when using a InterBase database alias.

:service

Specifies a service name for the connection. Only used if :host is provided. Required when connecting to a non-standard service.

:port

Specifies the connection port. Only used if :host is provided and :service is not. Required when connecting to a non-standard port and :service is not defined.

:username

Specifies the database user. May be omitted or set to nil (together with :password) to use the underlying operating system user credentials on supported platforms.

:password

Specifies the database password. Must be provided if :username is explicitly specified; should be omitted if OS user credentials are are being used.

:charset

Specifies the character set to be used by the connection. Refer to InterBase documentation for valid options.

:role:

Specifies the role that the username is using when connecting to the database (if any)

Constant Summary collapse

@@reserved_words_array =

class property

[ "ACTION", "AFTER", "ANY", "AT", "BASED", "BEGIN", "BOOLEAN",
   "CASCADE", "CHARACTER", "ACTIVE", "ALL", "AS", "AUTO", "BASENAME", "BETWEEN", "BUFFER", "CAST",
   "CHAR_LENGTH", "ADD", "ALTER", "ASC", "AUTODDL", "BASE_NAME", "BLOB", "BY", "CHAR", "CHECK",
   "ADMIN", "AND", "ASCENDING", "AVG", "BEFORE", "BLOBEDIT", "CACHE", "CHARACTER", "CHECK_POINT_LEN",
   "CHECK_POINT_LENGTH", "COLLATE", "COLLATION", "COLUMN", "COMMIT", "COMMITTED", "COMPILETIME",
   "COMPUTED", "CLOSE", "CONDITIONAL", "CONNECT", "CONSTRAINT", "CONTAINING", "CONTINUE", "COUNT",
   "CREATE", "CSTRING", "CURRENT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURSOR", "DATABASE",
   "DATE", "DAY", "DB_KEY", "DEBUG", "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DELETE", "DESC", "DESCENDING",
   "DESCRIBE", "DESCRIPTOR", "DISCONNECT", "DISPLAY", "DISTINCT", "DO", "DOMAIN", "DOUBLE", "DROP", "ECHO",
   "EDIT", "ELSE", "END", "ENTRY_POINT", "ESCAPE", "EVENT", "EXCEPTION", "EXECUTE", "EXISTS", "EXIT", "EXTERN",
   "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FILE", "FILTER", "FLOAT", "FOR", "FOREIGN", "FOUND", "FREE_IT",
   "FROM", "FULL", "FUNCTION", "GDSCODE", "GENERATOR", "GEN_ID", "GLOBAL", "GOTO", "GRANT", "GROUP", "GROUP_COMMIT_WAIT",
   "GROUP_COMMIT_WAIT_TIME", "HAVING", "HELP", "HOUR", "IF", "IMMEDIATE", "IN", "INACTIVE", "INDEX", "INDICATOR",
   "INIT", "INNER", "INPUT", "INPUT_TYPE", "INSERT", "INT", "INTEGER", "INTO", "IS", "ISOLATION", "ISQL", "JOIN",
   "KEY", "LC_MESSAGES", "LC_TYPE", "LEFT", "LENGTH", "LEV", "LEVEL", "LIKE", "LOGFILE", "LOG_BUFFER_SIZE",
   "LOG_BUF_SIZE", "LONG", "MANUAL", "MAX", "MAXIMUM", "MAXIMUM_SEGMENT", "MAX_SEGMENT", "MERGE", "MESSAGE", "MIN",
   "MINIMUM", "MINUTE", "MODULE_NAME", "MONTH", "NAMES", "NATIONAL", "NATURAL", "NCHAR", "NO", "NOAUTO", "NOT", "NULL",
   "NUMERIC", "NUM_LOG_BUFS", "NUM_LOG_BUFFERS", "OCTET_LENGTH", "OF", "ON", "ONLY", "OPEN", "OPTION", "OR", "ORDER",
   "OUTER", "OUTPUT", "OUTPUT_TYPE", "OVERFLOW", "PAGE", "PAGELENGTH", "PAGES", "PAGE_SIZE", "PARAMETER", "PASSWORD",
   "PERCENT", "PLAN", "POSITION", "POST_EVENT", "PRECISION", "PREPARE", "PRESERVE", "PROCEDURE", "PROTECTED", "PRIMARY",
   "PRIVILEGES", "PUBLIC", "QUIT", "RAW_PARTITIONS", "READ", "REAL", "RECORD_VERSION", "REFERENCES", "RELEASE", "RESERV",
   "RESERVING", "RESTRICT", "RETAIN", "RETURN", "RETURNING_VALUES", "RETURNS", "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROWS",
   "RUNTIME", "SCHEMA", "SECOND", "SEGMENT", "SELECT", "SET", "SHADOW", "SHARED", "SHELL", "SHOW", "SINGULAR", "SIZE",
   "SMALLINT", "SNAPSHOT", "SOME", "SORT", "SQLCODE", "SQLERROR", "SQLWARNING", "STABILITY", "STARTING", "STARTS", "STATEMENT",
   "STATIC", "STATISTICS", "SUB_TYPE", "SUM", "SUSPEND", "TABLE", "TEMPORARY", "TERMINATOR", "THEN", "TIES", "TIME", "TIMESTAMP",
   "TO", "TRANSACTION", "TRANSLATE", "TRANSLATION", "TRIGGER", "TRIM", "TRUE", "TYPE", "UNCOMMITTED", "UNION", "UNIQUE", "UNKNOWN",
   "UPDATE", "UPPER", "USER", "USING", "VALUE", "VALUES", "VARCHAR", "VARIABLE", "VARYING", "VERSION", "VIEW", "WAIT", "WEEKDAY",
   "WHEN", "WHENEVER", "WHERE", "WHILE", "WITH", "WORK", "WRITE", "YEAR", "YEARDAY"
]
@@reserved_words_hash =

will turn it into a hash for faster access

{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, logger, connection_params = nil) ⇒ InterBaseAdapter

Returns a new instance of InterBaseAdapter.



374
375
376
377
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 374

def initialize(connection, logger, connection_params=nil)
  super(connection, logger)
  @connection_params = connection_params
end

Class Method Details

.reserved_wordsObject

You can make a column case sensitive by adding it to the list of reserved words. This method builds the fast hash when first accessed.



364
365
366
367
368
369
370
371
372
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 364

def self.reserved_words
  if @@reserved_words_hash.size == 0
    @@reserved_words_array.each() do |value|
      @@reserved_words_hash[ value ] = true
    end
  end
  
  @@reserved_words_hash
end

Instance Method Details

#active?Boolean

CONNECTION MANAGEMENT ====================================

Returns:

  • (Boolean)


434
435
436
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 434

def active?
  not @connection.closed?
end

#adapter_nameObject

:nodoc:



384
385
386
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 384

def adapter_name # :nodoc:
  'InterBase'
end

#add_column(table_name, column_name, type, options = {}) ⇒ Object



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 750

def add_column(table_name, column_name, type, options = {})
  new_col = IBRuby::InterBaseColumn.new( quote_column_name(column_name), table_name.to_s, 
     rails_type_to_native_type[type] )
     
  new_col.sub_type = rails_type_to_native_sub_type[type]
  
  push_options_into_ib_column( new_col, options )
  
  if (new_col.type == IBRuby::InterBaseColumn::VARCHAR) && new_col.length.nil?
    new_col.length = 255;
  end
  
  new_col.default = options[:default]
  
  #puts "#{new_col.name} precision:#{new_col.precision}:#{new_col.scale}"
  
#        if ( type == :decimal )
#          new_col.precision = 10 unless new_col.precision?
#          new_col.scale = 0 unless new_col.scale?
#        end
  
  new_col.add_column(raw_connection)
end

#add_index(table_name, column_name, options = {}) ⇒ Object



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 729

def add_index(table_name, column_name, options = {})
  column_names = Array(column_name)
  index_name   = index_name(table_name.to_s, :column => column_names)

  if Hash === options # legacy support, since this param was a string
    index_type = options[:unique] ? "UNIQUE" : ""
    index_name = options[:name] || index_name
  else
    index_type = options
  end
  
  columns = column_names.collect() { |col| quote_column_name(col) }
  
  begin
    index = IBRuby::InterBaseIndex.new( table_name.to_s, index_name, "UNIQUE".casecmp(index_type) == 0, columns )
    index.create_index( raw_connection )
  rescue Exception => indexFailed
    puts "Warning: Index creation failed #{indexFailed.message} - please read up on InterBase Index size limitations in Operations Guide"
  end
end

#add_limit_offset!(sql, options) ⇒ Object

:nodoc:



538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 538

def add_limit_offset!(sql, options) # :nodoc:
  if options[:limit]
    limit_string = " ROWS "
    offset = options[:offset] ? (options[:offset] + 1) : 1
    if offset.to_i < 1
      offset = 1
    end
    limit_string << offset.to_s
    limit = offset.to_i + options[:limit].to_i - 1
    limit_string << " TO #{limit}"
    #sql.sub!(/\A(\s*SELECT\s)/i, '\&' + limit_string + ' ')
    sql << limit_string
  end
end

#begin_db_transactionObject

:nodoc:



507
508
509
510
511
512
513
514
515
516
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 507

def begin_db_transaction() # :nodoc:
  #puts "begin_transaction"
  #~ if @transaction.nil? or !transaction.active?
    #~ if raw_connection.transactions.size > 0
      #~ @transaction = raw_connection.transactions[0]
    #~ else
      @transaction = @connection.start_transaction
    #~ end
  #~ end
end

#case_insignificant_uses_lowerObject



379
380
381
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 379

def case_insignificant_uses_lower
  false
end

#change_column(table_name, column_name, type, options = {}) ⇒ Object



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 644

def change_column(table_name, column_name, type, options = {})
  col = InterBaseMetaFunctions.table_fields( raw_connection, table_name.to_s, true, column_name )

  new_col = col.dup
  
  if !type.nil?
    new_col.type = rails_type_to_native_type[type]
    new_col.sub_type = rails_type_to_native_sub_type[type]
  end
  
  push_options_into_ib_column( new_col, options )        
  
  if !options[:default].nil?
    new_col.default = options[:default]
  end
  
  col.change_column( raw_connection, new_col )
end

#change_column_default(table_name, column_name, default) ⇒ Object



663
664
665
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 663

def change_column_default(table_name, column_name, default)
  change_column( table_name.to_s, column_name, nil, { :default => default } )
end

#columns(table_name, name = nil) ⇒ Object

:nodoc:



811
812
813
814
815
816
817
818
819
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 811

def columns(table_name, name = nil) # :nodoc:
  columns = InterBaseMetaFunctions.table_fields(raw_connection,table_name.to_s,true)
  
  cols = columns.collect() do |field|
    ConnectionAdapters::InterBaseColumn.new( field )
  end
  
  cols
end

#commit_db_transactionObject

:nodoc:



518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 518

def commit_db_transaction() # :nodoc:
  #puts "commit transaction"
  if @total_count
    @total_count += 1
  else
    @total_count = 0
  end
  #raise Exception, 'someone called commit?' if @total_count == 1
  @transaction.commit unless @transaction.nil? or !@transaction.active?
ensure
  @transaction = nil
end

#create_table(name, options = {}) {|table_definition| ... } ⇒ Object

have to create a sequence for each table because of the “prefetching of the primary key”

Yields:

  • (table_definition)


588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 588

def create_table(name, options = {})
  # this from super
  table_definition = InterBaseTableDefinition.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
  # to here
  # 
  # now build the proper IB meta structures
  columns = []
  
  table_definition.columns.each() do |col|
    new_col = IBRuby::InterBaseColumn.new( quote_column_name(col.name), name, rails_type_to_native_type[col.type],
      nil, !col.null.nil? && !col.null, col.limit, col.precision, col.scale, rails_type_to_native_sub_type[col.type], 
      col.default )
      
    columns << new_col
  end

  if ( table_definition.pk_field )        
    pk_constraints = [InterBaseConstraint.new(IBRuby::InterBaseConstraint::PRIMARY_KEY,
       [table_definition.pk_field.name] ) ]
  end
  
  table = InterBaseTable.new(name, columns, nil, pk_constraints )
  
  table.create_table( raw_connection )
  
  seq_name = name.to_s + "_SEQ"
  if !IBRuby::Generator.exists?( seq_name, raw_connection )
    IBRuby::Generator::create(seq_name, @connection)
  end
end

#default_sequence_name(table_name, primary_key) ⇒ Object

:nodoc:



394
395
396
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 394

def default_sequence_name(table_name, primary_key) # :nodoc:
  "#{table_name}_seq"
end

#disconnect!Object



443
444
445
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 443

def disconnect!
  @connection.close
end

#drop_table(name) ⇒ Object

should drop the indexes as well as any other meta data associated with this table!



627
628
629
630
631
632
633
634
635
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 627

def drop_table(name)
  #puts "transactions? #{@transaction.nil?}"
  InterBaseTable.new(name).drop_table(raw_connection)
  
  seq_name = name.to_s + "_SEQ"
  if IBRuby::Generator.exists?( seq_name, raw_connection )
    IBRuby::Generator.new(seq_name, @connection).drop
  end
end

#execute(sql, name = nil, &block) ⇒ Object Also known as: update, delete

:nodoc:



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 481

def execute(sql, name = nil, &block) # :nodoc:
  sql = interbaseSQL(sql)
  #~ begin
  log(sql, name) do
    if @transaction
      #puts "within trans: #{sql}"
      @connection.execute(sql, @transaction, &block)
    else
      #puts "immediate: #{sql}"
      @connection.execute_immediate(sql, &block)
    end
  end
  #~ rescue Exception => boom
    #~ puts "sql went boom #{boom.message}"
    #~ nil
  #~ end
end

#indexes(table_name, name = nil) ⇒ Object

returns an array of IndexDefinitions which include a string array of columns



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 775

def indexes(table_name, name = nil) #:nodoc:
  indices = []

  ibIndices = InterBaseMetaFunctions.indices(raw_connection,table_name.to_s)
  
  # returns array of InterBaseIndex's
  ibIndices.each() do |ibIndex|
    index = IndexDefinition.new(InterBaseAdapter.ib_to_ar_case(ibIndex.table), 
          InterBaseAdapter.ib_to_ar_case(ibIndex.name), ibIndex.unique, [])

    ibIndex.columns.each() do |col|
      index.columns << InterBaseAdapter.ib_to_ar_case(col.name)
    end
    
    indices << index
  end
  
  indices
end

#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object

:nodoc:



499
500
501
502
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 499

def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) # :nodoc:
  execute(sql, name)
  id_value
end

#interbaseSQL(sql) ⇒ Object

DATABASE STATEMENTS ======================================



449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 449

def interbaseSQL( sql )
  sql = sql.sub( / (IN|in) \(NULL\)/, ' IS NULL' )
  # anything after the WHERE clause where we find = NULL, we need replace this with IS NULL
  if ((sql !=~ /~INSERT /) && (sql =~ /= NULL/) )
    sqlMatch = / WHERE /
    matched = sqlMatch.match( sql )
    if !matched.nil? # this of course will break if the = NULL is in a bit of text
      sql = matched.pre_match << ' WHERE ' << matched.post_match.gsub( /= NULL/, 'IS NULL' )
    end
  end
  #puts "SQL = #{sql}"
  sql
end

#native_database_typesObject

:nodoc



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 667

def native_database_types #:nodoc
  {
    :primary_key => "integer not null PRIMARY KEY",
    :string      => { :name => "varchar", :limit => 252 }, # allows default string to be index (index limit 252 in InterBase)
    :text        => { :name => "blob sub_type 1" },
    :integer     => { :name => "integer" },
    :float       => { :name => "double precision" },
    :decimal     => { :name => "decimal" },
    :datetime    => { :name => "timestamp" },
    :timestamp   => { :name => "timestamp" },
    :time        => { :name => "time" },
    :date        => { :name => "date" },
    :binary      => { :name => "blob" },
    :boolean     => { :name => "boolean" }
  }
end

#next_sequence_value(sequence_name) ⇒ Object

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?).



556
557
558
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 556

def next_sequence_value(sequence_name)
  IBRuby::Generator.new(sequence_name, @connection).next(1)
end

#prefetch_primary_key?(table_name = nil) ⇒ Boolean

Returns true for InterBase adapter (since InterBase requires primary key values to be pre-fetched before insert). See also #next_sequence_value.

Returns:

  • (Boolean)


390
391
392
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 390

def prefetch_primary_key?(table_name = nil)
  true
end

#quote(value, column = nil) ⇒ Object

QUOTING ==================================================



401
402
403
404
405
406
407
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 401

def quote(value, column = nil) # :nodoc:
  if [Time, DateTime].include?(value.class)
    "CAST('#{value.strftime("%Y-%m-%d %H:%M:%S")}' AS TIMESTAMP)"
  else
    super
  end
end

#quote_column_name(column_name) ⇒ Object

:nodoc:



413
414
415
416
417
418
419
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 413

def quote_column_name(column_name) # :nodoc:
  if InterBaseAdapter.reserved_words[column_name.to_s.upcase] 
    %Q("#{column_name.to_s.downcase}")
  else
    InterBaseAdapter.ar_to_ib_case(column_name)
  end
end

#quote_string(string) ⇒ Object

:nodoc:



409
410
411
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 409

def quote_string(string) # :nodoc:
  string.gsub(/'/, "''")
end

#quoted_falseObject

:nodoc:



426
427
428
429
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 426

def quoted_false # :nodoc:
  'false'
  #false
end

#quoted_trueObject

:nodoc:



421
422
423
424
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 421

def quoted_true # :nodoc:
  'true'
  #true
end

#rails_type_to_native_sub_typeObject



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 700

def rails_type_to_native_sub_type
  {  
    :string      => 0,
    :text        => 1,
    :integer     => 0,
    :float       => 0,
    :decimal     => 0, # 0 is decimal, 1 is numeric
    :datetime    => 0,
    :timestamp   => 0,
    :time        => 0,
    :date        => 0,
    :binary      => 0,
    :boolean     => 0
  }
end

#rails_type_to_native_typeObject



684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 684

def rails_type_to_native_type
  {  
    :string      => IBRuby::InterBaseColumn::VARCHAR,
    :text        => IBRuby::InterBaseColumn::BLOB,
    :integer     => IBRuby::InterBaseColumn::INTEGER,
    :float       => IBRuby::InterBaseColumn::DOUBLE,
    :decimal     => IBRuby::InterBaseColumn::DECIMAL,
    :datetime    => IBRuby::InterBaseColumn::TIMESTAMP,
    :timestamp   => IBRuby::InterBaseColumn::TIMESTAMP,
    :time        => IBRuby::InterBaseColumn::TIME,
    :date        => IBRuby::InterBaseColumn::DATE,
    :binary      => IBRuby::InterBaseColumn::BLOB,
    :boolean     => IBRuby::InterBaseColumn::BOOLEAN
  }
end

#reconnect!Object



438
439
440
441
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 438

def reconnect!
  @connection.close
  @connection = @connection.database.connect(*@connection_params)
end

#recreate_database!Object

should really put this in IBRuby but don’t want to change it for the release of 3rdRail



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 567

def recreate_database!
  sql = "SELECT rdb$character_set_name FROM rdb$database"
  charset = execute(sql).to_a.first[0]
filename = @connection.database.file
  disconnect!
db = IBRuby::Database.new( filename )
  db.drop(@connection_params[0], @connection_params[1])
db = nil
if charset.nil?
 IBRuby::Database.create(@connection.database.file,
 @connection_params[0], @connection_params[1], 4096)
else
 IBRuby::Database.create(@connection.database.file,
 @connection_params[0], @connection_params[1], 4096, charset.rstrip)
end
db = IBRuby::Database.new( filename )
@connection = db.connect( @connection_params[0], @connection_params[1], @connection_params[2] )
end

#remove_index(table_name, options = {}) ⇒ Object

no table name specified for InterBase



807
808
809
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 807

def remove_index(table_name, options = {})
  InterBaseMetaFunctions.remove_index(raw_connection, index_name(table_name.to_s, options) )
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object



637
638
639
640
641
642
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 637

def rename_column(table_name, column_name, new_column_name)
  # will break if there is an index based on this column!
  # 
  col = InterBaseMetaFunctions.table_fields( raw_connection, table_name.to_s, true, quote_column_name(column_name) )
  col.rename_column( raw_connection, quote_column_name(new_column_name) )
end

#rename_table(name, new_name) ⇒ Object



801
802
803
804
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 801

def rename_table(name, new_name)
  table = IBRuby::InterBaseTable.new(name)
  table.rename_table(raw_connection, new_name )
end

#rollback_db_transactionObject

:nodoc:



531
532
533
534
535
536
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 531

def rollback_db_transaction() # :nodoc:
  #puts "rollback transaction"
  @transaction.rollback unless @transaction.nil? or !@transaction.active?
ensure
  @transaction = nil
end

#select_all(sql, name = nil) ⇒ Object

:nodoc:



463
464
465
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 463

def select_all(sql, name = nil) # :nodoc:
  select(sql, name)
end

#select_one(sql, name = nil) ⇒ Object

:nodoc:



467
468
469
470
471
472
473
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 467

def select_one(sql, name = nil) # :nodoc:
  if sql !=~ / ROWS / 
    sql << " ROWS 1 TO 1"
  end
  result = select(sql, name)
  result.nil? ? nil : result.first  #first element in array
end

#select_value(sql, name = nil) ⇒ Object



475
476
477
478
479
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 475

def select_value(sql, name = nil)
  result = select_one(sql, name)
  
  result.nil? ? nil : result.values.first
end

#supports_migrations?Boolean

SCHEMA STATEMENTS ========================================

Returns:

  • (Boolean)


562
563
564
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 562

def supports_migrations?
  true
end

#tablesObject

returns a string array of tables!



796
797
798
799
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 796

def tables
  table_names = InterBaseMetaFunctions.table_names(raw_connection)
  table_names.each() { |table_name| table_name.downcase! }
end

#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object

:nodoc:



717
718
719
720
721
722
723
724
725
726
727
# File 'lib/active_record/connection_adapters/interbase_adapter.rb', line 717

def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
  return super unless type.to_s == 'integer'

  if limit.nil? || limit == 4
    'integer'
  elsif limit < 4
    'smallint'
  else
    'decimal(#{limit},0)'
  end
end