Forum: Ruby on Rails Sybase ctlib Adapter

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John S. (Guest)
on 2006-02-01 16:05
(Received via mailing list)
Hi,

I've been trying to update Will Sobel's sybase-ctlib adapter to pass
unit tests on Rails 1.0.  It's been a slow, sloggy process for me so
far, as I've been learning Ruby, Rails, and Sybase administration all
in one go.  (c:  It's been a saving grace to have a good starting
point (thanks Will!).

   http://dev.rubyonrails.org/ticket/2030

The big issue I'm facing right now is reconciling fixtures and the
insert() method.  I couldn't tell for certain from looking at the SQL
in test/fixtures/db_definitions whether the unit test tables should
have (1) auto-generated id's (IDENTITY in Sybase) or (2) app-
generated id's.  Near as I could tell, the SQL for db2, mysql,
postgresql, and sqlserver use #1, while firebird, oci, and sqlite use
#2.  Just guessing tho.

In case #1, insert() would work as is for Sybase, but the fixtures
bail since they try to explicitly set the id's.  You can override
this with SET IDENTITY_INSERT, but I'm not sure how to hook into the
fixtures to flip this on and off.  This would be my preferred approach.

In case #2, the fixtures work fine, but insert() fails because of the
missing id value.  I assume I'd have to generate my own id, e.g,.
with max() + 1?  It doesn't look like the other adapters are doing
this, so I'm guessing case #1 is the way to go.

Of course, in the bigger picture, I'm not sure how ActiveRecord is
intended to handle id generation if the table (or database) doesn't
support auto-increment.  What's the rule?

Also, is anyone else out there working on the ctlib adapter?

I'd appreciate any insights.  Looking forward to getting this done so
I can go back to being a regular Rails user.  (c:

Thanks,
John
Jon S. (Guest)
on 2006-02-01 19:00
(Received via mailing list)
On 2/1/06, John S. <removed_email_address@domain.invalid> wrote:
> Hi,
>
> I've been trying to update Will Sobel's sybase-ctlib adapter to pass unit
> tests on Rails 1.0.  It's been a slow, sloggy process for me so far, as I've

If your want to work on this and don't have Sybase available, Sybase
has a free Linux version that is not too restricted. My two cents is
that Sybase is 5X more cost effective than Oracle.

http://www.sybase.com/linuxpromo

Sybase ASE Express Edition for Linux is the first enterprise-class
commercial database that can take you from pilot to deployment for
zero dollars and zero risk. You can develop a pilot project on Linux
without cost or risk AND without scrimping on performance or
manageability. Since it's an industrial-strength data management
platform, you'll be able to handle growth and evolving requirements
without painful, expensive upgrades

--
Jon S.
removed_email_address@domain.invalid
Corey L. (Guest)
on 2006-02-01 21:41
(Received via mailing list)
If you look at the SQL Server adapter, notice that in this method:

       def enable_identity_insert(table_name, enable = true)
          if has_identity_column(table_name)
            "SET IDENTITY_INSERT #{table_name} #{enable ? 'ON' : 'OFF'}"
          end
        end

...it turns on/off IDENTITY_INSERT on a given table. This is what you
would
want to emulate...
John S. (Guest)
on 2006-02-02 02:51
(Received via mailing list)
On Feb 1, 2006, at 10:59 AM, Jon S. wrote:

> that Sybase is 5X more cost effective than Oracle.
>
> http://www.sybase.com/linuxpromo

They also have a free developer's version for Mac at, IIRC:

   http://www.sybase.com/ase_1252devel

Works pretty well on my PowerBook, although it does keep falling into
a strange state where it refuses all connections; I have to kill it
from the command line and restart.  Other than that, it's great.
Sure made running the ActiveRecord unit tests easier.

John

--
John R. Sheets
http://umber.sourceforge.net
http://writersforge.sourceforge.net
John S. (Guest)
on 2006-02-02 03:34
(Received via mailing list)
On Feb 1, 2006, at 1:40 PM, Corey L. wrote:

> you would want to emulate...
Yep, I poached those and a bunch of other stuff from
sqlserver_adapter.rb.  To get the fixtures to work, I added the code
below to the end of sybase_adapter.rb, for lack of a better place.
Any suggestions on where to officially put it?

require "active_record/fixtures"
class Fixtures
   def insert_fixtures
     values.each do |fixture|
       allow_identity_inserts table_name, true
       @connection.execute "INSERT INTO #{@table_name} (#
{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
       allow_identity_inserts table_name, false
     end
   end

   def allow_identity_inserts(table_name, enable)
       @connection.execute "SET IDENTITY_INSERT #{table_name} #
{enable ? 'ON' : 'OFF'}" rescue nil
   end
end

The full unit test suite is now down to 10 failures and 7 errors.
I'll try to get those resolved and the adapter code cleaned up to
submit a patch in the next few days.

John

--
John R. Sheets
http://umber.sourceforge.net
http://writersforge.sourceforge.net
John S. (Guest)
on 2006-02-10 01:20
(Received via mailing list)
On Feb 1, 2006, at 8:05 AM, John S. wrote:

> Hi,
>
> I've been trying to update Will Sobel's sybase-ctlib adapter to
> pass unit tests on Rails 1.0.  It's been a slow, sloggy process for
> me so far, as I've been learning Ruby, Rails, and Sybase
> administration all in one go.  (c:  It's been a saving grace to
> have a good starting point (thanks Will!).

Finally got it passing all unit tests.  The patch and list of caveats
are in the ticket:

   http://dev.rubyonrails.org/ticket/3765

I'd be grateful to hear any feedback on the implementation, local
testing results, etc.

John

--
John R. Sheets
http://umber.sourceforge.net
http://writersforge.sourceforge.net
This topic is locked and can not be replied to.