Class: ActiveRecord::ConnectionAdapters::NuoDBAdapter

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

Overview

class NuoDBColumn

Defined Under Namespace

Classes: BindSubstitution, ExplainPrettyPrinter, StatementPool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, logger, pool, config) ⇒ NuoDBAdapter

Returns a new instance of NuoDBAdapter.



255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 255

def initialize(connection, logger, pool, config)
  super(connection, logger, pool)
  @visitor = Arel::Visitors::NuoDB.new self
  @config = config.clone
  # prefer to run with prepared statements unless otherwise specified
  if @config.fetch(:prepared_statements) { true }
    @visitor = Arel::Visitors::NuoDB.new self
  else
    @visitor = BindSubstitution.new self
  end
  connect!
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



249
250
251
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 249

def config
  @config
end

#statementsObject

Returns the value of attribute statements.



249
250
251
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 249

def statements
  @statements
end

Instance Method Details

#adapter_nameObject

ADAPTER NAME ===========================================



272
273
274
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 272

def adapter_name
  'NuoDB'
end

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

Carlos Added Begins



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 503

def add_column(table_name, column_name, type, options = {})
  clear_cache!
  #Stored procedure not supported
  #add_column_sql = "CREATE PROCEDURE PR1 BEGIN IF NOT EXISTS((SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE()
  #        AND COLUMN_NAME=#{quote_column_name(column_name)} AND TABLE_NAME=#{quote_table_name(table_name)})) THEN ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type.to_s} END IF"
  if column_exists?(table_name, column_name) == false
    add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type.to_s}"
    add_column_options!(add_column_sql, options)
    execute(add_column_sql)
  end
end

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



515
516
517
518
519
520
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 515

def add_index(table_name, column_name, options = {})
  index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
  if okay_index(table_name, column_name, options = {}) == true
    execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})"
  end
end

#begin_db_transactionObject

Begins the transaction (and turns off auto-committing).



821
822
823
824
825
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 821

def begin_db_transaction()
  log('begin transaction', nil) {
    raw_connection.autocommit = false if raw_connection.autocommit?
  }
end

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

Bug: (4) methods, see: tools/jira/browse/DB-2389

Raises:

  • (NotImplementedError)


471
472
473
474
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 471

def change_column(table_name, column_name, type, options = {})
  raise NotImplementedError, "change_column is not implemented"
  #execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_sql(table_name, column_name, type, options)}")
end

#change_column_default(table_name, column_name, default) ⇒ Object

Raises:

  • (NotImplementedError)


476
477
478
479
480
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 476

def change_column_default(table_name, column_name, default)
  raise NotImplementedError, "change_column_default is not implemented"
  #column = column_for(table_name, column_name)
  #change_column table_name, column_name, column.sql_type, :default => default
end

#change_column_null(table_name, column_name, null, default = nil) ⇒ Object

Raises:

  • (NotImplementedError)


482
483
484
485
486
487
488
489
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 482

def change_column_null(table_name, column_name, null, default = nil)
  raise NotImplementedError, "change_column_null is not implemented"
  #column = column_for(table_name, column_name)
  #unless null || default.nil?
  #  execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
  #end
  #change_column table_name, column_name, column.sql_type, :null => null
end

#clear_cache!Object



391
392
393
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 391

def clear_cache!
  @statements.clear
end

#column_exists?(table_name, column_name, type = nil, options = {}) ⇒ Boolean

Carlos Added

Returns:

  • (Boolean)


542
543
544
545
546
547
548
549
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 542

def column_exists?(table_name, column_name, type = nil, options = {})
  begin
    execute("SELECT #{quote_column_name(column_name)} FROM #{quote_table_name(table_name)}")
    return true
  rescue
    return false
  end
end

#columns(table_name, name = nil) ⇒ Object



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 630

def columns(table_name, name = nil)

  # the following query returns something like this:
  #
  # INDEXNAME              TABLENAME NON_UNIQUE FIELD     LENGTH
  # ---------------------- --------- ---------- --------- ------
  # COMPANIES..PRIMARY_KEY COMPANIES 0          ID        4
  # COMPANY_INDEX          COMPANIES 1          FIRM_ID   4
  # COMPANY_INDEX          COMPANIES 1          TYPE      255
  # COMPANY_INDEX          COMPANIES 1          RATING    4
  # COMPANY_INDEX          COMPANIES 1          RUBY_TYPE 255

  result = exec_query(<<-eosql, 'SCHEMA', [config[:schema], table_name.to_s])
    SELECT
      fields.field as name,
      fields.defaultvalue as default_value,
      datatypes.name as data_type,
      fields.length as length,
      fields.scale as scale,
      fields.precision as precision,
      fields.flags as flags
    FROM
      system.fields AS fields, system.datatypes AS datatypes
    WHERE
      schema = ? AND tablename = ? AND
      datatypes.id = fields.datatype
    ORDER BY fields.fieldposition
  eosql

  columns = []
  result.map do |row|
    row.symbolize_keys!
    columns << NuoDBColumn.new(row[:name].downcase, row[:default_value], row[:data_type], row[:flags].to_i & 1 == 0, row[:length], row[:scale], row[:precision])
  end
  columns
end

#commit_db_transactionObject

Commits the transaction (and turns on auto-committing).



828
829
830
831
832
833
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 828

def commit_db_transaction()
  log('commit transaction', nil) {
    raw_connection.autocommit = true unless raw_connection.autocommit?
    raw_connection.commit
  }
end

#connect!Object



375
376
377
378
379
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 375

def connect!
  @connection = ::NuoDB::Connection.new(config)
  @statements = StatementPool.new(@connection, @config.fetch(:statement_limit) { 1000 })
  @quoted_column_names, @quoted_table_names = {}, {}
end

#convert_results(results) ⇒ Object



923
924
925
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 923

def convert_results(results)
  ActiveRecord::Result.new(column_names(results), results.rows)
end

#create_savepointObject

SAVEPOINT SUPPORT ======================================



397
398
399
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 397

def create_savepoint
  execute("SAVEPOINT #{current_savepoint_name}")
end

#default_sequence_name(table, column) ⇒ Object



844
845
846
847
848
849
850
851
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 844

def default_sequence_name(table, column)
  result = exec_query(<<-eosql, 'SCHEMA', [table.to_s, column.to_s])
    SELECT generator_sequence FROM system.fields WHERE tablename='#{table}' AND field='#{column}'
  eosql
  result.rows.first.first
rescue ActiveRecord::StatementInvalid
  "#{table}$#{column}"
end

#disconnect!Object



381
382
383
384
385
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 381

def disconnect!
  super
  clear_cache!
  raw_connection.disconnect rescue nil
end

#exec_delete(sql, name, binds) ⇒ Object



871
872
873
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 871

def exec_delete(sql, name, binds)
  exec_query(sql, name, binds.map { |col, val| type_cast(val, col) })
end

#exec_insert(sql, name, binds) ⇒ Object



863
864
865
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 863

def exec_insert(sql, name, binds)
  exec_query sql, name, binds.map { |col, val| type_cast(val, col) }, true
end

#exec_query(sql, name = 'SQL', binds = [], get_generated_keys = false) ⇒ Object



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 875

def exec_query(sql, name = 'SQL', binds = [], get_generated_keys = false)
  log(sql, name, binds) do
    if binds.empty?

      cache = statements[process_id] ||= {
          :stmt => raw_connection.statement
      }
      stmt = cache[:stmt]

      results = nil
      if stmt.execute(sql)
        results = convert_results stmt.results
      end
      if get_generated_keys
        generated_keys_result = stmt.generated_keys
        if generated_keys_result.nil? || generated_keys_result.rows.empty?
          @last_inserted_id = nil
        else
          @last_inserted_id = generated_keys_result.rows.last[0]
        end
      end

      results
    else
      cache = statements[sql] ||= {
          :stmt => raw_connection.prepare(sql)
      }
      stmt = cache[:stmt]

      results = nil
      stmt.bind_params binds
      if stmt.execute
        results = convert_results stmt.results
      end
      if get_generated_keys
        generated_keys_result = stmt.generated_keys
        if generated_keys_result.nil? || generated_keys_result.rows.empty?
          @last_inserted_id = nil
        else
          @last_inserted_id = generated_keys_result.rows.last[0]
        end
      end

      results
    end
  end
end

#exec_update(sql, name, binds) ⇒ Object



867
868
869
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 867

def exec_update(sql, name, binds)
  exec_query(sql, name, binds, true)
end

#execute(sql, name = 'SQL') ⇒ Object



853
854
855
856
857
858
859
860
861
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 853

def execute(sql, name = 'SQL')
  log(sql, name) do
    cache = statements[process_id] ||= {
        :stmt => raw_connection.statement
    }
    stmt = cache[:stmt]
    stmt.execute(sql)
  end
end

#explain(arel, binds = []) ⇒ Object



314
315
316
317
318
319
320
321
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 314

def explain(arel, binds = [])
  sql     = "EXPLAIN #{to_sql(arel, binds.dup)}"
  start   = Time.now
  result  = exec_query(sql, 'EXPLAIN', binds)
  elapsed = Time.now - start

  ExplainPrettyPrinter.new.pp(result, elapsed)
end

#indexes(table_name, name = nil) ⇒ Object

Returns an array of indexes for the given table. Skip primary keys.



583
584
585
586
587
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
625
626
627
628
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 583

def indexes(table_name, name = nil)
  # the following query returns something like this:
  #
  # INDEXNAME              TABLENAME NON_UNIQUE FIELD     LENGTH
  # ---------------------- --------- ---------- --------- ------
  # COMPANIES..PRIMARY_KEY COMPANIES 0          ID        4
  # COMPANY_INDEX          COMPANIES 1          FIRM_ID   4
  # COMPANY_INDEX          COMPANIES 1          TYPE      255
  # COMPANY_INDEX          COMPANIES 1          RATING    4
  # COMPANY_INDEX          COMPANIES 1          RUBY_TYPE 255

  result = exec_query(<<-eosql, 'SCHEMA', [config[:schema], table_name.to_s])
    SELECT
      indexes.indexname as index_name,
      indexes.tablename as table_name,
      CASE indexes.indextype WHEN 2 THEN 1 ELSE 0 END AS non_unique,
      indexfields.field as field_name,
      fields.length as field_length
    FROM
      system.indexes AS indexes, system.indexfields AS indexfields, system.fields AS fields
    WHERE
      indexes.schema = ? AND
      indexes.tablename = ? AND
      indexes.indexname = indexfields.indexname AND
      indexfields.field = fields.field AND
      indexfields.schema = fields.schema AND
      indexfields.tablename = fields.tablename
  eosql
  indexes = []
  current_index = nil
  result.map do |row|
    row.symbolize_keys!
    #Carlos Added .downcase!
    index_name = row[:index_name].downcase!
    if current_index != index_name
      next if !!(/PRIMARY/ =~ index_name)
      current_index = index_name
      table_name = row[:table_name]
      is_unique = row[:non_unique].to_i == 1
      indexes << IndexDefinition.new(table_name, index_name, is_unique, [], [], [])
    end
    indexes.last.columns << row[:field_name] unless row[:field_name].nil?
    indexes.last.lengths << row[:field_length] unless row[:field_length].nil?
  end
  indexes
end

#last_inserted_id(result) ⇒ Object



927
928
929
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 927

def last_inserted_id(result)
  @last_inserted_id
end

#modify_types(tp) ⇒ Object

jruby version – no original



692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 692

def modify_types(tp)
  tp[:primary_key] = 'int not null generated always primary key'
  tp[:boolean] = {:name => 'boolean'}
  tp[:date] = {:name => 'date', :limit => nil}
  tp[:datetime] = {:name => 'timestamp', :limit => nil}
  tp[:decimal] = {:name => 'decimal'}
  tp[:integer] = {:name => 'int', :limit => 4}
  tp[:string] = {:name => 'string'}
  tp[:time] = {:name => 'time', :limit => nil}
  tp[:timestamp] = {:name => 'timestamp', :limit => nil}
  tp
end

#native_database_typesObject



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 669

def native_database_types
  {
      # generic rails types...
      :binary => {:name => 'binary'},
      :boolean => {:name => 'boolean'},
      :date => {:name => 'date'},
      :datetime => {:name => 'timestamp'},
      :decimal => {:name => 'decimal'},
      :float => {:name => 'float', :limit => 8},
      :integer => {:name => 'integer', :limit => 4},
      :primary_key => 'int not null generated by default as identity primary key',
      :string => {:name => 'varchar', :limit => 255},
      :text => {:name => 'string'},
      :time => {:name => 'time'},
      :timestamp => {:name => 'timestamp'},
      # nuodb specific types...
      :char => {:name => 'char'},
      :numeric => {:name => 'numeric(20)'},
      :binarystring => {:name => 'varchar', :limit => 255}
  }
end

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



522
523
524
525
526
527
528
529
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 522

def okay_index(table_name, column_name, options = {})
  begin
    execute("CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})")
    return true
  rescue
    return false
  end
end

#outside_transaction?Boolean

end

Returns:

  • (Boolean)


812
813
814
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 812

def outside_transaction?
  nil
end

#primary_key(table_name) ⇒ Object



447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 447

def primary_key(table_name)
  # n.b. active record does not support composite primary keys!
  row = exec_query(<<-eosql, 'SCHEMA', [config[:schema], table_name.to_s]).rows.first
    SELECT
      indexfields.field as field_name
    FROM
      system.indexfields AS indexfields
    WHERE
      indexfields.schema = ? AND
      indexfields.tablename = ?
  eosql
  row && row.first.downcase
end

#process_idObject



245
246
247
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 245

def process_id
  Process.pid
end

#quote_column_name(name) ⇒ Object



769
770
771
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 769

def quote_column_name(name)
  @quoted_column_names[name] ||= "`#{name.to_s.gsub('`', '``')}`"
end

#quote_table_name(name) ⇒ Object



773
774
775
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 773

def quote_table_name(name)
  @quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`')
end

#quoted_date(value) ⇒ Object



790
791
792
793
794
795
796
797
798
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 790

def quoted_date(value)
  if value.acts_like?(:time)
    zone_conversion_method = :getutc
    if value.respond_to?(zone_conversion_method)
      value = value.send(zone_conversion_method)
    end
  end
  value.to_s(:db)
end

#quoted_falseObject



786
787
788
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 786

def quoted_false
  "'false'"
end

#quoted_trueObject



782
783
784
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 782

def quoted_true
  "'true'"
end

#reconnect!Object

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



369
370
371
372
373
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 369

def reconnect!
  disconnect!
  connect!
  super
end

#release_savepointObject



405
406
407
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 405

def release_savepoint
  execute("RELEASE SAVEPOINT #{current_savepoint_name}")
end

#remove_index!(table_name, index_name) ⇒ Object

Carlos Added Ends

Raises:

  • (NotImplementedError)


533
534
535
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 533

def remove_index!(table_name, index_name) #:nodoc:
  raise NotImplementedError, "remove_index! is not implemented"
end

#rename_column(table_name, column_name, new_column_name) ⇒ Object

Raises:

  • (NotImplementedError)


491
492
493
494
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 491

def rename_column(table_name, column_name, new_column_name)
  raise NotImplementedError, "rename_column is not implemented"
  #execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_sql(table_name, column_name, new_column_name)}")
end

#rename_index(table_name, old_name, new_name) ⇒ Object



537
538
539
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 537

def rename_index(table_name, old_name, new_name)
  execute("ALTER INDEX #{quote_column_name(old_name)} RENAME TO #{quote_table_name(new_name)}")
end

#rename_table(table_name, new_name) ⇒ Object

Raises:

  • (NotImplementedError)


496
497
498
499
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 496

def rename_table(table_name, new_name)
  raise NotImplementedError, "rename_table is not implemented"
  #execute("RENAME TABLE #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}")
end

#reset!Object



387
388
389
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 387

def reset!
  reconnect!
end

#rollback_db_transactionObject

Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.



837
838
839
840
841
842
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 837

def rollback_db_transaction()
  log('rollback transaction', nil) {
    raw_connection.autocommit = true unless raw_connection.autocommit?
    raw_connection.rollback
  }
end

#rollback_to_savepointObject



401
402
403
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 401

def rollback_to_savepoint
  execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
end

#select_rows(sql, name = nil) ⇒ Object



804
805
806
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 804

def select_rows(sql, name = nil)
  exec_query(sql, name).rows
end

#supports_bulk_alter?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 294

def supports_bulk_alter?
  false
end

#supports_count_distinct?Boolean

Returns:

  • (Boolean)


286
287
288
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 286

def supports_count_distinct?
  true
end

#supports_ddl_transactions?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 290

def supports_ddl_transactions?
  true
end

#supports_explain?Boolean

Returns:

  • (Boolean)


310
311
312
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 310

def supports_explain?
  true
end

#supports_index_sort_order?Boolean

Returns:

  • (Boolean)


302
303
304
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 302

def supports_index_sort_order?
  true
end

#supports_migrations?Boolean

FEATURES ===============================================

Returns:

  • (Boolean)


278
279
280
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 278

def supports_migrations?
  true
end

#supports_partial_index?Boolean

Returns:

  • (Boolean)


306
307
308
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 306

def supports_partial_index?
  false
end

#supports_primary_key?Boolean

Returns:

  • (Boolean)


282
283
284
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 282

def supports_primary_key?
  true
end

#supports_savepoints?Boolean

Returns:

  • (Boolean)


298
299
300
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 298

def supports_savepoints?
  true
end

#supports_statement_cache?Boolean

Returns:

  • (Boolean)


816
817
818
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 816

def supports_statement_cache?
  true
end

#table_exists?(table_name) ⇒ Boolean

ENDS

Returns:

  • (Boolean)


553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 553

def table_exists?(table_name)
  return false unless table_name

  table_name = table_name.to_s.downcase
  schema, table = table_name.split('.', 2)

  unless table
    table = schema
    schema = nil
  end

  tables('SCHEMA', schema).include? table
end

#tables(name = 'SCHEMA', schema = nil) ⇒ Object



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

def tables(name = 'SCHEMA', schema = nil)
  result = exec_query(<<-eosql, name, [schema || config[:schema]])
    SELECT
      tablename
    FROM
      system.tables
    WHERE
      schema = ?
  eosql
  result.inject([]) do |tables, row|
    row.symbolize_keys!
    tables << row[:tablename].downcase
  end
end

#type_cast(value, column) ⇒ Object



777
778
779
780
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 777

def type_cast(value, column)
  return super unless value == true || value == false
  value ? true : false
end

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

jruby version maps logical rails types to nuodb-specific data types.



707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 707

def type_to_sql(type, limit = nil, precision = nil, scale = nil)
  case type.to_s
    when 'integer'
      return 'integer' unless limit
      case limit
        when 1..2
          'smallint'
        when 3..4
          'integer'
        when 5..8
          'bigint'
        else
          raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
      end
    when 'timestamp'
      column_type_sql = 'timestamp'
      unless precision.nil?
        case precision
          when 0..9
            column_type_sql << "(#{precision})"
          else
            nil
        end
      end
      column_type_sql
    when 'time'
      column_type_sql = 'time'
      unless precision.nil?
        case precision
          when 0..9
            column_type_sql << "(#{precision})"
          else
            nil
        end
      end
      column_type_sql
    else
      super
  end
end

#versionObject



461
462
463
# File 'lib/active_record/connection_adapters/nuodb_adapter.rb', line 461

def version
  self.class::VERSION
end