Sibylle Koczian wrote:
> Hello,
> 
> I found this in the archive:
> 
> -----------------------------------------------
> Author: Uwe Grauer <uwemailmeister /at/ googlemail D.O.T com>
> Subject: Re: [dabo-users]What is the preferred way to specify additional
> connection params?
> Posted: 2007/05/07 15:55:32
> Ed Leafe wrote:
>> On May 7, 2007, at 3:47 PM, Uwe Grauer wrote:
>>
>>> Could you give an example on how this is intended to be uses in
>>> dForm.afterInit()?
>> It isn't. It was intended to be used in a construct such as:
>>
>> ci = dabo.db.dConnectInfo(Host="foo.com", ...)
>> conn = dabo.db.dConnection(ci, charset="utf-8")
>>
>> It hasn't been integrated into cnxml files yet.
>>
>> -- Ed Leafe
> 
> So i have to overwrite dApp.getConnectionByName.
> 
> Ok, tested that kinterbasdb gets the right thing.
> But i have to test this outside of dabo to be able to tell if the
> translation works as expected.
> 
> But thanks for the change as we now are able to give the backend all
> params that we want to use.
> -----------------------------------------------------
> 
> Is this still state of the art? If yes, I think it would have to look
> like this:
> 
> def getConnectionByName(self, connName):
> """Given the name of a connection, returns the actual
> connection. Stores the connection so that multiple requests
> for the same named connection will not open multiple
> connections. If the name doesn't exist in self.dbConnectionDefs,
> then an exception is raised.
> """
>       if not self.dbConnections.has_key(connName):
>               if self.dbConnectionDefs.has_key(connName):
>                       ci = self.dbConnectionDefs[connName]
>                       # This is changed:
>                       self.dbConnections[connName] = dabo.db.dConnection(ci,
> charset="utf8")
>               try:
>                       ret = self.dbConnections[connName]
>               except KeyError:
>                       raise dException.ConnectionNotFoundException, _("No 
> connection named
> '%s' is defined") % connName
>               return ret
> 
> The base class method can't be called, because the changed line comes in
> the middle. Right? 
> 
> Sibylle
> 

You have to overwrite dApp:
#---------------------------------------------------------------------
# -*- coding: utf-8 -*-

import dabo
from dabo.dLocalize import _

class ugApp(dabo.dApp):
    def getConnectionByName(self, connName):
        """Given the name of a connection, returns the actual
        connection. Stores the connection so that multiple requests
        for the same named connection will not open multiple
        connections. If the name doesn't exist in self.dbConnectionDefs,
        then None is returned.
        """
        if not self.dbConnections.has_key(connName):
            if self.dbConnectionDefs.has_key(connName):
                ci = self.dbConnectionDefs[connName]
                if self.Charset == None:
                    self.dbConnections[connName] = dabo.db.dConnection(ci)
                else:
                    self.dbConnections[connName] =
dabo.db.dConnection(ci, charset=self.Charset)
        try:
            ret = self.dbConnections[connName]
        except KeyError:
            ret = None
        return ret

    def _getCharset(self):
        try:
            return self._charset
        except AttributeError:
            return None

    def _setCharset(self, value):
        self._charset = value

    Charset = property(_getCharset, _setCharset, None,
                       _("Connection charset to be used (string)") )

#---------------------------------------------------------------------

BTW, i tested the prerelease version of kinterbasdb:
http://www.firebirdsql.org/download/prerelease/python/
and found that UTF8 support improved.

Uwe


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to