[Zope] How do I use a Z Oracle Connection in a script?

J. Cone jcone@g8labs.com
Mon, 16 Jul 2001 20:30:16 +0100


You are correct that the ZOracleDA object is a function object, although I
cannot see from reading the source in either db.py or ZSQLMethods/SQL.py or
Shared/DC/ZRDB/TM.py, where the object function is declared.
(Oracle_database_connection is the name of something in the same folder, so
I hope it is an instance of a class.  It may come to show that I don't
really understand OO)

My attempt is now:
  db0=context.Oracle_database_connection
  db=db0()

  c=db.cursor
and my error is now:
  - being prompted for a username and password
  - the administrator's account and password won't do
  - after three attempts or cancel, whichever happens first:
      Unauthorized
      ...
      File
/usr/local/zope/Zope-2.3.3-src/lib/python/Products/PythonScripts/PythonScrip
t.py, line 336, in _exec
        (Object: save_profile)
        (Info: ({'script': <PythonScript instance at 4086a3d0>, 'context':
<r instance at 408b6ca8>, 'container': <Folder instance at 408684c0>, '_':
<TemplateDict object at 408f7a58>, 'traverse_subpath': []}, (),
{'newProfile': '\000\000\000\010\000\000<snip>\033', 'acctId': 56091}, None))
        File Script (Python), line 5, in save_profile
      ...
      Unauthorized: cursor

I have tried:
  - ticking every box in the Oracle connection
  - ticking every box in the Python Script
  - creating this __init__.py, which seems to be compiled:
      # Global module assertions for Python scripts
      from Products.PythonScripts.Utility import allow_module

      allow_module('ZOracleDA')
      allow_module('Shared.DC')
      allow_module('DCOracle2')
  - I have not done all of these simultaneously; only one-at-a-time

Suggestions welcome :-)

At 20:37 16/07/01 +0200, Dieter Maurer wrote:
>J. Cone writes:
> > I am sorry to be so ignorant, but your second suggestion defeats me, so
far.
>Sorry to have caused confusion.
>Apparently, I do that sometimes...
>
> >   db0=Shared.DC.ZRDB.Connection
> >   c=db0.cursor
>When I said, that a Zope Database Adapter instance is
>a "Shared.DC.ZRDB.Connection.Connection" instance,
>it did not mean, that you should access it this way.
>
>I wanted to give you a hint, where to look for the sources.
>Looking at the sources (the available methods) gives
>you a feeling how to use it.
> > 
> > which get me the errors:
> > 
> >   Error Type: NameError
> >   Error Value: Shared
>"Shared" is a Python package. You must import it, before
>you can use it. As said above, you do not use it for your
>current problem, but if you need to, you would do something
>like:
>
>	from Shared.DC.ZRDB.Connection import Connection
>
>
>I do not have the DCOracle sources here (at home),
>therefore the following is only right in principle.
>You will need to look at the sources to find out the details.
>
>   Assume you are in an external method, and "da" already contains
>   a Z OracleDA instance.
>   You call it, to get the lower level wrapper:
>
>       db= da()
>
>   This "db" object has attributes that represent the
>   low level DB-API connection and a cursor for it.
>
>   Maybe the attributes are "cursor" (or "Cursor")
>   and "connection" (or "Connection" or "Conn" or ...).
>
>   Look at the sources in "Products/ZOracleDA/db.py"!
>
>  
>
>Dieter
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>
>