Personal tools
You are here: Home Downloads Tutorials Python Creating a DataBase product for ZOPE and MySQL
nrcfoss logo aukbc cdac iit mumbai iit madras ow2 iosn flosscc

Creating a DataBase product for ZOPE and MySQL

This article describes how you can create a MySQL connection for ZOPE by using python scripts, instead of using ZMySQLDA(the adapter for ZOPE)

Hope   you may know the   "egg"  installation  by using  your python (here its  ZOPE's  Python )


Just untar/extract your MySQLDA connector tar/zip file.

Then using your ZOPE instance's python you can install it..

~/ZOPE_instance/Python_Dir/bin/python  install   which  will  install   the  DB  connector  as a shared object  in your    site-packages  dir  of  your  ZOPE server's Python folder



Then  do  read  following  story...



Inside  your   ZOPE's   Product folder ==>  create a  folder "AllowModule" 


Then add the following declarations  to the file inside that folder

zope/lib/python/Products/AllowModule/   file


from AccessControl import allow_module, allow_class, allow_type  # 1

from AccessControl import ModuleSecurityInfo, ClassSecurityInfo    # 2


from MySQLdb import  __all__  # 3

from MySQLdb.connections import Connection #4

from MySQLdb.cursors import Cursor,  DictCursor, BaseCursor #5


ModuleSecurityInfo("MySQLdb").declarePublic('__all__')  #6

ModuleSecurityInfo('_mysqldb').declarePublic('__all__')  #7

ModuleSecurityInfo('MySQLdb.connections').declarePublic('Connection') # 8


allow_module('MySQLdb.connections') #9

allow_class('Connection') #10



ModuleSecurityInfo('MySQLdb.cursors').declarePublic('Cursor','BaseCursor','DictCursor') #11

allow_module('MySQLdb.cursors')  #12

allow_module(Cursor)  #13

allow_module(BaseCursor)  #14

allow_module(DictCursor)  #15

#make sure to restart your ZopeServer

# Now You can use  MySQLdb Library in your python code as follows



testing    add  a  Script(Python)  from  ZMI


add the   python snippets  there



from  MySQLdb.connections import Connection

from MySQLdb.cursors  import  DictCursor


conn = Connection(user='mycompany',  passwd='mycompany',db='mycompany',host='localhost')


curs = DictCursor(conn)


curs.execute("""select * from CUSTOMERS;""")


test = curs.fetchone()






print test


return printed

Document Actions