[Zope3-dev] Re: Changing zope.app.rdb to better support sqlos
Brian Sutherland
jinty at web.de
Mon Nov 7 08:52:51 EST 2005
On Thu, Nov 03, 2005 at 12:48:40PM +0100, Brian Sutherland wrote:
> On Thu, Nov 03, 2005 at 12:08:09PM +0100, Andres Freund wrote:
> > 4. Every database adapter has an own interface which inherits from the
> > zope one. This would enable the use of normal zope adaption which i
> > would prefer, but again every adapter which should be used together
> > with sqlos has to be changed.
>
> This is also my slightly preferred option. It could work for mysql as
> follows (/me waves hands rapidly):
>
> 1. zope.app.rdb define IMySQLZopeConnection which extends
> IZopeConnection. IMySQLZopeConnection is just a marker interface.
> 2. in sqlos register an adapter from IMySQLZopeConnection to sqlos to the
> IZopeSQLConnection.
> 3. in mysqldbda provide an implementation of IMySQLZopeConnection, i.e.
> returns objects implementing IMySQLZopeConnection in place of
> IZopeConnection
So, this is the code I will commit to the mysqldbda (similar code may
eventually make it's way into the other database adapters):
Index: ../mysqldbda/adapter.py
===================================================================
--- ../mysqldbda/adapter.py (revision 39859)
+++ ../mysqldbda/adapter.py (working copy)
@@ -16,11 +16,17 @@
$Id: Adapter.py,v 1.1 2004/10/10 mriya3
"""
+from zope.interface import directlyProvides
+from zope.app.rdb.interfaces import IZopeConnection
from zope.app.rdb import ZopeDatabaseAdapter, parseDSN
import MySQLdb
+class IMySQLZopeConnection(IZopeConnection):
+ """A marker interface stating that this connection uses the MySQL SQL."""
+
+
class MySQLStringConverter:
def __init__(self, encoding):
@@ -66,3 +72,8 @@
def identity(self, x):
return x
+
+ def __call__(self):
+ connection = ZopeDatabaseAdapter.__call__(self)
+ directlyProvides(connection, IMySQLZopeConnection)
+ return connection
And how it is used in sqlos:
Index: sqlos/src/sqlos/configure.zcml
===================================================================
--- sqlos/src/sqlos/configure.zcml (revision 19326)
+++ sqlos/src/sqlos/configure.zcml (working copy)
@@ -1,5 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="sqlos">
<include file="permissions.zcml" />
@@ -145,6 +146,15 @@
/>
-->
+ <configure zcml:condition="installed mysqldbda">
+ <adapter
+ provides=".interfaces.IZopeSQLConnection"
+ for="mysqldbda.adapter.IMySQLZopeConnection"
+ permission="zope.Public"
+ factory=".adapter.MySQLAdapter"
+ />
+ </configure>
+
<adapter
provides="zope.app.container.interfaces.INameChooser"
for="sqlos.interfaces.container.ISQLObjectContainer"
--
Brian Sutherland
Metropolis - "it's the first movie with a robot. And she's a woman.
And she's EVIL!!"
More information about the Zope3-dev
mailing list