Forum: Ruby ResultSetMetaData

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1ca59ebae43d3490fbcabbe44c3035a5?d=identicon&s=25 Michael Barinek (barinek)
on 2006-04-19 16:56
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...
04bd97396a23bebf19887fd041e15123?d=identicon&s=25 Esteban Manchado =?iso-8859-1?Q?Vel=E1zquez?= (Guest)
on 2006-04-20 10:14
(Received via mailing list)
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,
This topic is locked and can not be replied to.