Included Modules

Class Index [+]

Quicksearch

Sequel::JDBC::Derby::DatabaseMethods

Instance methods for Derby Database objects accessed via JDBC.

Constants

PRIMARY_KEY_INDEX_RE

Public Instance Methods

cast_type_literal(type) click to toggle source

Derby doesn’t support casting integer to varchar, only integer to char, and char(254) appears to have the widest support (with char(255) failing). This does add a bunch of extra spaces at the end, but those will be trimmed elsewhere.

    # File lib/sequel/adapters/jdbc/derby.rb, line 17
17:         def cast_type_literal(type)
18:           (type == String) ? 'CHAR(254)' : super
19:         end
database_type() click to toggle source

Derby uses the :derby database type.

    # File lib/sequel/adapters/jdbc/derby.rb, line 22
22:         def database_type
23:           :derby
24:         end
serial_primary_key_options() click to toggle source

Derby uses an IDENTITY sequence for autoincrementing columns.

    # File lib/sequel/adapters/jdbc/derby.rb, line 27
27:         def serial_primary_key_options
28:           {:primary_key => true, :type => :integer, :identity=>true, :start_with=>1}
29:         end
supports_transactional_ddl?() click to toggle source

Derby supports transaction DDL statements.

    # File lib/sequel/adapters/jdbc/derby.rb, line 41
41:         def supports_transactional_ddl?
42:           true
43:         end
svn_version() click to toggle source

The SVN version of the database.

    # File lib/sequel/adapters/jdbc/derby.rb, line 32
32:         def svn_version
33:           @svn_version ||= begin
34:             v = synchronize{|c| c.get_meta_data.get_database_product_version}
35:             v =~ /\((\d+)\)\z/
36:             $1.to_i
37:           end
38:         end

Private Instance Methods

_table_exists?(ds) click to toggle source

Derby optimizes away Sequel’s default check of SELECT NULL FROM table, so use a SELECT * FROM table there.

    # File lib/sequel/adapters/jdbc/derby.rb, line 49
49:         def _table_exists?(ds)
50:           ds.first
51:         end
alter_table_sql(table, op) click to toggle source

Derby-specific syntax for renaming columns and changing a columns type/nullity.

    # File lib/sequel/adapters/jdbc/derby.rb, line 54
54:         def alter_table_sql(table, op)
55:           case op[:op]
56:           when :rename_column
57:             "RENAME COLUMN #{quote_schema_table(table)}.#{quote_identifier(op[:name])} TO #{quote_identifier(op[:new_name])}"
58:           when :set_column_type
59:             # Derby is very limited in changing a columns type, so adding a new column and then dropping the existing column is
60:             # the best approach, as mentioned in the Derby documentation.
61:             temp_name = :x_sequel_temp_column_x
62:             [alter_table_sql(table, op.merge(:op=>:add_column, :name=>temp_name)),
63:              from(table).update_sql(temp_name=>::Sequel::SQL::Cast.new(op[:name], op[:type])),
64:              alter_table_sql(table, op.merge(:op=>:drop_column)),
65:              alter_table_sql(table, op.merge(:op=>:rename_column, :name=>temp_name, :new_name=>op[:name]))]
66:           when :set_column_null
67:             "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{op[:null] ? 'NULL' : 'NOT NULL'}"
68:           else
69:             super
70:           end
71:         end
column_definition_null_sql(sql, column) click to toggle source

Derby doesn’t allow specifying NULL for columns, only NOT NULL.

    # File lib/sequel/adapters/jdbc/derby.rb, line 74
74:         def column_definition_null_sql(sql, column)
75:           sql << " NOT NULL" if column.fetch(:null, column[:allow_null]) == false
76:         end
create_table_as(name, sql, options) click to toggle source

Insert data from the current table into the new table after creating the table, since it is not possible to do it in one step.

    # File lib/sequel/adapters/jdbc/derby.rb, line 87
87:         def create_table_as(name, sql, options)
88:           super
89:           from(name).insert(sql.is_a?(Dataset) ? sql : dataset.with_sql(sql))
90:         end
create_table_as_sql(name, sql, options) click to toggle source

Derby currently only requires WITH NO DATA, with a separate insert to import data.

    # File lib/sequel/adapters/jdbc/derby.rb, line 94
94:         def create_table_as_sql(name, sql, options)
95:           "#{create_table_prefix_sql(name, options)} AS #{sql} WITH NO DATA"
96:         end
create_table_prefix_sql(name, options) click to toggle source

Temporary table creation on Derby uses DECLARE instead of CREATE.

     # File lib/sequel/adapters/jdbc/derby.rb, line 99
 99:         def create_table_prefix_sql(name, options)
100:           if options[:temp]
101:             "DECLARE GLOBAL TEMPORARY TABLE #{quote_identifier(name)}"
102:           else
103:             super
104:           end
105:         end
create_table_sql(name, generator, options) click to toggle source

Add NOT LOGGED for temporary tables to improve performance.

    # File lib/sequel/adapters/jdbc/derby.rb, line 79
79:         def create_table_sql(name, generator, options)
80:           s = super
81:           s << ' NOT LOGGED' if options[:temp]
82:           s
83:         end
last_insert_id(conn, opts={}) click to toggle source

Use IDENTITY_VAL_LOCAL() to get the last inserted id.

     # File lib/sequel/adapters/jdbc/derby.rb, line 108
108:         def last_insert_id(conn, opts={})
109:           statement(conn) do |stmt|
110:             sql = 'SELECT IDENTITY_VAL_LOCAL() FROM sysibm.sysdummy1'
111:             rs = log_yield(sql){stmt.executeQuery(sql)}
112:             rs.next
113:             rs.getInt(1)
114:           end
115:         end
primary_key_index_re() click to toggle source

Primary key indexes appear to be named sqlNNNN on Derby

     # File lib/sequel/adapters/jdbc/derby.rb, line 123
123:         def primary_key_index_re
124:           PRIMARY_KEY_INDEX_RE
125:         end
rename_table_sql(name, new_name) click to toggle source

Derby uses RENAME TABLE syntax to rename tables.

     # File lib/sequel/adapters/jdbc/derby.rb, line 118
118:         def rename_table_sql(name, new_name)
119:           "RENAME TABLE #{quote_schema_table(name)} TO #{quote_schema_table(new_name)}"
120:         end
type_literal(column) click to toggle source

If an :identity option is present in the column, add the necessary IDENTITY SQL.

     # File lib/sequel/adapters/jdbc/derby.rb, line 128
128:         def type_literal(column)
129:           if column[:identity]
130:             sql = "#{super} GENERATED BY DEFAULT AS IDENTITY"
131:             if sw = column[:start_with]
132:               sql << " (START WITH #{sw.to_i}"
133:               sql << " INCREMENT BY #{column[:increment_by].to_i}" if column[:increment_by]
134:               sql << ")"
135:             end
136:             sql
137:           else
138:             super
139:           end
140:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.