A generic database adapter for Zope 2
Zope ZSQL-SQLAlchemy Integration Wrapper
SQLAlchemyDA is a generic database adapter for Zope ZSQL methods, which are an older/legacy SQL templating feature for executing relational database queries from with in a Zope to transaction context.
SQLAlchemyDA provides an implementation in the form of a Zope2 “product” which wraps z3c.sqlalchemy, so that database connections are installable as objects in the Zope2 ZMI. Such connection objects can be set up to connect to any kind of database backend supported by SQLAlchemy using a database URI, such as Postgres, MySQL, Oracle, SQLite, MS-SQL, Firebird, Informix. However, some of these database backends have not been tested with the SQLAlchemyDA, so your mileage may vary.
In addition to ZSQL support, the SQLAlchemyDA makes it possible to use the standard SQLAlchemy API within a Zope2 context and participate in Zope transactions.
However, if you do not require ZSQL support, and only wish to call ‘normal’ SQLAlchemy APIs within Zope transactions, this package adds no value. Instead, you would be better off trying out zope.sqlalchemy, as recommended in the Zope2 book chapter on relational database connectivity.
- Zope 2.10+
- SQLAlchemy >= 0.5.0 (+ database specific low-level Python drivers)
- z3c.sqlalchemy >= 1.2.0
download and install SQLAlchemy as egg or from the sources from Cheeseshop (easy_install sqlalchemy). See
download and install z3c.sqlalchemy as egg or from the sources from Cheeseshop (easy_install z3c.sqlalchemy). See
unpack the archive containing SQLAlchemyDA inside the “Products” directory of your Zope instance home.
after restarting Zope you go to the ZMI and create an instance of “SQLAlchemyDA” (as you would create some DA instance)
click on the new created SQLAlchemyDA instance within the ZMI and configure your database connection through the “Properties” tab. The connection parameter ‘dsn’ must be specified as a valid SQLAlchemy DSN like
ZSQL methods should see the new DA through the selection widget of available database adapters
NOTE: you must have the low-level Python DB drivers installed in order to access a particular database. See
Configuration of SQLAlchemyDA:
- ‘dsn’ - SQLAlchemy compliant Database Set Name (see www.sqlalchemy.org/docs)
- ‘transactional’ - uncheck this property if you are working with a non-transactional
- database like older versions of MySQL. Uncheck this property only if you see any commit() related error. Otherwise leave this property checked. Changing this property requires a Zope restart.
- ‘quoting_style’ - affects how strings are quoted in SQL. By default ‘standard’
- quotes strings correctly. Setting the value to ‘no-quote’ might solve quoting issues with some databases.
SQLAlchemyDA works as a database adapter as documented within “The Zope Book”
and can be used like any other DA together with ZSQL methods.
Tested with databases:
- Postgres 7.4, 8.0-8.2
- SQLite 3.3.X
- Oracle 10g
- MySQL is only supported for MySQL databases with transaction support. (see also z3c/sqlalchemy/README.txt)
“”” Database connection could not be opened ((ProgrammingError) (1064, You have an error in your SQL syntax near ‘COMMIT . “”“
This bug might appear with older MySQL versions when opening/closing the connections manually through the ZMI. It should not affect the functionality of SQLAlchemyDA.
SQLAlchemyDA is licensed under the Zope Public License 2.1. See LICENSE.txt.
Parts of the SQLAlchemyDA V 0.3.X development has been sponsored by Wayne Volkmuth (renovis.com).
More recent SQLAlchemy support and maintenance sponsored by ZeOmega.com.
Beta Release: If you try out this version, please provide feedback!
- Added alternative lookup API to get a handle on SAWrapper instances. To use the new lookup mechanism, see Products.SQLAlchemyDA.da.py and look for the function lookup_da. This was created to allow avoiding Zope Acquisition as a lookup mechanism, and to work around the issue that the underlying z3c.sqlalchemy getSAWrapper function is non-usable when created by the SAWrapper DA. This is because API consumers have no access to the random internally generated name (‘util_id’ attribute) under which the utility is registered…at least not without resorting to Acquisition calls.
- Tested with SQLAlchemy 0.7.6, Zope 2.13, and Python 2.7.9, and SQLite. Your mileage may vary with other databases and versions, but most likely it will run with older versions of Zope and Python as old as 2.5 (running tests requires at least Python 2.5). Newer versions of SQLAlchemy will be tested for the next release.
- Fixed LP #639597
- fixed typo in type mapping
- Fixed LP #570208
- Added a method ‘add_extra_engine_options’ to set additional engine options for SQLAlchemy.create_engine.
- Removed SOFTWARE_HOME dependency
- Requires SQLAlchemy >= 0.5.0
- fixed issue with version.txt file
- requires z3c.sqlalchemy (2.0.0 or higher)
- requires SQLAlchemy 0.4.4 or higer
- fixed some security assertions
- added “Test” tab for executing SQL queries directly
- better error handling for ZMI screens
- no longer depending on a pre-registered SQLAlchemy wrapper. SQLAlchemyDA now accepts (as any other DA) a DSN as property ‘dsn’
- DSN can be passed through the add form
- redirect directly to “Info” tab after creating an instance through the ZMI
- catching some low-level exceptions from the sqlite interface in order to make it work with SQLite
- new properties ‘transactional’ and ‘quoting_style’
- improved support for Oracle and MySQL
- SQLAlchemyDA no longer provides access to mapper related functionalities. It now acts as a DA for executing SQL statements only.
- fixed unregistration code for a wrapper (hopefully works with Zope 2.8 or higher)
- updated documentation
- connections can be closed/opened through the ZMI
- some code cleanup
- fixed a very stupid typo causing ZODB conflict errors
- first public release
- initial coding