Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7344 (reopened defect)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Make Oracle respect default values for LOBs

Reported by: gfriedrich Assigned to: mschoen
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: oracle tiny
Cc:

Description

Patch and unit tests so that the Oracle adapter respects default values for CLOBs and BLOBs.

Attachments

fix_defaults_for_oracle_lobs.6027.diff (2.4 kB) - added by gfriedrich on 01/24/07 04:40:11.
fix_defaults_for_oracle_lobs_2.6039.diff (1.6 kB) - added by gfriedrich on 01/24/07 23:46:54.
fix_defaults_for_oracle_lobs_3.6039.diff (1.9 kB) - added by gfriedrich on 01/25/07 01:11:27.
oracle_text_defaults.patch (4.8 kB) - added by mschoen on 01/29/07 21:27:27.

Change History

01/24/07 04:40:11 changed by gfriedrich

  • attachment fix_defaults_for_oracle_lobs.6027.diff added.

01/24/07 05:21:11 changed by bitsweat

  • owner changed from core to mschoen.

01/24/07 05:22:34 changed by gfriedrich

I should add that I tested the patch only with Oracle 10g Express Edition (and Postgresql 8.1.4).

01/24/07 23:46:34 changed by gfriedrich

I was a bit too quick yesterday. The problem is a bit bigger than I thought. Firstly, this patch will break the Oracle LOB support for values bigger than 4000 bytes.

The current behaviour is that in migrations default values are set to "empty_clob()" or "empty_blob()" regardless of the given default value. This is because ConnectionAdapter::quote() is used to quote the default value. But the OracleAdapter overwrites quote() and uses an after_save callback in order to support LOBs. Since [5937] the problem got worse, because now migrations always add a DEFAULT to the column options.

This now means if you have a table like that:

create_table "posts" do |t|
  t.column "content", :text
end

You'll get the following behaviour:

>> Post.new.content
=> "empty_clob()"

Obviously that breaks any validates_presence_of. The new patch fixes this because the OracleAdapter treats empty_clob() and empty_blob() as "".

The default value issue still remains.

Michael, what are your thoughts on this?

01/24/07 23:46:54 changed by gfriedrich

  • attachment fix_defaults_for_oracle_lobs_2.6039.diff added.

01/25/07 01:11:27 changed by gfriedrich

  • attachment fix_defaults_for_oracle_lobs_3.6039.diff added.

01/25/07 01:15:30 changed by gfriedrich

The third patch includes the changes from the second patch and corrects the issue when using no default value for a CLOB or BLOB. It now sets the default value to NULL instead of empty_clob().

01/29/07 21:27:04 changed by mschoen

This revised patch handles default values for :text columns.

01/29/07 21:27:27 changed by mschoen

  • attachment oracle_text_defaults.patch added.

01/29/07 22:06:09 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [6090]) Oracle: fix lob and text default handling. Closes #7344.

11/20/07 10:20:19 changed by jt

  • status changed from closed to reopened.
  • resolution deleted.

Rails 1.2.5 puts "empty_clob()" as default value, _whatever_ I put in my migration:

t.column :test1, :text t.column :test2, :text, :default => "null" t.column :test3, :text, :default => nil t.column :test4, :text, :default => "hello world" t.column :test5, :text, :data_default => "null" t.column :test6, :text, :data_default => nil t.column :test7, :text, :data_default => "hello world"

config: rails 1.2.5, oci8 1.0-rc3, oracle 10g