cannot require 'postgres' from cgi 
Author Message
 cannot require 'postgres' from cgi

i have a cgi program which works fine standalone and from a browser,
by adding the line
        require 'postgres'

it continues to function from the command line, but browser gives
'doccument contains no data' error...

the postgress module is installed and works find on the machine.  the
web server (netforge) is running as me so the user is the same in both
cases, i have printed out the value of $: in both command line and
browser and they are the same, $SAFE is 0 is both cases... i am
mistified!!

i am not DOING anything with the module, only requiring it!

any help appreciated.

-ara



Tue, 09 Nov 2004 07:33:08 GMT  
 cannot require 'postgres' from cgi

Quote:

> Why aren't you using DBI?

just one more thing to learn - haven't had time.  plus i'd read some things
about speed issues and hadn't had time to investigate.  what are you opinions
of it?

turns out (this took me a LONG time to determine) that the postgres.so lib has
dependancies on other libs which are not to be found in the LD_LIBRARY_PATH
(empty) of the default cgi environment but that WERE found in my own
LD_LIBRARY_PATH.

it's a little troublesome that 'require' is unable to throw for this sort of
error...

anyhow, i'm unsure of where to go from here

  - install postgress libs in /usr/lib
  - modify ENV of running cgi
  - staticaly link the postgres lib

  ???

any opinions on this?

-a

--

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328

 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================



Tue, 09 Nov 2004 14:00:24 GMT  
 cannot require 'postgres' from cgi

Quote:
> > Why aren't you using DBI?

> just one more thing to learn - haven't had time.  plus i'd read some
> things about speed issues and hadn't had time to investigate.  what
> are you opinions of it?

Use DBI 0.0.14 or later and the speed problems should be nil.  I use
DBI for tons of operations and as of yesterday, pumped over 30M rows
through it w/o a hitch.  :~)  Need a quick example?

dbh = DBI.connect('dbi:postgres:dbname:hostname','user','pass')
sql = 'SELECT or, some, other, sql, here FROM my_table AS mt WHERE mt.val1 = ? mt.val2 = ?'
dbh.select_all(sql, val1, val2) do |row|
  # do stuff w/ your row (array coresponding to the columns)
end
dbh.disconnect

Don't forget you can also use transactions:

dbh.transaction do |t|
  # t is just a normal DBH object
  t.do('INSERT INTO foo (val1, val2) VALUES (?,?)', val1, val2)
end

and statement handles:

sql = 'INSERT INTO foo (val1, val2) VALUES (?,?)'
dbh.prepare(sql) do |sth|
  # t is just a normal DBH object
  sth.execute(val1, val2)
end

statement handles are nice and faster for repeat operations.  You can
also go sth = dbh.prepare(sql): it's just a style preference.

Quote:
> turns out (this took me a LONG time to determine) that the
> postgres.so lib has dependancies on other libs which are not to be
> found in the LD_LIBRARY_PATH (empty) of the default cgi environment
> but that WERE found in my own LD_LIBRARY_PATH.

> it's a little troublesome that 'require' is unable to throw for this
> sort of error...

> anyhow, i'm unsure of where to go from here

>   - install postgress libs in /usr/lib
>   - modify ENV of running cgi
>   - staticaly link the postgres lib

>   ???

> any opinions on this?

See if you can set LD_RUN_PATH and recompile your postgres libs, then
you won't have to worry about LD_LIBRARY_PATH in the future.
Something tells me you're on Solaris, yes?  If so, I'm sorry. :~) That
OS has all kinds of strange SO problems from my experience.  Not
impossible to overcome, just a PITA.

--
Sean Chittenden



Tue, 09 Nov 2004 14:00:24 GMT  
 cannot require 'postgres' from cgi

Quote:
ahoward writes:

 > turns out (this took me a LONG time to determine) that the postgres.so lib has
 > dependancies on other libs which are not to be found in the LD_LIBRARY_PATH
 > (empty) of the default cgi environment but that WERE found in my own
 > LD_LIBRARY_PATH.

I had the same problem. Solaris, right? Rather than mucking with
LD_LIBRARY_PATH (which is an egregious hack anyway), I figured out how
to set the RUN_PATH during compilation. For ruby itself, there's an
$LDFLAGS global in ext/extmk.rb around line 555 that you can add
"-R/usr/local/lib" to. The Postgres module should have something
similar, though I've not compiled it.

Incidentally, it was kind of annoying that Ruby wouldn't take LDFLAGS
from my environment like every other package does. Usually one of the
following does the trick on Solaris:

make LDFLAGS=-R/usr/local/lib

LDFLAGS=-R/usr/local/lib ./configure ......

But with ruby I had to grovel through the build scripts looking for
the right variable.

 >
 > it's a little troublesome that 'require' is unable to throw for this sort of
 > error...

It's not ruby's fault ;). It's the OS's runtime linker.

Dan
--

www.nodewarrior.org
ignorami: n:
The art of folding problem users into representational shapes.



Tue, 09 Nov 2004 21:38:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ODBC import - 'Cannot load file driver.'

2. Cannot run 'irb --readline'

3. cannot open include file 'param.inc'

4. g95: installation problem, cannot exec 'f951': No such file or directory

5. 'StdCLib required'

6. require 'tk' causes segfault later

7. 'require' search path

8. 'require' error (ver/path)

9. require 'etc'

10. require 'aDir'

11. Problem with require 'nqxml/treeparser'

12. require '../foo/bar'

 

 
Powered by phpBB® Forum Software