JRruby,Sybase JDBC和DBI-使用AS子句问题获取列名 [英] JRruby, Sybase JDBC and DBI - fetching column name with the AS clause issue

查看:121
本文介绍了JRruby,Sybase JDBC和DBI-使用AS子句问题获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用JRuby Interpreter运行的ruby脚本. 该脚本使用DBI和Sybase JDBC(jTDS3.jar和jconn3.jar)连接到Sybase数据库

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 alters the column names of table. 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

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

或者简单地

sth = dbh.execute(stmt)

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

不是 ALL ,这些名称是在查询中使用"as"子句设置它们时出现的.有些是原始字段名称,有些是我指定的名称.

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) ---

TRANSACTION
TRADE_CURRENCY
settlement_currency

在Squirrel SQL Client中进行测试时,列的名称正确,所以这是DBI或Sybase JDBC驱动程序中的错误吗?还是我做错了什么?

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?

任何帮助将不胜感激

推荐答案

我可以确认它是Sybase驱动程序.使用以下版本的jTDS(v1.2.5) http://jtds.sourceforge.net/我可以获得在查询中正确定义的所有列名称,并且可以确认原来的问题不是DBI

I can confirm it is the Sybase drivers. Using the jTDS (v1.2.5) from http://jtds.sourceforge.net/ I can get all the column names correctly defined in my query and can confirm that the original issue is NOT DBI

如果遵循此方法的任何人想知道我如何让jtds在jRuby下与DBI一起工作,请看一下我以前的

If anyone who is following this wondered how I got jtds working with DBI under jRuby please take a look at one of my former questions - it did take some time - and DBI is a little funny when specifying the URL use

dbi:Jdbc:jtds:sybase://<host>:<port>/<db>

请注意Jdbc的大写字母J

Please note the capital J for Jdbc

我希望这可以节省很多时间;-)

I hope this saves someone a lot of time ;-)

这篇关于JRruby,Sybase JDBC和DBI-使用AS子句问题获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆