[Zope3-checkins] CVS: Products3/informixDA - Adapter.py:1.1 __init__.py:1.1 configure.zcml:1.1

Christian Theune ct@gocept.com
Thu, 12 Dec 2002 08:24:16 -0500


Update of /cvs-repository/Products3/informixDA
In directory cvs.zope.org:/tmp/cvs-serv4450/informixDA

Added Files:
	Adapter.py __init__.py configure.zcml 
Log Message:
initial checkin for the "database adapter collection"

those are initial drafts. The mysql adapter is tested and able to connect and query
as well as the sapdb. Postgres has already been there.

There will be a lot of issues with converting custom data types into
the zopish ones (see BLOB/CLOB...).

The other database adapters aren't tested anyway, but probably work,
as it has mostly been an "edit and replace" work. 

(Is that a sign of refactoring?)


=== Added File Products3/informixDA/Adapter.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Informix database adapter.

$Id: Adapter.py,v 1.1 2002/12/12 13:24:14 ctheune Exp $
"""

import sapdbapi

from Zope.App.RDB.ZopeDatabaseAdapter import \
    ZopeDatabaseAdapter, parseDSN, identity

class sapdbAdapter(ZopeDatabaseAdapter):
    """A sapdb adapter for Zope3"""

    __implements__ = ZopeDatabaseAdapter.__implements__

    def _connection_factory(self):
        """Create a sapdb DBI connection based on the DSN"""
        conn_info = parseDSN(self.dsn)
        print "connecting sapdb ..."
        print "connecting with ", conn_info
        return sapdbapi.connect(conn_info['username'],conn_info['password'],
                            conn_info['dbname'], host=conn_info['host'])

    # IDBITypeInfo

    def getConverter(self, typechar):
        print "type", typechar
        return convertLongReader
        if converter_mapping.has_key(typechar):
            return converter_mapping[typechar]
        else:
            return identity


# Converters

def convertLongReader(data):
    # Converts a BLOB into a string. 
    # XXX Reads *all* data currently.
    if type(data) is sapdb.SapDB_LongReader:
        print data()
        return data()
    else:
        print "asdf", data
        if data:
            print unicode(data,"utf-8")
        return data

converter_mapping = {
    "Char Binary": convertLongReader }



=== Added File Products3/informixDA/__init__.py ===
# make this a python package



=== Added File Products3/informixDA/configure.zcml ===
<zopeConfigure
    xmlns='http://namespaces.zope.org/zope'>

    <content class=".Adapter.informixAdapter">
        <factory id="informixDA"
                permission="Zope.Public" />
        <require permission="Zope.Public"
                interface="Zope.App.RDB.IZopeDatabaseAdapter." />
    </content>

 <include package=".browser" />
 </zopeConfigure>