ResultSetMetaData


#1

dose Ruby or ActiveRecord have the Java/JDBC equivalent for retrieving
ResultSet meta data…

PreparedStatement statement = null;
try
{
statement = connection.prepareStatement(“select * from some_table”);

ResultSet rs = null;
try
{
rs = statement.executeQuery();
ResultSetMetaData rsMetaData = rs.getMetaData();
int columnCount = rsMetaData.getColumnCount();

more stuff...

#2

Hi Barinek,

On Wed, Apr 19, 2006 at 11:56:23PM +0900, barinek barinek wrote:

{
rs = statement.executeQuery();
ResultSetMetaData rsMetaData = rs.getMetaData();
int columnCount = rsMetaData.getColumnCount();

more stuff...
Hmmm... you can use ActiveRecord::Base.columns to get a list of

ActiveRecord::ConnectionAdapters::Column objects, like this:

MyModel.columns
# => [#<ActiveRecord::ConnectionAdapters::Column:0xb749b798 

@limit=255,
@type=:string, @name=“some_field_name”, @default=nil>, …]

If you want metadata for random SQL queries (from ActiveRecord), I don’t
think you can get it…

If you really want to query the database and retrieve meta data, you 

can
always use Ruby’s DBI (see http://ruby-dbi.rubyforge.org/). You have an
explanation on meta data retrieving on “Using the Ruby DBI Module”, at
http://www.kitebird.com/articles/ruby-dbi.html#TOC_9

HTH,