[z3] Problems with the SQLOS 'example'

Luca Manini manini.luca at tiscali.it
Sun Feb 20 16:56:16 MET 2005


Hi, 

I'm trying to use SQLOS in order to reuse some SQLObject (PostgreSQL)
classes (not written by me) in Zope 3.

I've read the doc at http://codespeak.net/z3/sqlos/index.html but I
can not get the 'example' running, but I think I'm quite close :-)

I've asked for help on the zope-3-users ML with no result (yet?).

I took notes (see below) of everithing I've done (from a fresh start).

	Can anybody help me?
	Of course feel free to ask for more info!

=====================
My try at using SQLOS
=====================

This notes are being written as I try to use SQLOS; obiviously in
order to use SQLObject's bases classes from Zope 3.

Doc
======

	http://codespeak.net/z3/sqlos/

Parts
=====

1) Zope 3 from svn 

     svn co svn://svn.zope.org/repos/main/Zope3/tags/ZopeInterface-3.0.1

   into /usr/local/src

   Instance created in ZOPE_INSTANCE=/usr/local/var/zope_sqlos_try

2) sqlos from svn

     svn co http://codespeak.net/svn/z3/sqlos/trunk

   into $ZOPE_INSTANCE/lib/python/sqlos

3) SQLObject from Debian (unstable - version 0.6-1)

   apt-get install python2.3-sqlobject

4) psycopgda from svn

     svn co svn://svn.zope.org/repos/main/psycopgda/trunk

   into $ZOPE_INSTANCE/lib/python/psycopgda

5) following the doc at codespeak I'll make a module called
   'contacts', with a module contacts/people.py with single class
   Person (SQLOS) that implements the interface IPerson defined in
   contacts/interfaces.py.

Steps
=====

1) create a go.sh script in contacts to set up PYTHONPATH (if needed)
   and run ZOPE_INSTANCE/bin/run_zope

2) check Zope comes up ... OK

3) make contacts module

     ./__init__.py			# empty
     ./configure.zcml			# as per doc
     ./contacts-configure.zcml		# standard
     ./go.sh				# simple
     ./interfaces.py			# as per doc
     ./makefile				# just for clean
     ./people.py			# as per doc

4) cp contacts-configure.zcml in etc/packege-includes
   add ZOPE_INSTANCE to PYTHONPATH in go.sh
   ./go.sh

   BANG!!!! ::

       zope.configuration.xmlconfig.ZopeXMLConfigurationError: 
	   File "/usr/local/var/zope_sqlos_try/etc/site.zcml", line 6.2-6.55
       ZopeXMLConfigurationError: 
	   File "/usr/local/var/zope_sqlos_try/etc/
	   package-includes/contacts-configure.zcml", line 1.0-1.29
       ZopeXMLConfigurationError: File "/usr/local/
	   var/zope_sqlos_try/contacts/configure.zcml", line 24.2
       ConfigurationError: ('Unknown directive', 
	   u'http://namespaces.sqlobject.org/sqlos', u'factory')

   OK, my configure.zcml (as per doc) contains a factory statement
   (???) that comes from the sqlos namespace:: 

       <sqlos:factory
          id="Person"
          title="Person"
          description="A Simple Person"
       />

   It seems Zope 3 does not know about the namespace.

   I see that in the sqlos module there is a meta.zcml file and in
   package-includes there are many *-meta.zcml that import packages
   and include meta.zcml files.

   So let's try adding a sqlos-configure.zcml to package-includes::

     > cat ......./etc/package-includes/sqlos-configure.zcml 
     <include package="sqlos"/>

     > cat ......./etc/package-includes/sqlos-meta.zcml
     <include package="sqlos" file="meta.zcml"/>
   
   ./go.sh

   BANG!!!! ::

       zope.configuration.xmlconfig.ZopeXMLConfigurationError: 
           File "/usr/local/var/zope_sqlos_try/etc/site.zcml", line 6.2-6.55
       ZopeXMLConfigurationError: 
           File "/usr/local/var/zope_sqlos_try/etc/package-includes/
	   contacts-configure.zcml", line 1.0-1.29
       ZopeXMLConfigurationError: 
           File "/usr/local/var/zope_sqlos_try/
	   contacts/configure.zcml", line 24.2-28.10
	   ConfigurationError: ('Missing parameter:', 'component')

   OK, in  ../lib/python/sqlos/metadirectives.py I find::

       class IFactoryDirective(Interface):
	   """
	   Define a factory
	   """

	   component = GlobalObject(
	       title=u"Component to be used",
	       required=True)

   OK, adding the component seems to fix that::

       <sqlos:factory
	     id="Person"
	     title="Person"
	     description="A Simple Person"
	     component="contacts.people.Person"
	     />

   Zope comes up and I have two new 'addable types':
   SQLObjectContainer and SQLObjectPrincipalSource.  Adding any of
   them do work, but (of course) there is nothing to add into.

5) Now it is time to add a connection!

   As per docs, I add this to configure.zcml::

       <configure
	  xmlns='http://namespaces.zope.org/zope'
	  xmlns:rdb="http://namespaces.zope.org/rdb"
	  xmlns:sqlos='http://namespaces.sqlobject.org/sqlos'>

	<sqlos:connectionName name='pgsql' />

	<!-- Here you configure the dsn for a given connection -->
	<rdb:provideConnection
	 name='pgsql'
	 component='psycopgda.adapter.PsycopgAdapter'
	 dsn='dbi://zope3:123@localhost:5432/zope3'
	 />

       </configure>

   Zope 3 comes up, but no news ...

6) Define a container ....

   As per doc, interface IPersonContainer added to
   contacts/interfaces.py, implementation PersonContainer added to
   contacts/people.py, some stuff added to configure.zcml.

   ./go.sh ...

   Zope comes up, I can add a PersonContainer but the connection is
   wrong (and PostgreSQL was not even running...) so I changed the
   dsn to an existing db

      dsn='dbi://postgres://postgres@localhost/network'

   and get PostgreSQL running .... and ...

   BANG !!!

       File "/usr/local/src/ZopeInterface-3.0.1/
           src/zope/app/rdb/__init__.py", line 141, in connect
	   raise DatabaseException, str(error)
	   DatabaseException: unpack list of wrong size


   

-- 
    bye, Luca


More information about the z3 mailing list