# Sybase ctlib Adapter

**URL:** <https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729>\
**Category:** Rails\
**Created:** [February 1, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729 "2006-02-01T15:05:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 1, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/1 "2006-02-01T15:05:21Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 1, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/2 "2006-02-01T18:00:34Z")

</div>

On 2/1/06, John S. [removed\_email\_address@domain.invalid](mailto: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](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

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 1, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/3 "2006-02-01T20:41:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 2, 2006, 1:51am UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/4 "2006-02-02T01:51:54Z")

</div>

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](http://www.sybase.com/linuxpromo)

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

[http://www.sybase.com/ase\_1252devel](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://umber.sourceforge.net)  
[http://writersforge.sourceforge.net](http://writersforge.sourceforge.net)

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 2, 2006, 2:34am UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/5 "2006-02-02T02:34:15Z")

</div>

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://umber.sourceforge.net)  
[http://writersforge.sourceforge.net](http://writersforge.sourceforge.net)

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 10, 2006, 12:20am UTC](https://www.ruby-forum.com/t/sybase-ctlib-adapter/99729/6 "2006-02-10T00:20:20Z")

</div>

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](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://umber.sourceforge.net)  
[http://writersforge.sourceforge.net](http://writersforge.sourceforge.net)
