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 13
def database_type
  :cubrid
end
indexes(table, opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 17
def indexes(table, opts=OPTS)
  m = output_identifier_meth
  m2 = input_identifier_meth
  indexes = {}
  metadata_dataset.
    from(:db_index___i).
    join(:db_index_key___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___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 38
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(:db_index_key___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___db_type, :default_value___default, :is_nullable___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 34
def supports_savepoints?
  false
end
tables(opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 65
def tables(opts=OPTS)
  _tables('CLASS')
end
views(opts=OPTS) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 69
def views(opts=OPTS)
  _tables('VCLASS')
end

Private Instance Methods

_tables(type) click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 75
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_op_sql(table, op) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/cubrid.rb, line 84
def alter_table_op_sql(table, op)
  case op[:op]
  when :rename_column
    "RENAME COLUMN #{quote_identifier(op[:name])} AS #{quote_identifier(op[:new_name])}"
  when :set_column_type, :set_column_null, :set_column_default
    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))}"
  else
    super
  end
end
alter_table_sql(table, op) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/cubrid.rb, line 103
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 112
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 117
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 122
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 128
def connection_execute_method
  :query
end
database_error_regexps() click to toggle source
# File lib/sequel/adapters/shared/cubrid.rb, line 138
def database_error_regexps
  DATABASE_ERROR_REGEXPS
end
identifier_input_method_default() click to toggle source

CUBRID is case insensitive, so don't modify identifiers

# File lib/sequel/adapters/shared/cubrid.rb, line 143
def identifier_input_method_default
  nil
end
identifier_output_method_default() click to toggle source

CUBRID is case insensitive, so don't modify identifiers

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

CUBRID does not support named column constraints.

# File lib/sequel/adapters/shared/cubrid.rb, line 153
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 158
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 163
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 168
def view_with_check_option_support
  true
end