module Sequel::Cubrid::DatabaseMethods

Constants

AUTOINCREMENT
COLUMN_DEFINITION_ORDER
DATABASE_ERROR_REGEXPS

Public Instance Methods

database_type() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 18
def database_type
  :cubrid
end
indexes(table, opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 22
def indexes(table, opts=OPTS)
  m = output_identifier_meth
  m2 = input_identifier_meth
  indexes = {}
  metadata_dataset.
    from{db_index[:i]}.
    join(Sequel[:db_index_key].as(:k), :index_name=>:index_name, :class_name=>:class_name).
    where{{i[:class_name]=>m2.call(table), :is_primary_key=>'NO'}}.
    order{k[:key_order]}.
    select{[i[:index_name], k[:key_attr_name].as(:column), :is_unique]}.
    each do |row|
      index = indexes[m.call(row[:index_name])] ||= {:columns=>[], :unique=>row[:is_unique]=='YES'}
      index[:columns] << m.call(row[:column])
    end
  indexes
end
schema_parse_table(table_name, opts) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 43
def schema_parse_table(table_name, opts)
  m = output_identifier_meth(opts[:dataset])
  m2 = input_identifier_meth(opts[:dataset])

  pks = metadata_dataset.
    from{db_index[:i]}.
    join(Sequel[:db_index_key].as(:k), :index_name=>:index_name, :class_name=>:class_name).
    where{{i[:class_name]=>m2.call(table_name), :is_primary_key=>'YES'}}.
    order{k[:key_order]}.
    select_map{k[:key_attr_name]}.
    map{|c| m.call(c)}

  metadata_dataset.
    from(:db_attribute).
    where(:class_name=>m2.call(table_name)).
    order(:def_order).
    select{[:attr_name, data_type.as(:db_type), default_value.as(:default), is_nullable.as(:allow_null), :prec]}.
    map do |row|
      name = m.call(row.delete(:attr_name))
      row[:allow_null] = row[:allow_null] == 'YES'
      row[:primary_key] = pks.include?(name)
      row[:type] = schema_column_type(row[:db_type])
      row[:max_length] = row[:prec] if row[:type] == :string
      [name, row]
    end
end
supports_savepoints?() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 39
def supports_savepoints?
  false
end
tables(opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 70
def tables(opts=OPTS)
  _tables('CLASS')
end
views(opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 74
def views(opts=OPTS)
  _tables('VCLASS')
end

Private Instance Methods

_tables(type) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 80
def _tables(type)
  m = output_identifier_meth
  metadata_dataset.
    from(:db_class).
    where(:is_system_class=>'NO', :class_type=>type).
    select_map(:class_name).
    map{|c| m.call(c)}
end
alter_table_change_column_sql(table, op) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 93
def alter_table_change_column_sql(table, op)
  o = op[:op]
  opts = schema(table).find{|x| x.first == op[:name]}
  opts = opts ? opts.last.dup : {}
  opts[:name] = o == :rename_column ? op[:new_name] : op[:name]
  opts[:type] = o == :set_column_type ? op[:type] : opts[:db_type]
  opts[:null] = o == :set_column_null ? op[:null] : opts[:allow_null]
  opts[:default] = o == :set_column_default ? op[:default] : opts[:ruby_default]
  opts.delete(:default) if opts[:default] == nil
  "CHANGE COLUMN #{quote_identifier(op[:name])} #{column_definition_sql(op.merge(opts))}"
end
alter_table_rename_column_sql(table, op) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 89
def alter_table_rename_column_sql(table, op)
  "RENAME COLUMN #{quote_identifier(op[:name])} AS #{quote_identifier(op[:new_name])}"
end
alter_table_set_column_default_sql(table, op)
alter_table_set_column_null_sql(table, op)
alter_table_set_column_type_sql(table, op)
alter_table_sql(table, op) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/cubrid.rb, line 108
def alter_table_sql(table, op)
  case op[:op]
  when :drop_index
    "ALTER TABLE #{quote_schema_table(table)} #{drop_index_sql(table, op)}"
  else
    super
  end
end
auto_increment_sql() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 117
def auto_increment_sql
  AUTOINCREMENT
end
column_definition_order() click to toggle source

CUBRID requires auto increment before primary key

# File lib/sequel/adapters/shared/cubrid.rb, line 122
def column_definition_order
  COLUMN_DEFINITION_ORDER
end
column_references_sql(column) click to toggle source

CUBRID requires FOREIGN KEY keywords before a column reference

Calls superclass method
# File lib/sequel/adapters/shared/cubrid.rb, line 127
def column_references_sql(column)
  sql = super
  sql = " FOREIGN KEY#{sql}" unless column[:columns]
  sql
end
connection_execute_method() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 133
def connection_execute_method
  :query
end
database_error_regexps() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 143
def database_error_regexps
  DATABASE_ERROR_REGEXPS
end
supports_named_column_constraints?() click to toggle source

CUBRID does not support named column constraints.

# File lib/sequel/adapters/shared/cubrid.rb, line 148
def supports_named_column_constraints?
  false
end
type_literal_generic_trueclass(column) click to toggle source

CUBRID doesn't support booleans, it recommends using smallint.

# File lib/sequel/adapters/shared/cubrid.rb, line 153
def type_literal_generic_trueclass(column)
  :smallint
end
uses_clob_for_text?() click to toggle source

CUBRID uses clob for text types.

# File lib/sequel/adapters/shared/cubrid.rb, line 158
def uses_clob_for_text?
  true
end
view_with_check_option_support() click to toggle source

CUBRID supports views with check option, but not local.

# File lib/sequel/adapters/shared/cubrid.rb, line 163
def view_with_check_option_support
  true
end