Damjan Rems wrote:


Thanks for your guidance so far. There is some progress as below:

> my = Mysql.real_connect("server", "username", "password", "cnms")
> db = SQLite3::Database.open( 'simo/db/development.sqlite3' ) ##second db
> stmt = db.prepare("insert into usages ( device_id, bytes_sourced ) 
> values( ?, ? )" )
> myresult = my.query("SELECT device_id, bytes_sourced FROM odma_unit")
> myresult.each_hash do |row|
>   row.each do |key, value|
>     stmt.execute(key, value)
>   end
> end
> 
The above code does the following:
device_id             00:80:c6:e8:c6:ae
bytes_sourced         510807

So, its taking a key and value and adding them in row after row until 
its done. Something is right but something is not working.

> But maybe:
>  myresult.each do |row|
>    stmt.execute(row['device_id'], row['bytes_sourced')
>  end
> 
the above code gives the error:

dbadd.rb:38:in `[]': can't convert String into Integer (TypeError)

The first statement seems to have it almost right. What I am trying to 
do is get the device_id and the bytes_sourced into the same row. So, to 
simplify, each device_id has a bytes_sourced. Each of these will make a 
row.

I am sure I could rewrite this some other way. But, I know a bit about 
MySQL and I am trying to understand Ruby and Sqlite3 as well. In time I 
plan to get this app in a better format, but for now I just want to get 
it working until I have grown in knowledge.

Thanks for the help so far.

Gigg
-- 
Posted via http://www.ruby-forum.com/.