简体   繁体   中英

read a content from a file and store it in database tables in ruby

I am having some content in file. I already read the specific needed content and store it in one array and variables

Now i need to pass those value of the array and variable to the created table in database

Please help me to do this.

con = PG.connect :dbname => 'user1', :user => 'user1'
puts con.server_version
con.exec "SELECT exists(select schema_name FROM information_schema.schemata WHERE schema_name = 'testing');"
con.exec "set search_path TO testing;"
con.exec "create table table1(name varchar());"

Now lets say i am having the below value,

a="someone"

How do i insert that value to the table. Thanks in advance.

我们必须解析这样的值,

con.exec "insert into xox values('#{a}');"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM