Skip to content

Commit 4a4c046

Browse files
committed
empty_insert_statement_value for Derby and HSQLDB won't work
1 parent 2f8befa commit 4a4c046

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

lib/arjdbc/derby/adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def add_column_options!(sql, options)
160160
super
161161
end
162162

163+
def empty_insert_statement_value
164+
'VALUES ( DEFAULT )' # won't work as Derby does need to know the columns count
165+
end
166+
163167
# Set the sequence to the max value of the table's column.
164168
def reset_sequence!(table, column, sequence = nil)
165169
mpk = select_value("SELECT MAX(#{quote_column_name(column)}) FROM #{quote_table_name(table)}")

lib/arjdbc/hsqldb/adapter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ def add_limit_offset!(sql, options) #:nodoc:
189189
end
190190
end
191191

192+
def empty_insert_statement_value
193+
# on HSQLDB only work with tables that have a default value for each
194+
# and every column ... you'll need to avoid `Model.create!` on 4.0
195+
'DEFAULT VALUES'
196+
end
197+
192198
# filter out system tables (that otherwise end up in db/schema.rb)
193199
# JdbcConnection#tables
194200
# now takes an optional block filter so we can screen out

test/db/derby/simple_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class DerbySimpleTest < Test::Unit::TestCase
88
include ActiveRecord3TestMethods
99
include CustomSelectTestMethods
1010

11+
# @override
12+
def test_empty_insert_statement
13+
# "INSERT INTO table VALUES ( DEFAULT ) " not supported by Derby DB
14+
pend if ar_version('4.0')
15+
super
16+
end
17+
1118
# Check that a table-less VALUES(xxx) query (like SELECT works.
1219
def test_values
1320
value = nil
@@ -28,7 +35,7 @@ def test_find_with_include_and_order
2835
end
2936

3037
def test_text_and_string_conversions
31-
e = DbType.first
38+
e = DbType.create!(:sample_string => '', :sample_text => '').reload
3239

3340
# Derby will normally reject any non text value.
3441
# The adapter has been patched to convert non text values to strings

test/db/hsqldb/simple_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ class HsqldbSimpleTest < Test::Unit::TestCase
66
include ExplainSupportTestMethods if ar_version("3.1")
77
include ActiveRecord3TestMethods
88
include CustomSelectTestMethods
9+
10+
# @override
11+
def test_empty_insert_statement
12+
# "INSERT INTO table DEFAULT VALUES" only works if all columns have defaults
13+
pend if ar_version('4.0')
14+
super
15+
end
16+
917
end

0 commit comments

Comments
 (0)