JRruby, Sybase JDBC and DBI - fetching column names

I have a ruby script which I run using the JRuby Interpreter. The script
connects to a Sybase database using DBI and Sybase JDBC (jTDS3.jar and
jconn3.jar)

My problem is that I have a select query that when I return the result I
change the column names. For example:

SELECT
t.TRANSACTION as ‘business_transaction’,
t.TRADE_CURRENCY as ‘currency’,
t.CURRENCY as ‘settlement_currency’
…etc…

FROM
TRADE t
…etc…

My problem is when using the examples directly from the documentation
(http://www.kitebird.com/articles/ruby-dbi.html)

sth = dbh.execute(stmt)

printf “Number of rows: %d\n”, rows.size
printf “Number of columns: %d\n”, sth.column_names.size
sth.column_info.each_with_index do |info, i|
printf “— Column %d (%s) —\n”, i, info[“name”]
end

or simply

sth = dbh.execute(stmt)

rows = sth.fetch_all
col_names = sth.column_names
sth.finish
DBI::Utils::TableFormatter.ascii(col_names, rows)

Not ALL the names come out as I set them using the ‘as’ clause in the
query. Some are the original field names and some are the names I have
specified.

For example they will list like:

— Column 0 (TRANSACTION) —
— Column 1 (TRADE_CURRENCY) —
— Column 2 (settlement_currency) —

or

TRANSACTION
TRADE_CURRENCY
settlement_currency

When testing this in Squirrel SQL Client the columns are correctly named
so is this a bug in DBI or the Sybase JDBC drivers? or am I doing
something wrong?

Any help would be greatly appreciated

I posted on:

My first guess would be that this is a problem in DBI. I’m not sure
who’s maintaining DBI right now, though, so I’m not sure who you’d
talk to. Have you tried their mailing list, if they have one? Or their
bug tracker?

It definitely doesn’t seem to be a JRuby-specific issue. Maybe you can
dig into the DBI code a little and see if you can find it yourself?

On Thu, Oct 8, 2009 at 6:43 PM, Carl B. removed_email_address[email protected]
wrote:

t.TRANSACTION as ‘business_transaction’,

sth = dbh.execute(stmt)
For example they will list like:


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs