[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using ActiveRecord to determine database structure

Karla

10/24/2006 9:10:00 AM

Hi Folks,

for a project i have to write a program that determines automatically
the stucture of a given database. This means, i have to find out which
tables a database has, which attributes those tables have, which type
those attributes have and also the table constraints.

For this purpose i wanted to use ActiveRecord because as far as i know
it is capable of doing all this things.
I did the "Rolling with Ruby on Rails" tutorial so i know that the
scaffolding mechanism can be used to determine a table's structure.
When looking into the ActiveRecord sources i found a method named
"structure_dump" in
connection_adapters/abstract/schema_statements.rb, i guess i can use
that to find out of which tables a database consists.

Since i'm very new to Ruby i have a lot of problems to implement those
things. What i already achieved is to connect to a database with
ActiveRecord like this

ActiveRecord::Base.establish_connection(
:host => "localhost" ,
:adapter => "mysql",
:database => "test" ,
:username => "user" ,
:password => "password" ,
:socket => "/var/run/mysqld/mysqld.sock"
)

My question is if somebody kindly provide me with some sort of small
example of how to determine a Database's description with ActiveRecord.
This would be very nice.

With kind regards,
Karla