Using variables in conn.exec (pgsql) 
Author Message
 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
  }

Quote:
}


./create_table.ruby:19:in `exec': wrong argument type nil (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

--
WBR
Korshunov Ilya



Sat, 09 Apr 2005 21:30:40 GMT  
 Using variables in conn.exec (pgsql)

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

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

K>   result = conn.exec ($res)

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

Guy Decoux



Sat, 09 Apr 2005 21:36:47 GMT  
 Using variables in conn.exec (pgsql)
???Y?? ?? 22 ?????? 2002 17:36 ts ?D:

Quote:

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

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

> K>   result = conn.exec ($res)

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

> Guy Decoux


./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

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



Sat, 09 Apr 2005 21:40:08 GMT  
 Using variables in conn.exec (pgsql)

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

 Yes, read this :-)))

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

Quote:

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

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

Quote:
>> rather than `,'

Guy Decoux


Sat, 09 Apr 2005 21:43:12 GMT  
 Using variables in conn.exec (pgsql)
???Y?? ?? 22 ?????? 2002 17:43 ts ?D:
Quote:

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

>  Yes, read this :-)))

> K> 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



Sat, 09 Apr 2005 21:44:48 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. creating argv like variable to be used by exec

2. using exec on a variable

3. using shell pipe and variables in Tcl exec command

4. using exec in windows nt exec on tcl scripts

5. using incr as a variable on a variable?

6. TCL Newbie Question: using variables to reference variables

7. Creating a new variable using an existing variable

8. Using a variable name for a variable name??

9. where is php-pgsql source code?

10. PgSQL.py / mxDateTime Question

11. PgSQL and double quotes...

12. Installing pgsql (PostgreSQL Interface) results in swig errors

 

 
Powered by phpBB® Forum Software