Re: [Zope-DB] Using psycopg directly in Zope Python script

2005-07-03 Thread Dieter Maurer
Jørgen Frøjk Kjærsgaard wrote at 2005-7-1 23:28 +0200:
I need to be able to access a Postgresql database directly from Zope 
Python scripts (Z SQL Methods is not an option as the SQL code occurs in 
modules that must be re-usable in a non-Zope context).
 ...
import psycopg
dbcon = psycopg.connect('host=%s dbname=%s user=%s' % ('dbhost', 
'dbname', 'username'))

You should *NOT* do this because you move outside of Zope's
transaction handling.

Fetch the connection from the DA. It looks somehow like:

  db = DA() # low level connection object
  db._register() # register with Zope's transaction system
  conn = db.db # this is the psycopg connection

Pass the conn into your code.
  
 ...
When run outside Zope, it opens a connection as expected. When run in 
Zope, however, I get thrown out - the browser asks me to enter my user 
name and password again. I get no error message!

Cancel the login dialog and you will get the error message :-)

Does Zope somehow create a restricted environment

PythonScripts are a restricted environment where import is
restricted as well as access to attributes.

-- 
Dieter
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: [Zope-DB] Using psycopg directly in Zope Python script

2005-07-01 Thread Andreas Jung



--On 1. Juli 2005 23:28:51 +0200 Jørgen Frøjk Kjærsgaard 
[EMAIL PROTECTED] wrote:





Does Zope somehow create a restricted environment where opening a
database connection is impossible? Is there a way to bypass that
restriction?



That's a misuse of PythonScripts. They are not designed to handle such 
tasks. Use an external method or write a Zope product instead.


-aj

pgpo4O6vTMNR3.pgp
Description: PGP signature
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db