[SQL-CVS] r3522 - in SQLObject/trunk: docs sqlobject/postgres sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2008-07-23 14:20:49
|
Author: phd Date: 2008-07-23 08:20:47 -0600 (Wed, 23 Jul 2008) New Revision: 3522 Added: SQLObject/trunk/sqlobject/tests/test_schema.py Modified: SQLObject/trunk/docs/SQLObject.txt SQLObject/trunk/sqlobject/postgres/pgconnection.py SQLObject/trunk/sqlobject/tests/dbtest.py Log: A patch by Diez B. Roggisch: added support for schemas in PostgreSQL. Modified: SQLObject/trunk/docs/SQLObject.txt =================================================================== --- SQLObject/trunk/docs/SQLObject.txt 2008-07-23 13:58:11 UTC (rev 3521) +++ SQLObject/trunk/docs/SQLObject.txt 2008-07-23 14:20:47 UTC (rev 3522) @@ -162,7 +162,8 @@ Parameters are: ``debug`` (default: False), ``debugOutput`` (default: False), ``cache`` (default: True), ``autoCommit`` (default: True), ``debugThreading`` (default: False), -``logger`` (default: None), ``loglevel`` (default: None). +``logger`` (default: None), ``loglevel`` (default: None), +``schema`` (default: None). If you want to pass True value in a connection URI - pass any non-empty string; an empty string for False. Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py =================================================================== --- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2008-07-23 13:58:11 UTC (rev 3521) +++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2008-07-23 14:20:47 UTC (rev 3522) @@ -85,6 +85,7 @@ dsn = ' '.join(dsn) self.dsn = dsn self.unicodeCols = unicodeCols + self.schema = kw.pop('schema', None) DBAPI.__init__(self, **kw) def connectionFromURI(cls, uri): @@ -114,6 +115,9 @@ # psycopg2 does not have an autocommit method. if hasattr(conn, 'autocommit'): conn.autocommit(1) + if self.schema: + c = conn.cursor() + c.execute("SET search_path TO " + self.schema) return conn def _queryInsertID(self, conn, soInstance, id, names, values): Modified: SQLObject/trunk/sqlobject/tests/dbtest.py =================================================================== --- SQLObject/trunk/sqlobject/tests/dbtest.py 2008-07-23 13:58:11 UTC (rev 3521) +++ SQLObject/trunk/sqlobject/tests/dbtest.py 2008-07-23 14:20:47 UTC (rev 3522) @@ -45,7 +45,8 @@ '-blobData': 'mssql', '-decimalColumn': 'mssql', '-emptyTable': 'mssql', - '-limitSelect' : 'mssql' + '-limitSelect' : 'mssql', + '+schema' : 'postgres', } Added: SQLObject/trunk/sqlobject/tests/test_schema.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_schema.py (rev 0) +++ SQLObject/trunk/sqlobject/tests/test_schema.py 2008-07-23 14:20:47 UTC (rev 3522) @@ -0,0 +1,22 @@ +from sqlobject import * +from sqlobject.tests.dbtest import * + +######################################## +## Schema per connection +######################################## + +class Test(SQLObject): + foo = UnicodeCol(length=200) + +def test_connection_schema(): + if not supports('schema'): + return + conn = getConnection(schema=None) + conn.schema = None + conn.query('CREATE SCHEMA test') + setupClass(Test) + Test(foo='bar') + conn = Test._connection + assert conn.schema, \ + """To test a schema you need to give a connection uri that contains a schema.""" + assert conn.queryAll("select * from %s.test" % conn.schema) |