Using variables in conn.exec (pgsql)

I want to create complex sql query for pgsql.

Following construction produce an error :

conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname)
open(".ftppasswd") { |file|
file.each_line { |line|
next if /^\s*#/ =~ line
username, password, = line.chomp.split(’:’)
res="CREATE TABLE ", username, " (id SERIAL, a char)"
result = conn.exec ($res)
^^^^^^^line 19
}
}

[kosha@kosha ruby_test]$ ./create_table.ruby
./create_table.ruby:19:in exec': wrong argument type nil (expected String) (TypeError) from ./create_table.ruby:19 from ./create_table.ruby:11:ineach_line’
from ./create_table.ruby:11
from ./create_table.ruby:10:in `open’
from ./create_table.ruby:10
[kosha@kosha rubye sample]$

···


WBR
Korshunov Ilya

   res="CREATE TABLE ", username, " (id SERIAL, a char)"

Well, here `res" will be an Array not a String. Probably you want `+' rather
than `,'

  result = conn.exec ($res)

You use `$res', which is not initialized, rather than `res'

Guy Decoux

В сообщении от 22 Октябрь 2002 17:36 ts написал:

res="CREATE TABLE “, username, " (id SERIAL, a char)”

Well, here res" will be an Array not a String. Probably you want +’
rather than `,’

result = conn.exec ($res)

You use $res', which is not initialized, rather than res’

Guy Decoux

[kosha@kosha rubye sample]$ ./create_table.ruby
./create_table.ruby:19:in exec': wrong argument type Array (expected String) (TypeError) from ./create_table.ruby:19 from ./create_table.ruby:11:in each_line’
from ./create_table.ruby:11
from ./create_table.ruby:10:in `open’
from ./create_table.ruby:10
[kosha@kosha rubye sample]$

Another error)…i think that res must be string but not array…or i
mistaking ?

···


WBR
Korshunov Ilya

Another error).....i think that res must be string but not array...or i
mistaking ?

Yes, read this :-)))

res="CREATE TABLE ", username, " (id SERIAL, a char)"

Well, here `res" will be an Array not a String. Probably you want `+'

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

rather than `,'

Guy Decoux

В сообщении от 22 Октябрь 2002 17:43 ts написал:

Another error)…i think that res must be string but not array…or i
mistaking ?

Yes, read this :-)))

res="CREATE TABLE “, username, " (id SERIAL, a char)”

Well, here res" will be an Array not a String. Probably you want +’

     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

rather than `,’

ooops…
thnx)

···


WBR
Korshunov Ilya