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

Ticket #1874 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Firebird Adapter (based on FireRuby extension)

Reported by: Ken Kunz <kennethkunz@gmail.com> Assigned to: Jeremy Kemper <rails@bitsweat.net>
Priority: normal Milestone: 1.0
Component: ActiveRecord Version: 1.1.1
Severity: normal Keywords: adapter firebird interbase
Cc:

Description

This Firebird adapter represents an original effort and differs significantly from the adapter submitted under ticket #1418, so I am posting it under a separate ticket.

This adapter is based on the FireRuby Ruby extension for connecting to a Firebird database, which (imho) provides several improvements over the older Interbase extension. FireRuby is published as a gem, provides a richer API, is actively supported and well documented.

Implementing the Firebird adapter required several small changes to ActiveRecord. All of these changes are fully backward compatible and have been tested against Firebird (of course) as well as SQLite, MySQL and PostgreSQL.

Summary of ActiveRecord changes:

  1. Modified validates_uniqueness_of method in validations.rb to address "= NULL" comparison issue (see #1391 for background). To generate the correct NULL comparison syntax, I call the existing attribute_condition method (in base.rb). I also refactored validates_uniqueness_of to eliminate some duplication and make it more readable.
  2. Modified several methods in base.rb and associations.rb to ensure that column names are properly quoted. This was a problem because "type" (the default inheritance column name) is a reserved word for Firebird. The problem is addressed by calling quote_column_name, which is implemented by each of the adapters.
    • This fix caused some unit tests to fail in SQLite3. I was able to address the problem by changing the quote_column_name method in the sqlite adapter to use double-quotes instead of single-quotes.
    • Several test fixtures and unit tests reference "type" in find conditions, so I had to ensure that "type" is quoted in tests as well. I added a QUOTED_TYPE constant to abstract_unit.rb, and replaced all explicit references to "type".
  3. Firebird uses sequence generators as opposed to AUTO INCREMENT or IDENTITY columns to handle auto-generated primary key values. The only reliable way to know what pk value was used in an insert it to pre-fetch it and explicitly include the column/value pair in the insert. This is concurrency-safe because sequence generators are not subject to transactional context (so they aren't rolled-back). To implement this, I modified Base#create (in base.rb) to pre-fetch the next pk value from the correct sequence if the adapter requires it.

If this patch is accepted, tickets #1391 and #1418 may be closed.

Attachments

firebird_adapter_r1957.diff (40.2 kB) - added by Ken Kunz <kennethkunz@gmail.com> on 07/30/05 12:59:38.
Firebird Adapter patch based on trunk rev. 1957
firebird_adapter_r2032.diff (40.5 kB) - added by Ken Kunz <kennethkunz@gmail.com> on 08/18/05 21:19:28.
Firebird Adapter patch based on trunk rev. 2032
firebird_adapter_r2832.diff (48.5 kB) - added by Ken Kunz <kennethkunz@gmail.com> on 11/01/05 11:05:12.
Firebird Adapter patch based on AR rev. 2832

Change History

07/30/05 12:59:38 changed by Ken Kunz <kennethkunz@gmail.com>

  • attachment firebird_adapter_r1957.diff added.

Firebird Adapter patch based on trunk rev. 1957

08/12/05 22:55:47 changed by Ken Kunz <kennethkunz@gmail.com>

I've received inquiries from several people interested in testing the Firebird adapter, so I created a page on the Rails wiki with instructions on a simplified way to deploy/test the patch: http://wiki.rubyonrails.com/rails/show/Firebird+Adapter

08/18/05 21:17:13 changed by Ken Kunz <kennethkunz@gmail.com>

A minor defect with the adapter has been identified and fixed. The Firebird TIMESTAMP column type was being mapped to the ActiveRecord :timestamp type, instead of :datetime as it should be (thanks Peter Jagielski for the catch). I fixed the mapping, and added a Firebird specific test that verifies the correct mapping. I also made some minor documentation updates. I am attaching an updated diff file.

08/18/05 21:19:28 changed by Ken Kunz <kennethkunz@gmail.com>

  • attachment firebird_adapter_r2032.diff added.

Firebird Adapter patch based on trunk rev. 2032

09/27/05 13:38:47 changed by peter@tcssoftware.com

Just wanted to post some info regarding my testing of the Firebird Adapter:

OS: WinXP/SP2

Browser: IE6 (patches current), FireFox 1.0.6

Ruby: 1.8.2-15

Rails: 0.13.1

Firebird: 1.5.2

As I'm learning RoR, I'm just working on getting all the basics of a web app up and running, including basic data entry chores and database manipulation. I've also successfully used Firebird instead of MySQL while making my way through the Agile RoR book and Depot tutorial. The only thing I had to change while following the tutorial was on p. 73 at the top where the self.salable_items method is defined. Had to change the MySQL "now()" function to FB's "now". Otherwise, no problems and running smoothly.

11/01/05 11:05:12 changed by Ken Kunz <kennethkunz@gmail.com>

  • attachment firebird_adapter_r2832.diff added.

Firebird Adapter patch based on AR rev. 2832

11/01/05 11:12:40 changed by Ken Kunz <kennethkunz@gmail.com>

I attached an updated patch file based on rev. 2832. This is mainly to bring the adapter up-to-date. I also addressed a couple of issues discovered by other testers, including:

  • minor issue handling default values for Firebird domains
  • improved handling of BOOLEAN domains (behavior is now configurable to support legacy schemas)

I'm still working on Migrations, but I figured I should get an updated patch posted in the meantime. Hope to have Migrations done in about a week, time permitting.

Please let me know if you need any assistance getting Firebird and FireRuby set up to test the adapter. Note that I am following up to get FireRuby compiled for FreeBSD (for the Rails test server).

11/03/05 03:44:58 changed by Luis Lavena

FireRuby Rails Adapter as Plugin?

Based on the simple-but-useful new plugin system, is there a way instead of patching ActiveRecord extend it to include Firebird support?

11/16/05 06:25:55 changed by bitsweat

  • owner changed from David to bitsweat.

Hey Ken, are you working with wishdev? (see #1418)

I'd like to get this into trunk. A ~50KB patch is daunting since it has so many changes (including those outside of the adapter itself) so it's hard to be sure we aren't introducing regressions. But I'll give it a go -- thanks for all the hard work!

11/16/05 07:58:43 changed by bitsweat

Why the change test_default_values_on_empty_strings in base_test?

11/16/05 08:18:19 changed by bitsweat

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

(In [3052]) r3116@asus: jeremy | 2005-11-16 00:17:06 -0800

Introducing the Firebird adapter. Closes #1874.

11/16/05 08:21:24 changed by bitsweat

See #428 for issues with connection management.

11/24/05 01:17:44 changed by bitsweat

(In [3177]) r3303@asus: jeremy | 2005-11-23 17:14:31 -0800

Apply [3051], [3052], [3053], [3059] to stable. Brings the Firebird adapter to 1.0. References #1874.

11/24/05 01:18:34 changed by bitsweat

  • milestone changed from 1.1 to 1.0.

01/16/06 21:03:59 changed by chris_rorwiki@acron.biz

I posted a question on the wiki about whether the adapter works as a session storage mechanism and also a problem with using schema's (migration management).

04/14/06 02:44:19 changed by richmcgillicuddy@yahoo.com

  • status changed from closed to reopened.
  • type changed from enhancement to defect.
  • version changed from 0.13.1 to 1.1.1.
  • resolution deleted.

Using Firebird 1.2 Classic on Windows, latest FireRuby and Rails 1.1.2.

I get a FireRuby::FireRubyException with no additional information if I try to generate scaffold for a firebird table. Appears to connect OK. This consistently happens at the test/fictures/[table].yml step. I've tried it a few times.

04/14/06 02:47:11 changed by richmcgillicuddy@yahoo.com

Wrong versions in last post. Firebird 1.52. Tried FireRuby 0.4.1, went down to 0.3.2 and had the same results

07/08/06 01:42:18 changed by bitsweat

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

08/07/06 09:25:23 changed by bitsweat

(In [4708]) r3022@ks: jeremy | 2005-11-12 18:40:42 -0800

merge to stable r3024@ks: jeremy | 2005-11-12 19:00:49 -0800 Apply [2992] to stable. SQLite: the clone_structure_to_test and purge_test_database Rake tasks should always use the test environment. References #2846. r3027@ks: jeremy | 2005-11-12 22:37:45 -0800 Apply [2994] to stable. PostgreSQL: correct the sequence discovery fallback query. References #2594. r3033@ks: jeremy | 2005-11-12 23:27:13 -0800 Apply [2996] to stable. Much faster Oracle column reflection. Closes #2848. r3037@ks: jeremy | 2005-11-13 00:11:26 -0800 Apply [2998] to stable. PostgreSQL: last_insert_id uses select_value rather than using @connection.exec directly. r3053@ks: jeremy | 2005-11-13 14:37:39 -0800 Only include builtin filters whose filenames match /[a-z][a-z_]*_helper.rb$/ to avoid including operating system metadata such as ._foo_helper.rb. Closes #2855. r3055@ks: jeremy | 2005-11-13 14:48:48 -0800 Apply [3009] to stable: Reapply [2942] which was elided by [2997]. References #2788. r3058@ks: jeremy | 2005-11-13 16:09:17 -0800 Apply [3013] to stable. Note that the ruby-memcache bindings are required to use the memcache store. Closes #2857. r3063@ks: jeremy | 2005-11-13 16:13:51 -0800 Apply [3015] to stable. Update documentation for render :file. Closes #2858. r3066@ks: jeremy | 2005-11-13 20:24:18 -0800 Apply [3017] to stable. Update documentation for Migrations. Closes #2861. r3070@ks: jeremy | 2005-11-13 20:54:50 -0800 Apply [3019] to stable. Oracle: test case for column default parsing. Closes #2788. r3073@ks: jeremy | 2005-11-13 23:42:32 -0800 Apply [3021] to stable. Correct documentation for Base.delete_all. Closes #1568. r3077@ks: jeremy | 2005-11-14 14:28:21 -0800 Apply [3035] to stable. SQLServer: insert uses given primary key value if not nil rather than SELECT @@IDENTITY. Closes #2866. r3120@ks: jeremy | 2005-11-16 13:34:45 -0800 Apply [3060] to stable. Remove the unused, slow response_dump and session_dump variables from error pages. Closes #1222. r3130@ks: jeremy | 2005-11-16 14:37:47 -0800 Apply [3063] to stable. Remove CHANGELOG from apidoc Rake task since it isn't included with new apps anymore. r3148@ks: jeremy | 2005-11-17 12:45:44 -0800 Apply [3074] to stable. Don't add the same conditions twice in has_one finder sql. Closes #2916. r3149@ks: jeremy | 2005-11-17 12:47:36 -0800 Apply [3075] to stable. Document :force option to create_table. Closes #2921. r3157@ks: jeremy | 2005-11-17 21:27:39 -0800 Apply [3081] to stable. Eliminate nil from newly generated logfiles. Closes #2927. r3167@ks: jeremy | 2005-11-18 22:47:31 -0800 Apply [3089] to stable. Don't generate read methods for columns whose names are not valid ruby method names. Closes #2946. r3174@ks: jeremy | 2005-11-19 01:53:00 -0800 Apply [3092] to stable. Correct boolean handling in generated reader methods. Closes #2945. r3178@ks: jeremy | 2005-11-19 01:59:47 -0800 Apply [3094] to stable. Use query methods rather than readers in boolean tests for [3092]. References #2949. r3190@ks: jeremy | 2005-11-19 20:20:48 -0800 Apply [3098] to stable. Introducing the session_migration generator. Creates an add_session_table migration. Closes #2958. r3199@ks: jeremy | 2005-11-19 21:13:22 -0800 Apply [3101] to stable. Allows generator to specify migrations directory. Closes #2960. r3201@ks: jeremy | 2005-11-19 21:31:47 -0800 Apply [3103] to stable. Document request.env and request.host. Strip trailing whitespace. r3258@ks: jeremy | 2005-11-21 00:33:59 -0800 Apply [3139] to stable. Use Kernel.binding rather than binding to allow columns of that name. Closes #2973. r3269@ks: jeremy | 2005-11-21 04:46:40 -0800 Apply [3148] to stable. Simpler Mysql load test. r3285@ks: jeremy | 2005-11-22 13:33:04 -0800 Apply [3162] to stable. Model generator: correct relative path to test_helper in unit test. r3296@ks: jeremy | 2005-11-23 13:38:56 -0800 Apply [3170] to stable. Credit ticket author. References #2888. r3303@ks: jeremy | 2005-11-23 17:14:31 -0800 Apply [3051], [3052], [3053], [3059] to stable. Brings the Firebird adapter to 1.0. References #1874. r3305@ks: jeremy | 2005-11-23 17:33:51 -0800 Apply [3151] to stable. Don't put flash in session if sessions are disabled. r3306@ks: jeremy | 2005-11-23 17:39:24 -0800 Apply [3100], [3108] to stable. Makes new ActiveRecordStore sessions work correctly with components. r3307@ks: jeremy | 2005-11-23 17:52:14 -0800 Apply [3110] to stable. PostgreSQL: the purge_test_database Rake task shouldn't explicitly specify the template0 template when creating a fresh test database. References #2964. r3313@ks: jeremy | 2005-11-23 23:03:36 -0800 Apply [3182] to stable. Reloading a model doesn't lose track of its connection. Closes #2996. r3315@ks: jeremy | 2005-11-23 23:13:48 -0800 Apply [3184] to stable. SQLServer: resolve column aliasing/quoting collision when using limit or offset in an eager find. Closes #2974. r3339@ks: jeremy | 2005-12-01 17:03:16 -0800 Apply [3202] to stable. Firebird: updated for FireRuby 0.4.0. Closes #3009. r3363@ks: jeremy | 2005-12-06 22:26:27 -0800 Apply #428 changesets to stable: r3000, r3001, r3002, r3025, r3045, r3096, r3148, r3152, r3165, r3189, r3195, r3205, r3216, r3219, r3221, r3222. Closes #428. r3372@ks: jeremy | 2005-12-07 20:25:20 -0800 Apply [3233] to stable. Oracle: use syntax compatible with Oracle 8. Closes #3131. r3375@ks: jeremy | 2005-12-07 20:36:13 -0800 Apply [3235] to stable. PostgreSQL: more robust sequence name discovery. Closes #3087. r3378@ks: jeremy | 2005-12-07 20:41:47 -0800 Apply [3237] to stable. More robust relative url root discovery for SCGI compatibility. This solves the 'SCGI routes problem' -- you no longer need to prefix all your routes with the name of the SCGI mountpoint. Closes #3070. r3379@ks: jeremy | 2005-12-07 20:42:31 -0800 Don't warn on keep_flash in test. r3387@ks: jeremy | 2005-12-07 20:48:42 -0800 Apply [3242] to stable. Reloading an instance refreshes its aggregations as well as its associations. Closes #3024. r3389@ks: jeremy | 2005-12-07 20:52:39 -0800 Apply [3244] to stable. SQLite: find database file when RAILS_ROOT is a symlink. Closes #3116. r3392@ks: jeremy | 2005-12-07 21:10:42 -0800 Apply [3246] to stable. MySQL: more robust test for nullified result hashes. Closes #3124. r3401@ks: jeremy | 2005-12-07 23:30:11 -0800 Apply [3252] to stable. Oracle: active? performs a select instead of a commit. Closes #3133. r3404@ks: jeremy | 2005-12-08 15:24:44 -0800 Apply [3254] to stable. Fix some test failures due to MySQL assumptions. References #3149. r3407@ks: jeremy | 2005-12-09 10:39:00 -0800 Apply [3256] to stable. Generator copies files in binary mode. Closes #3156. r3410@ks: jeremy | 2005-12-09 10:48:32 -0800 Apply [3258] to stable. Fix shebang handling for empty files. Closes #2927. r3413@ks: jeremy | 2005-12-09 15:03:42 -0800 Apply [3260] to stable. Fix bundled mysql.rb to correctly check for PROTO_41. Fixed scramble41 with nil password. Fixed change_user with PROTO_41. r3416@ks: jeremy | 2005-12-09 15:07:21 -0800 Apply [3262] to stable. Generator looks in vendor/generators also. r3419@ks: jeremy | 2005-12-09 15:36:50 -0800 Apply [3165] to stable. MySQL, PostgreSQL: reconnect! also reconfigures the connection. Otherwise, the connection 'loses' its settings if it times out and is reconnected. References #2978. r3420@ks: jeremy | 2005-12-09 15:38:30 -0800 Apply [3264] to stable. MySQL: ensure that @config is set. r3421@ks: jeremy | 2005-12-09 15:42:40 -0800 Apply [3265] to stable. Name vendor/generators source differently from lib/generators source. r3429@ks: jeremy | 2005-12-09 16:55:16 -0800 Apply [3270] SQLServer rollup to stable. r3435@ks: jeremy | 2005-12-10 13:40:43 -0800 Apply [3274] to stable. MySQL: fixes for the bundled mysql.rb driver. Closes #3160. r3457@ks: jeremy | 2005-12-13 08:52:39 -0800 Apply [3293] to stable. MySQL: allow encoding option for mysql.rb driver. r3458@ks: jeremy | 2005-12-13 09:33:50 -0800 Roll back [3245] on stable. References #3116. r3465@ks: jeremy | 2005-12-13 10:15:33 -0800 Apply [3298] to stable. Don't used defined? on a scoped constant since it results in a const_missing call. r3724@ks: jeremy | 2006-02-09 10:13:41 -0800 Apply [3554] to stable. PostgreSQL: correctly parse negative integer column defaults. Closes #3776. r3730@ks: jeremy | 2006-02-09 11:42:57 -0800 Apply [3559] to stable. Closes #3581. r3846@ks: jeremy | 2006-02-26 15:24:58 -0800 silence test/unit whining DefaultsTest is empty r3847@ks: jeremy | 2006-02-26 15:26:53 -0800 Apply [3674] to stable. Closes #3591. r4960@ks: jeremy | 2006-08-06 23:56:18 -0700 Merged to stable: change the request.env example in AC::Base docs to a var that exists (REMOTE_IP doesn't) and isn't already wrapped by a request method (i.e. request.remote_ip). References #5113. r4961@ks: jeremy | 2006-08-07 00:11:59 -0700 Merged to stable: add :status option to send_data and send_file. Defaults to '200 OK'. References #5243. r4962@ks: jeremy | 2006-08-07 00:18:42 -0700 Merged to stable: real files and symlinks should be treated the same when compiling templates. References #5438. r4963@ks: jeremy | 2006-08-07 00:26:42 -0700 Merged to stable: Added ActionController.filter_parameter_logging that makes it easy to remove passwords, credit card numbers, and other sensitive information from being logged when a request is handled. References #1897. r4964@ks: jeremy | 2006-08-07 00:33:32 -0700 Merged to stable: correct spurious documentation example code which results in a SyntaxError. References [4210]. r4965@ks: jeremy | 2006-08-07 00:38:04 -0700 Merged to stable: remote_form_for can leave out the object parameter and default to the instance variable of the object_name, just like form_for. References [4215]. r4966@ks: jeremy | 2006-08-07 00:48:40 -0700 Merged to stable: update inconsistent migrations documentation. References #4683. r4967@ks: jeremy | 2006-08-07 00:52:34 -0700 Merge to stable: cache CgiRequest#request_parameters so that multiple calls don't re-parse multipart data. References [4256]. r4968@ks: jeremy | 2006-08-07 00:55:51 -0700 Merge to stable: only require redcloth/bluecloth if they are not already loaded. References [4257]. r4977@ks: jeremy | 2006-08-07 01:08:02 -0700 Merge to stable: skip silence stderr test if we can't STDERR.tell r4978@ks: jeremy | 2006-08-07 01:13:00 -0700 Merge to stable: update layout and content_for documentation to use yield rather than magic @content_for_layout instance variables. References [4263]. r4979@ks: jeremy | 2006-08-07 01:16:43 -0700 Merge to stable: add documentation for redirect_to :back's RedirectBackError exception; remove all remaining references to @params in the documentation. References [4267], [4268]. r4980@ks: jeremy | 2006-08-07 01:18:04 -0700 Merge to stable: fix documentation indentation. r4981@ks: jeremy | 2006-08-07 01:28:34 -0700 Merge to stable: mention in docs that config.frameworks doesn't work when getting Rails via Gems; documentation for AbstractRequest. References #4857, #4895. r4982@ks: jeremy | 2006-08-07 01:45:26 -0700 Merge to stable: fix syntax error in documentation. References #4679. r4983@ks: jeremy | 2006-08-07 01:50:47 -0700 Merge to stable: Enhance documentation for setting headers in integration tests. Skip auto HTTP prepending when its already there. References #4079. Add warning about the proper way to validate the presence of a foreign key. References #4147. r4984@ks: jeremy | 2006-08-07 02:08:00 -0700 Merge to stable: ActionController::Base Summary documentation rewrite; Fix text_helper.rb documentation rendering; Fixes bad rendering of JavaScriptMacrosHelper rdoc. References #4725, #4900, #4910. r4985@ks: jeremy | 2006-08-07 02:14:18 -0700 Merge to stable: documentation fix: integration test scripts don't require integration_test. References #4914.