[egenix-users] Zope, MySQL, UTF-8

Charlie Clark charlie at egenix.com
Mon Feb 14 16:55:29 CET 2005


On 2005-02-14 at 16:37:27 [+0100], Jan Stiller 
<Jan.Stiller at hagen-partner.de> wrote:
> Hi Charlie
> 
> asking for help obviously liberated my brain ;o)
> 
> 1.
> This
> 
> SET CHARACTER SET utf8
> <dtml-var sql_delimiter>
> update test
> set textfeld = <dtml-sqlvar text type=string>
> where tid = 1
> 
> seems to work... and Zope (or whoever) seems to remember this between
> different calls (I commented set char... out).
> 
> Is there any 'official' place to set the character set?
> 
> 
> 2.
> Do you have a small example for an external method? (I need some batch
> processing too)

The external method just receives an mxODBCZopeDA connection object and 
calls its .execute(code, (paras)) method as if it were written in Python. I 
posted an example on the Zope-DB list last year.

ah here it is:

3) Use an external Method. This has the advantage of being much finer 
grained 
conrtol than allowing all PythonScripts to do something but done properly 
is 
nearly as flexible.

Create a file in ~/Extensions say ODBC_SQL.py

This is essentially needs only one function:

def callSQL(connectionObject, statement):
	conn = connectionObject.database_connection()
	return conn.execute(statement)

Create an external method say SQL which points to callSQL in ODBC_SQL

You can then call this method from any PythonScript and simply pass it the 
connection and statement you want to execute.

In your case the PythonScript needs only to be modified slightly, depending 
on what you want to.

statement = """select [Building ID] from [Buildings]
 where [Building Name] = ?""", building)[1]
columns, results = context.SQL(container.crc_db, statement)

Hope that helps

Charlie



More information about the egenix-users mailing list