Note that there are some explanatory texts on larger screens.

plurals
  1. POJRruby, Sybase JDBC and DBI - fetching column name with the AS clause issue
    text
    copied!<p>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)</p> <p>My problem is that I have a select query that alters the column names of table. For example:</p> <pre><code>SELECT t.TRANSACTION as 'business_transaction', t.TRADE_CURRENCY as 'currency', t.CURRENCY as 'settlement_currency' ...etc... FROM TRADE t ...etc... </code></pre> <p>My problem is when using the examples directly from the <a href="http://www.kitebird.com/articles/ruby-dbi.html" rel="nofollow noreferrer">documentation</a> </p> <pre><code>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 </code></pre> <p>or simply</p> <pre><code>sth = dbh.execute(stmt) rows = sth.fetch_all col_names = sth.column_names sth.finish DBI::Utils::TableFormatter.ascii(col_names, rows) </code></pre> <p>Not <strong>ALL</strong> 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.</p> <p>For example they will list like:</p> <pre><code>--- Column 0 (TRANSACTION) --- --- Column 1 (TRADE_CURRENCY) --- --- Column 2 (settlement_currency) --- </code></pre> <p>or </p> <pre><code>TRANSACTION TRADE_CURRENCY settlement_currency </code></pre> <p>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?</p> <p>Any help would be greatly appreciated </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload