Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

read tables from SQL code

 
 
Bulhac Mihai
Guest
Posts: n/a
 
      10-20-2007
hi,
i have a SQL code like this one:

SELECT Select_List
FROM Table_List
[WITH (BUFFERING = lExpr)]
[WHERE Conditions]
[GROUP BY Column_List]
[UNION Clause]
[HAVING Conditions]
[ORDER BY Column_List]
[INTO Clause | TO Clause ]
[Additional_Display_Options]

can i read/save with ruby the columns involved in that SQL select?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Sharon Rosner
Guest
Posts: n/a
 
      10-20-2007
> 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
this:

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
end
p dataset.columns
dataset.each {|r| p r}

You can find more information about Sequel here:

http://code.google.com/p/ruby-sequel

And you can also get help on Sequel-talk:

http://groups.google.com/group/sequel-talk

best
Sharon


 
Reply With Quote
 
 
 
 
John Joyce
Guest
Posts: n/a
 
      10-20-2007
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
though.

 
Reply With Quote
 
 
 
Reply

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



Advertisments