the query string itself is attached to the URL object; you should  
modify your patch so that everything happens right within  
create_connect_args().  I see that the Firebird module is picking  
them up in the dialect constructor too, but i think its using them  
for some module-level parameters that are distinct from the dbapi  
connect() function.

it also would be better if it were done generically; i.e. anything in  
the query string gets passed straight through, so we dont have to  
constantly update all the DB modules to match the latest options  
available on every DBAPI.

one key issue involves if the query string parts should be sent as  
strings, or eval()ed to produce a wider variety of python types.     
probably each DBAPI module should make this decision individually,  
and maybe thats a place where certain specific connection parameters  
that need to be eval()'ed or converted to int or whatever might be  
hardcoded.

anyway ive just been waiting for someone to submit a patch for this  
one (i.e. for all the DBs..), its pretty easy.  it would be even  
easiest if we just did it like this to start, i.e. mysql's dialect  
just said:

     def create_connect_args(self, url):
         opts = url.translate_connect_args(['host', 'db', 'user',  
'passwd', 'port'])
        opts.update(url.query)
         return [[], opts]

also, if its true that Turbogears allows only a connection URL and  
does not allow any additional **kwargs (as the creator function would  
be one of those), i find that to be rigid on Turbogears' part.

On Jul 24, 2006, at 11:35 AM, Arnar Birgisson wrote:

> Hi there,
>
> Is there a standard way to pass extra arguments to the underlying
> DB-API's connect(..) function via the URL?
>
> For example, MySQLdb's connect takes a parameter called init_command.
> I need this to set the MySQL driver to return UTF-8 encoded strings
> correctly. The SA way of defining a custom creator function and a
> user-provided Pool class does not fit very well to my TurboGears
> project (to say the least).
>
> The dialect's constructor receives the url query-part as a dict. I
> modified the MySQL dialect a little so that it picks 'init_command'
> out of the list and stores them in a member variable. I then use these
> in "create_connect_args".
>
> The start of MySQLDialect then looks like this:
>
> class MySQLDialect(ansisql.ANSIDialect):
>     def __init__(self, module = None, **kwargs):
>         if module is None:
>             self.module = mysql
>         else:
>             self.module = module
>         dbapiargs = ('init_command',) # add more choices here
>         self.extraargs = {}
>         for arg in dbapiargs:
>             if arg in kwargs:
>                 self.extraargs[arg] = kwargs.pop(arg)
>         ansisql.ANSIDialect.__init__(self, **kwargs)
>
>     def create_connect_args(self, url):
>         opts = self.extraargs.copy()
>         opts.update(url.translate_connect_args(['host', 'db', 'user',
> 'passwd', 'port']))
>         return [[], opts]
>
>
> Then I can use an url like
> "mysql://user:[EMAIL PROTECTED]/database?init_command=set%20character%20set% 
> 20utf8".
> I know this is not the proper way of doing this, but it gets my  
> idea across.
>
> Is there any way something like this would be implemented in SA?
>
> Arnar
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys -- and earn  
> cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to