Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > read tables from SQL code

Thread Tools

read tables from SQL code

Bulhac Mihai
Posts: n/a
i have a SQL code like this one:

SELECT Select_List
FROM Table_List
[WHERE Conditions]
[GROUP BY Column_List]
[UNION Clause]
[HAVING Conditions]
[ORDER BY Column_List]
[INTO Clause | TO Clause ]

can i read/save with ruby the columns involved in that SQL select?
Posted via

Reply With Quote
Sharon Rosner
Posts: n/a
> can i read/save with ruby the columns involved in that SQL select?

If you use Sequel you can retrieve the columns for arbitrary SQL like

require 'sequel/mysql' # assuming you're using MySQL
DB = Sequel('mysql://localhost/mydb')
DB['select * from items'].columns #=> [:id, :name, ...]

But if you're already using Sequel why not construct your queries
using Ruby instead of SQL, e.g.:

dataset = DB.query do
from :items
where {:name =~ /^abc/ && rice < 100}
order_by :name
p dataset.columns
dataset.each {|r| p r}

You can find more information about Sequel here:

And you can also get help on Sequel-talk:


Reply With Quote
John Joyce
Posts: n/a
Ruby DBI will let you do exact SQL, like DBI in other languages.

ActiveRecord can do some of that select statement, but some of it no.
ActiveRecord does have the ability to execute direct SQL statements

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
How to get database metadata information (i.e. existing tables and columns in tables) Chris Brat Python 5 08-22-2006 05:25 PM
Tables within tables Otuatail HTML 7 08-02-2004 04:42 AM
Text after 2 tables actually appears between 2 tables ! Peter Bassett HTML 3 08-15-2003 06:46 PM