sqlobject-cvs Mailing List for SQLObject (Page 174)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sub...@co...> - 2004-12-10 13:59:09
|
Author: phd Date: 2004-12-10 13:59:05 +0000 (Fri, 10 Dec 2004) New Revision: 476 Modified: trunk/SQLObject/sqlobject/col.py Log: Fixed a bug in UnicodeStringValidator: test if the value is None. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2004-12-10 00:20:52 UTC (rev 475) +++ trunk/SQLObject/sqlobject/col.py 2004-12-10 13:59:05 UTC (rev 476) @@ -11,8 +11,8 @@ NoDefault = sqlbuilder.NoDefault True, False = 1==1, 0==1 - + ######################################## ## Columns ######################################## @@ -208,7 +208,7 @@ def _firebirdType(self): return self._sqlType() - + def _maxdbType(self): return self._sqlType() @@ -328,7 +328,7 @@ return 'BLOB SUB_TYPE TEXT' else: return self._sqlType() - + def _maxdbType(self): if not self.length: return 'LONG ASCII' @@ -344,9 +344,13 @@ self.db_encoding = db_encoding def fromPython(self, value, state): + if value is None: + return None return value.encode(self.db_encoding) def toPython(self, value, state): + if value is None: + return None return unicode(value, self.db_encoding) class SOUnicodeCol(SOStringCol): @@ -407,7 +411,7 @@ def _firebirdType(self): return 'INT' - + def _maxdbType(self): return "BOOLEAN" @@ -452,7 +456,7 @@ def _firebirdType(self): return 'INT' - + def _maxdbType(self): return 'INT' @@ -510,7 +514,7 @@ 'idName':idName}) sql = ' '.join([sql, reference]) return sql - + def maxdbCreateSQL(self): from main import findClass other = findClass(self.foreignKey) @@ -562,7 +566,7 @@ checkConstraint = "CHECK (%s in (%s))" % (self.dbName, enumValues) #NB. Return a tuple, not a string here return "VARCHAR(%i)" % (length), checkConstraint - + def _maxdbType(self): raise "Enum type is not supported" @@ -588,7 +592,7 @@ def _firebirdType(self): return 'TIMESTAMP' - + def _maxdbType(self): return 'TIMESTAMP' @@ -611,7 +615,7 @@ def _firebirdType(self): return 'DATE' - + def _maxdbType(self): return 'DATE' |
From: <sub...@co...> - 2004-12-07 17:58:10
|
Author: phd Date: 2004-12-07 17:58:06 +0000 (Tue, 07 Dec 2004) New Revision: 464 Added: home/phd/SQLObject/inheritance/sqlobject/util/ Removed: home/phd/SQLObject/inheritance/sqlobject/dbm/ Modified: home/phd/SQLObject/inheritance/README.txt home/phd/SQLObject/inheritance/docs/Authors.txt home/phd/SQLObject/inheritance/docs/News.txt home/phd/SQLObject/inheritance/docs/SQLObject.txt home/phd/SQLObject/inheritance/examples/config.py home/phd/SQLObject/inheritance/setup.py home/phd/SQLObject/inheritance/sqlobject/__init__.py home/phd/SQLObject/inheritance/sqlobject/col.py home/phd/SQLObject/inheritance/tests/SQLObjectTest.py home/phd/SQLObject/inheritance/tests/test_sqlobject.py Log: Merged patches from revisions 455:463: removed deadly broken dbm connection; updated docs. Modified: home/phd/SQLObject/inheritance/README.txt =================================================================== --- home/phd/SQLObject/inheritance/README.txt 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/README.txt 2004-12-07 17:58:06 UTC (rev 464) @@ -10,9 +10,9 @@ mapper, i.e., a library that will wrap your database tables in Python classes, and your rows in Python instances. -It absolutely requires Python 2.2 or higher. It currently supports -MySQL through the `MySQLdb` package, PostgreSQL through the -`psycopg` package, SQLite, Firebird, and a DBM-based backend. +It absolutely requires Python 2.2 or higher. It currently supports +MySQL through the `MySQLdb` package, PostgreSQL through the +`psycopg` package, SQLite, Firebird, MaxDB (SAP DB) and Sybase. For more information please see the documentation in ``docs/SQLObject.html`` Modified: home/phd/SQLObject/inheritance/docs/Authors.txt =================================================================== --- home/phd/SQLObject/inheritance/docs/Authors.txt 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/docs/Authors.txt 2004-12-07 17:58:06 UTC (rev 464) @@ -16,4 +16,4 @@ * Daniel Savard, Xsoli Inc <sqlobject at xsoli.com> * alexander smishlajev <alex at ank-sia.com> * Yaroslav Samchuk <yarcat at ank-sia.com> -* Oleg Broytmann <ph...@ph...> +* Oleg Broytmann <phd at phd.pp.ru> Modified: home/phd/SQLObject/inheritance/docs/News.txt =================================================================== --- home/phd/SQLObject/inheritance/docs/News.txt 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/docs/News.txt 2004-12-07 17:58:06 UTC (rev 464) @@ -7,6 +7,22 @@ .. _start: +SQLObject 0.6.2 +=============== + +Interface Changes +----------------- + +* The long broken and unused ``DBMConnection`` has been removed. + +* Removed DBMConnection. + +Features +-------- + +* New ``UnicodeCol()`` that converts to and from Unicode + in the database. + SQLObject 0.6.1 =============== Modified: home/phd/SQLObject/inheritance/docs/SQLObject.txt =================================================================== --- home/phd/SQLObject/inheritance/docs/SQLObject.txt 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/docs/SQLObject.txt 2004-12-07 17:58:06 UTC (rev 464) @@ -43,8 +43,7 @@ ============ Currently SQLObject supports MySQL_, PostgreSQL_ (via ``psycopg``), -SQLite_, Firebird_, and a DBM-based store. The DBM backend is -experimental. +SQLite_, Firebird_, Sybase_, and `MAX DB`_ (also known as SAP DB). .. _PostgreSQL: http://postgresql.org .. _SQLite: http://sqlite.org @@ -97,9 +96,7 @@ SQLObject provides a strong database abstraction, allowing cross-database compatibility (so long as you don't sidestep -SQLObject). This compatibility extends not just to several databases, -but also to currently one non-SQL, non-relational backend (based on -the `dbm` module). +SQLObject). SQLObject has joins, one-to-many, and many-to-many, something which many ORMs do not have. The join system is also intended to be @@ -615,26 +612,34 @@ Will create a ``BOOLEAN`` column in Postgres, or ``INT`` in other databses. It will also convert values to ``"t"/"f"`` or ``0/1`` according to the database backend. + `CurrencyCol`: Equivalent to ``DecimalCol(size=10, precision=2)``. + `DateTimeCol`: A date and time (usually returned as an mxDateTime object). + `DecimalCol`: Base-10, precise number. Uses the keyword arguments `size` for number of digits stored, and `precision` for the number of digits after the decimal point. + `EnumCol`: One of several string values -- give the possible strings as a list, with the `enumValues` keyword argument. MySQL has a native ``ENUM`` type, but will work with other databases too (storage just won't be as efficient). + `FloatCol`: Floats. + `ForeignKey`: A key to another table/class. Use like ``user = ForeignKey('User')``. + `IntCol`: Integers. + `StringCol`: A string (character) column. Extra keywords: @@ -646,6 +651,15 @@ ``CHAR`` and ``VARCHAR``, default True, i.e., use ``VARCHAR``. +`UnicodeCol`: + A subclass of `StringCol`. Also accepts a dbEncoding keyword + argument, which defaults to ``"UTF-8"``. Values coming in and + out from the database will be encoded and decoded. **Note**: + parameters in queries will not be automatically encoded, so if + you do a query matching a UnicodeCol column you must apply the + encoding yourself. + + SQLObject Class: Specifying Your Class -------------------------------------- @@ -792,8 +806,7 @@ All the connections support creating and droping tables based on the class definition. First you have to prepare your class definition, -which means including type information in your columns (though -DBMConnection_ do not require or use type information). +which means including type information in your columns. Columns Types ~~~~~~~~~~~~~ @@ -942,7 +955,7 @@ While SQLObject tries not to make too many requirements on your schema, some assumptions are made. Some of these may be relaxed in -the future. (Of course, none of this applies to DBMConnection) +the future. All tables that you want to turn into a class need to have an integer primary key. That key should be defined like: @@ -1032,7 +1045,7 @@ The `DBConnection` module currently has four external classes, `MySQLConnection`, `PostgresConnection`, `SQLiteConnection`, -and `DBMConnection`. +`SybaseConnection`, and `MaxdbConnection`. You can pass the keyword argument `debug` to any connector. If set to true, then any SQL sent to the database will also be printed to the @@ -1097,46 +1110,46 @@ .. _this page: http://www.volny.cz/iprenosil/interbase/ip_ib_indexcalculator.htm -DBMConnection -------------- +SybaseConnection +---------------- -`DBMConnection` takes a single string, which is the path to a -directory in which to store the database. +`SybaseConnection` takes the arguments `host`, `db`, `user`, and +`passwd`. It also takes the extra boolean argument `locking` (default +True), which is passed through when performing a connection. You may +use a False value for `locking` if you are not using multiple threads, +for a slight performance boost. -DBMConnection uses flat hash databases to store all the data. These -databases are created by the standard `anydbm` module. This is -something of an experiment, and things like safety under concurrent -access (multithreaded or multiprocess) should not be expected. The -select interface using the magic ``q`` attribute is supported, though -other SQL is not supported. +It uses the Sybase_ module. -DBMConnection allows any kind of objects to be put in columns -- all -values are pickled, and so only normal pickling restrictions apply. +.. _Sybase: http://www.object-craft.com.au/projects/sybase/ -DBMConnection does not support `automatic class generation` or -transactions_. +MAX DB +------ +MAX DB, also known as SAP DB, is available from a partnership of SAP +and MySQL. It takes the typical arguments: `host`, `database`, +`user`, `password`. It also takes the arguments `sqlmode` (default +``"internal"``), `isolation`, and `timeout`, which are passed through +when creating the connection to the database. + +It uses the sapdb_ module. + +.. _sapdb: http://www.sapdb.org/sapdbPython.html + Exported Symbols ================ -You can use ``from SQLObject import *``, though you don't have to. It +You can use ``from sqlobject import *``, though you don't have to. It exports a minimal number of symbols. The symbols exported: -From `SQLObject.SQLObject`: +From `sqlobject.main`: * `NoDefault` * `SQLObject` * `getID` * `getObject` -From `SQLObject.DBConnection`: - -* `MySQLConnection` -* `PostgresConnection` -* `SQLiteConnection` -* `DBMConnection` - -From `SQLObject.Col`: +From `sqlobject.col`: * `Col` * `StringCol` * `IntCol` @@ -1148,17 +1161,17 @@ * `DecimalCol` * `CurrencyCol` -From `SQLObject.Join`: +From `sqlobject.joins`: * `MultipleJoin` * `RelatedJoin` -From `SQLObject.Style`: +From `sqlobject.styles`: * `Style` * `MixedCaseUnderscoreStyle` * `DefaultStyle` * `MixedCaseStyle` -From `SQLObject.SQLBuilder`: +From `sqlobject.sqlbuilder`: * `AND` * `OR` Modified: home/phd/SQLObject/inheritance/examples/config.py =================================================================== --- home/phd/SQLObject/inheritance/examples/config.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/examples/config.py 2004-12-07 17:58:06 UTC (rev 464) @@ -13,8 +13,6 @@ conn = 'postgres://test@localhost/testdb' conn = SQLiteConnection('database.db') conn = 'sqlite://path/to/database.db' -conn = DBMConnection('database/') -conn = 'dbm://path/to/database/' ## end snippet """ #conn = MySQLConnection(user='test', db='test') Modified: home/phd/SQLObject/inheritance/setup.py =================================================================== --- home/phd/SQLObject/inheritance/setup.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/setup.py 2004-12-07 17:58:06 UTC (rev 464) @@ -2,7 +2,7 @@ import warnings warnings.filterwarnings("ignore", "Unknown distribution option") -subpackages = ['dbm', 'firebird', 'include', 'mysql', 'postgres', +subpackages = ['firebird', 'include', 'mysql', 'postgres', 'sqlite', 'sybase', 'maxdb'] import sys Modified: home/phd/SQLObject/inheritance/sqlobject/__init__.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/__init__.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/sqlobject/__init__.py 2004-12-07 17:58:06 UTC (rev 464) @@ -34,11 +34,6 @@ _warn('SQLiteConnection is deprecated; use connectionForURI("sqlite://...") or "from sqlobject.sqlite import builder; SQLiteConnection = builder()"') return _sqlite.builder()(*args, **kw) -import dbm as _dbm -def DBMConnection(*args, **kw): - _warn('DBMConnection is deprecated; use connectionForURI("dbm://...") or "from sqlobject.dbm import builder; DBMConnection = builder()"') - return _dbm.builder()(*args, **kw) - import sybase as _sybase def SybaseConnection(*args, **kw): _warn('SybaseConnection is deprecated; use connectionForURI("sybase://...") or "from sqlobject.sybase import builder; SybaseConnection = builder()"') Modified: home/phd/SQLObject/inheritance/sqlobject/col.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/col.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/sqlobject/col.py 2004-12-07 17:58:06 UTC (rev 464) @@ -338,6 +338,28 @@ class StringCol(Col): baseClass = SOStringCol +class UnicodeStringValidator(validators.Validator): + + def __init__(self, db_encoding='UTF-8'): + self.db_encoding = db_encoding + + def fromPython(self, value, state): + return value.encode(self.db_encoding) + + def toPython(self, value, state): + return unicode(value, self.db_encoding) + +class SOUnicodeCol(SOStringCol): + + def __init__(self, **kw): + self.dbEncoding = popKey(kw, 'dbEncoding', 'UTF-8') + SOStringCol.__init__(self, **kw) + self.validator = validators.All.join( + UnicodeStringValidator(self.dbEncoding), self.validator) + +class UnicodeCol(Col): + baseClass = SOUnicodeCol + class SOIntCol(SOCol): # 3-03 @@: support precision, maybe max and min directly Copied: home/phd/SQLObject/inheritance/sqlobject/util (from rev 463, trunk/SQLObject/sqlobject/util) Modified: home/phd/SQLObject/inheritance/tests/SQLObjectTest.py =================================================================== --- home/phd/SQLObject/inheritance/tests/SQLObjectTest.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/tests/SQLObjectTest.py 2004-12-07 17:58:06 UTC (rev 464) @@ -28,12 +28,6 @@ supportTransactions=False, supportExpressionIndex=False) -def dbmConnection(): - return 'dbm:///data', d( - supportAuto=False, - supportRestrictedEnum=False, - supportTransactions=False) - def postgresConnection(): return 'postgres:///test', d() Modified: home/phd/SQLObject/inheritance/tests/test_sqlobject.py =================================================================== --- home/phd/SQLObject/inheritance/tests/test_sqlobject.py 2004-12-07 17:53:51 UTC (rev 463) +++ home/phd/SQLObject/inheritance/tests/test_sqlobject.py 2004-12-07 17:58:06 UTC (rev 464) @@ -1254,6 +1254,39 @@ {0: 1, 1:1}) ######################################## +## Unicode columns +######################################## + +class Unicode1(SQLObject): + count = IntCol(alternateID=True) + col1 = UnicodeCol() + col2 = UnicodeCol(dbEncoding='latin-1') + +class UnicodeTest(SQLObjectTest): + + classes = [Unicode1] + + data = [u'\u00f0', u'test', 'ascii test'] + + def testCreate(self): + items = [] + for i, n in enumerate(self.data): + items.append(Unicode1(count=i, col1=n, col2=n)) + for n, item in zip(self.data, items): + item.col1 = item.col2 = n + for n, item in zip(self.data, items): + self.assertEqual(item.col1, item.col2, n) + conn = Unicode1._connection + rows = conn.queryAll(""" + SELECT count, col1, col2 + FROM unicode1 + ORDER BY count + """) + for count, col1, col2 in rows: + self.assertEqual(self.data[count].encode('utf-8'), col1) + self.assertEqual(self.data[count].encode('latin1'), col2) + +######################################## ## Run from command-line: ######################################## |
From: <sub...@co...> - 2004-12-07 17:53:54
|
Author: phd Date: 2004-12-07 17:53:51 +0000 (Tue, 07 Dec 2004) New Revision: 463 Modified: trunk/SQLObject/README.txt trunk/SQLObject/docs/News.txt trunk/SQLObject/examples/config.py trunk/SQLObject/tests/SQLObjectTest.py Log: Removed deadly broken dbm connection; updated docs. Modified: trunk/SQLObject/README.txt =================================================================== --- trunk/SQLObject/README.txt 2004-12-07 17:28:19 UTC (rev 462) +++ trunk/SQLObject/README.txt 2004-12-07 17:53:51 UTC (rev 463) @@ -10,9 +10,9 @@ mapper, i.e., a library that will wrap your database tables in Python classes, and your rows in Python instances. -It absolutely requires Python 2.2 or higher. It currently supports -MySQL through the `MySQLdb` package, PostgreSQL through the -`psycopg` package, SQLite, Firebird, and a DBM-based backend. +It absolutely requires Python 2.2 or higher. It currently supports +MySQL through the `MySQLdb` package, PostgreSQL through the +`psycopg` package, SQLite, Firebird, MaxDB (SAP DB) and Sybase. For more information please see the documentation in ``docs/SQLObject.html`` Modified: trunk/SQLObject/docs/News.txt =================================================================== --- trunk/SQLObject/docs/News.txt 2004-12-07 17:28:19 UTC (rev 462) +++ trunk/SQLObject/docs/News.txt 2004-12-07 17:53:51 UTC (rev 463) @@ -15,6 +15,8 @@ * The long broken and unused ``DBMConnection`` has been removed. +* Removed DBMConnection. + Features -------- Modified: trunk/SQLObject/examples/config.py =================================================================== --- trunk/SQLObject/examples/config.py 2004-12-07 17:28:19 UTC (rev 462) +++ trunk/SQLObject/examples/config.py 2004-12-07 17:53:51 UTC (rev 463) @@ -13,8 +13,6 @@ conn = 'postgres://test@localhost/testdb' conn = SQLiteConnection('database.db') conn = 'sqlite://path/to/database.db' -conn = DBMConnection('database/') -conn = 'dbm://path/to/database/' ## end snippet """ #conn = MySQLConnection(user='test', db='test') Modified: trunk/SQLObject/tests/SQLObjectTest.py =================================================================== --- trunk/SQLObject/tests/SQLObjectTest.py 2004-12-07 17:28:19 UTC (rev 462) +++ trunk/SQLObject/tests/SQLObjectTest.py 2004-12-07 17:53:51 UTC (rev 463) @@ -28,12 +28,6 @@ supportTransactions=False, supportExpressionIndex=False) -def dbmConnection(): - return 'dbm:///data', d( - supportAuto=False, - supportRestrictedEnum=False, - supportTransactions=False) - def postgresConnection(): return 'postgres:///test', d() |
From: <sub...@co...> - 2004-12-07 17:28:23
|
Author: ianb Date: 2004-12-07 17:28:19 +0000 (Tue, 07 Dec 2004) New Revision: 462 Modified: trunk/SQLObject/docs/News.txt trunk/SQLObject/docs/SQLObject.txt trunk/SQLObject/sqlobject/col.py trunk/SQLObject/tests/test_sqlobject.py Log: Added a UnicodeCol Modified: trunk/SQLObject/docs/News.txt =================================================================== --- trunk/SQLObject/docs/News.txt 2004-12-07 17:27:40 UTC (rev 461) +++ trunk/SQLObject/docs/News.txt 2004-12-07 17:28:19 UTC (rev 462) @@ -7,6 +7,20 @@ .. _start: +SQLObject 0.6.2 +=============== + +Interface Changes +----------------- + +* The long broken and unused ``DBMConnection`` has been removed. + +Features +-------- + +* New ``UnicodeCol()`` that converts to and from Unicode + in the database. + SQLObject 0.6.1 =============== Modified: trunk/SQLObject/docs/SQLObject.txt =================================================================== --- trunk/SQLObject/docs/SQLObject.txt 2004-12-07 17:27:40 UTC (rev 461) +++ trunk/SQLObject/docs/SQLObject.txt 2004-12-07 17:28:19 UTC (rev 462) @@ -612,26 +612,34 @@ Will create a ``BOOLEAN`` column in Postgres, or ``INT`` in other databses. It will also convert values to ``"t"/"f"`` or ``0/1`` according to the database backend. + `CurrencyCol`: Equivalent to ``DecimalCol(size=10, precision=2)``. + `DateTimeCol`: A date and time (usually returned as an mxDateTime object). + `DecimalCol`: Base-10, precise number. Uses the keyword arguments `size` for number of digits stored, and `precision` for the number of digits after the decimal point. + `EnumCol`: One of several string values -- give the possible strings as a list, with the `enumValues` keyword argument. MySQL has a native ``ENUM`` type, but will work with other databases too (storage just won't be as efficient). + `FloatCol`: Floats. + `ForeignKey`: A key to another table/class. Use like ``user = ForeignKey('User')``. + `IntCol`: Integers. + `StringCol`: A string (character) column. Extra keywords: @@ -643,6 +651,15 @@ ``CHAR`` and ``VARCHAR``, default True, i.e., use ``VARCHAR``. +`UnicodeCol`: + A subclass of `StringCol`. Also accepts a dbEncoding keyword + argument, which defaults to ``"UTF-8"``. Values coming in and + out from the database will be encoded and decoded. **Note**: + parameters in queries will not be automatically encoded, so if + you do a query matching a UnicodeCol column you must apply the + encoding yourself. + + SQLObject Class: Specifying Your Class -------------------------------------- Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2004-12-07 17:27:40 UTC (rev 461) +++ trunk/SQLObject/sqlobject/col.py 2004-12-07 17:28:19 UTC (rev 462) @@ -338,6 +338,28 @@ class StringCol(Col): baseClass = SOStringCol +class UnicodeStringValidator(validators.Validator): + + def __init__(self, db_encoding='UTF-8'): + self.db_encoding = db_encoding + + def fromPython(self, value, state): + return value.encode(self.db_encoding) + + def toPython(self, value, state): + return unicode(value, self.db_encoding) + +class SOUnicodeCol(SOStringCol): + + def __init__(self, **kw): + self.dbEncoding = popKey(kw, 'dbEncoding', 'UTF-8') + SOStringCol.__init__(self, **kw) + self.validator = validators.All.join( + UnicodeStringValidator(self.dbEncoding), self.validator) + +class UnicodeCol(Col): + baseClass = SOUnicodeCol + class SOIntCol(SOCol): # 3-03 @@: support precision, maybe max and min directly Modified: trunk/SQLObject/tests/test_sqlobject.py =================================================================== --- trunk/SQLObject/tests/test_sqlobject.py 2004-12-07 17:27:40 UTC (rev 461) +++ trunk/SQLObject/tests/test_sqlobject.py 2004-12-07 17:28:19 UTC (rev 462) @@ -1254,6 +1254,39 @@ {0: 1, 1:1}) ######################################## +## Unicode columns +######################################## + +class Unicode1(SQLObject): + count = IntCol(alternateID=True) + col1 = UnicodeCol() + col2 = UnicodeCol(dbEncoding='latin-1') + +class UnicodeTest(SQLObjectTest): + + classes = [Unicode1] + + data = [u'\u00f0', u'test', 'ascii test'] + + def testCreate(self): + items = [] + for i, n in enumerate(self.data): + items.append(Unicode1(count=i, col1=n, col2=n)) + for n, item in zip(self.data, items): + item.col1 = item.col2 = n + for n, item in zip(self.data, items): + self.assertEqual(item.col1, item.col2, n) + conn = Unicode1._connection + rows = conn.queryAll(""" + SELECT count, col1, col2 + FROM unicode1 + ORDER BY count + """) + for count, col1, col2 in rows: + self.assertEqual(self.data[count].encode('utf-8'), col1) + self.assertEqual(self.data[count].encode('latin1'), col2) + +######################################## ## Run from command-line: ######################################## |
From: <sub...@co...> - 2004-12-07 17:27:43
|
Author: ianb Date: 2004-12-07 17:27:40 +0000 (Tue, 07 Dec 2004) New Revision: 461 Modified: trunk/SQLObject/docs/Authors.txt Log: Added Oleg. Modified: trunk/SQLObject/docs/Authors.txt =================================================================== --- trunk/SQLObject/docs/Authors.txt 2004-12-07 17:00:58 UTC (rev 460) +++ trunk/SQLObject/docs/Authors.txt 2004-12-07 17:27:40 UTC (rev 461) @@ -13,3 +13,4 @@ * James Ralston <jralston at hotmail.com> * Sidnei da Silva <sidnei at awkly.org> * Brad Bollenbach <brad at bbnet.ca> +* Oleg Broytmann <phd at phd.pp.ru> |
From: <sub...@co...> - 2004-12-07 17:01:09
|
Author: ianb Date: 2004-12-07 17:00:58 +0000 (Tue, 07 Dec 2004) New Revision: 460 Modified: trunk/SQLObject/docs/SQLObject.txt Log: * Took out references to DBMConnection * Added references to SybaseConnection and MaxdbConnection * A few other miscellaneous changes Modified: trunk/SQLObject/docs/SQLObject.txt =================================================================== --- trunk/SQLObject/docs/SQLObject.txt 2004-12-07 17:00:15 UTC (rev 459) +++ trunk/SQLObject/docs/SQLObject.txt 2004-12-07 17:00:58 UTC (rev 460) @@ -43,8 +43,7 @@ ============ Currently SQLObject supports MySQL_, PostgreSQL_ (via ``psycopg``), -SQLite_, Firebird_, and a DBM-based store. The DBM backend is -experimental. +SQLite_, Firebird_, Sybase_, and `MAX DB`_ (also known as SAP DB). .. _PostgreSQL: http://postgresql.org .. _SQLite: http://sqlite.org @@ -97,9 +96,7 @@ SQLObject provides a strong database abstraction, allowing cross-database compatibility (so long as you don't sidestep -SQLObject). This compatibility extends not just to several databases, -but also to currently one non-SQL, non-relational backend (based on -the `dbm` module). +SQLObject). SQLObject has joins, one-to-many, and many-to-many, something which many ORMs do not have. The join system is also intended to be @@ -792,8 +789,7 @@ All the connections support creating and droping tables based on the class definition. First you have to prepare your class definition, -which means including type information in your columns (though -DBMConnection_ do not require or use type information). +which means including type information in your columns. Columns Types ~~~~~~~~~~~~~ @@ -942,7 +938,7 @@ While SQLObject tries not to make too many requirements on your schema, some assumptions are made. Some of these may be relaxed in -the future. (Of course, none of this applies to DBMConnection) +the future. All tables that you want to turn into a class need to have an integer primary key. That key should be defined like: @@ -1032,7 +1028,7 @@ The `DBConnection` module currently has four external classes, `MySQLConnection`, `PostgresConnection`, `SQLiteConnection`, -and `DBMConnection`. +`SybaseConnection`, and `MaxdbConnection`. You can pass the keyword argument `debug` to any connector. If set to true, then any SQL sent to the database will also be printed to the @@ -1097,46 +1093,46 @@ .. _this page: http://www.volny.cz/iprenosil/interbase/ip_ib_indexcalculator.htm -DBMConnection -------------- +SybaseConnection +---------------- -`DBMConnection` takes a single string, which is the path to a -directory in which to store the database. +`SybaseConnection` takes the arguments `host`, `db`, `user`, and +`passwd`. It also takes the extra boolean argument `locking` (default +True), which is passed through when performing a connection. You may +use a False value for `locking` if you are not using multiple threads, +for a slight performance boost. -DBMConnection uses flat hash databases to store all the data. These -databases are created by the standard `anydbm` module. This is -something of an experiment, and things like safety under concurrent -access (multithreaded or multiprocess) should not be expected. The -select interface using the magic ``q`` attribute is supported, though -other SQL is not supported. +It uses the Sybase_ module. -DBMConnection allows any kind of objects to be put in columns -- all -values are pickled, and so only normal pickling restrictions apply. +.. _Sybase: http://www.object-craft.com.au/projects/sybase/ -DBMConnection does not support `automatic class generation` or -transactions_. +MAX DB +------ +MAX DB, also known as SAP DB, is available from a partnership of SAP +and MySQL. It takes the typical arguments: `host`, `database`, +`user`, `password`. It also takes the arguments `sqlmode` (default +``"internal"``), `isolation`, and `timeout`, which are passed through +when creating the connection to the database. + +It uses the sapdb_ module. + +.. _sapdb: http://www.sapdb.org/sapdbPython.html + Exported Symbols ================ -You can use ``from SQLObject import *``, though you don't have to. It +You can use ``from sqlobject import *``, though you don't have to. It exports a minimal number of symbols. The symbols exported: -From `SQLObject.SQLObject`: +From `sqlobject.main`: * `NoDefault` * `SQLObject` * `getID` * `getObject` -From `SQLObject.DBConnection`: - -* `MySQLConnection` -* `PostgresConnection` -* `SQLiteConnection` -* `DBMConnection` - -From `SQLObject.Col`: +From `sqlobject.col`: * `Col` * `StringCol` * `IntCol` @@ -1148,17 +1144,17 @@ * `DecimalCol` * `CurrencyCol` -From `SQLObject.Join`: +From `sqlobject.joins`: * `MultipleJoin` * `RelatedJoin` -From `SQLObject.Style`: +From `sqlobject.styles`: * `Style` * `MixedCaseUnderscoreStyle` * `DefaultStyle` * `MixedCaseStyle` -From `SQLObject.SQLBuilder`: +From `sqlobject.sqlbuilder`: * `AND` * `OR` |
From: <sub...@co...> - 2004-12-07 17:00:17
|
Author: ianb Date: 2004-12-07 17:00:15 +0000 (Tue, 07 Dec 2004) New Revision: 459 Modified: trunk/SQLObject/setup.py Log: Removed dbm package from setup.py Modified: trunk/SQLObject/setup.py =================================================================== --- trunk/SQLObject/setup.py 2004-12-07 16:36:05 UTC (rev 458) +++ trunk/SQLObject/setup.py 2004-12-07 17:00:15 UTC (rev 459) @@ -2,7 +2,7 @@ import warnings warnings.filterwarnings("ignore", "Unknown distribution option") -subpackages = ['dbm', 'firebird', 'include', 'mysql', 'postgres', +subpackages = ['firebird', 'include', 'mysql', 'postgres', 'sqlite', 'sybase', 'maxdb'] import sys |
From: <sub...@co...> - 2004-12-07 16:36:07
|
Author: ianb Date: 2004-12-07 16:36:05 +0000 (Tue, 07 Dec 2004) New Revision: 458 Modified: trunk/SQLObject/sqlobject/styles.py Log: Undid mistaken commit. Stupid editor keeps saving my files when I intend to abort... Modified: trunk/SQLObject/sqlobject/styles.py =================================================================== --- trunk/SQLObject/sqlobject/styles.py 2004-12-07 16:30:00 UTC (rev 457) +++ trunk/SQLObject/sqlobject/styles.py 2004-12-07 16:36:05 UTC (rev 458) @@ -87,10 +87,6 @@ DefaultStyle = MixedCaseUnderscoreStyle -class UnderscoreStyle(MixedCaseUnderscoreStyle): - def instanceAttrToIDAttr(self, attr): - return attr + '_id' - class MixedCaseStyle(Style): """ |
From: <sub...@co...> - 2004-12-07 16:30:09
|
Author: ianb Date: 2004-12-07 16:30:00 +0000 (Tue, 07 Dec 2004) New Revision: 457 Added: trunk/SQLObject/sqlobject/util/ Modified: trunk/SQLObject/sqlobject/__init__.py trunk/SQLObject/sqlobject/styles.py Log: R Modified: trunk/SQLObject/sqlobject/__init__.py =================================================================== --- trunk/SQLObject/sqlobject/__init__.py 2004-12-07 16:29:14 UTC (rev 456) +++ trunk/SQLObject/sqlobject/__init__.py 2004-12-07 16:30:00 UTC (rev 457) @@ -34,11 +34,6 @@ _warn('SQLiteConnection is deprecated; use connectionForURI("sqlite://...") or "from sqlobject.sqlite import builder; SQLiteConnection = builder()"') return _sqlite.builder()(*args, **kw) -import dbm as _dbm -def DBMConnection(*args, **kw): - _warn('DBMConnection is deprecated; use connectionForURI("dbm://...") or "from sqlobject.dbm import builder; DBMConnection = builder()"') - return _dbm.builder()(*args, **kw) - import sybase as _sybase def SybaseConnection(*args, **kw): _warn('SybaseConnection is deprecated; use connectionForURI("sybase://...") or "from sqlobject.sybase import builder; SybaseConnection = builder()"') Modified: trunk/SQLObject/sqlobject/styles.py =================================================================== --- trunk/SQLObject/sqlobject/styles.py 2004-12-07 16:29:14 UTC (rev 456) +++ trunk/SQLObject/sqlobject/styles.py 2004-12-07 16:30:00 UTC (rev 457) @@ -87,6 +87,10 @@ DefaultStyle = MixedCaseUnderscoreStyle +class UnderscoreStyle(MixedCaseUnderscoreStyle): + def instanceAttrToIDAttr(self, attr): + return attr + '_id' + class MixedCaseStyle(Style): """ |
From: <sub...@co...> - 2004-12-07 16:29:23
|
Author: ianb Date: 2004-12-07 16:29:14 +0000 (Tue, 07 Dec 2004) New Revision: 456 Removed: trunk/SQLObject/sqlobject/dbm/ Log: Removed |
From: <sub...@co...> - 2004-12-06 22:53:43
|
Author: phd Date: 2004-12-06 22:53:38 +0000 (Mon, 06 Dec 2004) New Revision: 452 Modified: home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py Log: Merged patch from revisions 449:450: fixed tableExists(): use sqlrepr() to quote tableName; removed a comment. Modified: home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py =================================================================== --- home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py 2004-12-06 22:50:45 UTC (rev 451) +++ home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py 2004-12-06 22:53:38 UTC (rev 452) @@ -111,9 +111,8 @@ return 'INT NOT NULL' def tableExists(self, tableName): - # @@: obviously broken - result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = '%s'" - % tableName) + result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = %s" + % self.sqlrepr(tableName)) return result[0] def addColumn(self, tableName, column): |
From: <sub...@co...> - 2004-12-06 22:50:48
|
Author: phd Date: 2004-12-06 22:50:45 +0000 (Mon, 06 Dec 2004) New Revision: 451 Modified: home/phd/SQLObject/inheritance/sqlobject/postgres/pgconnection.py Log: Merged patch from revisions 449:450: fixed tableExists(): use sqlrepr() to quote tableName; removed a comment. Modified: home/phd/SQLObject/inheritance/sqlobject/postgres/pgconnection.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/postgres/pgconnection.py 2004-12-06 22:46:33 UTC (rev 450) +++ home/phd/SQLObject/inheritance/sqlobject/postgres/pgconnection.py 2004-12-06 22:50:45 UTC (rev 451) @@ -105,9 +105,8 @@ return 'INT NOT NULL' def tableExists(self, tableName): - # @@: obviously broken - result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = '%s'" - % tableName) + result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = %s" + % self.sqlrepr(tableName)) return result[0] def addColumn(self, tableName, column): |
From: <sub...@co...> - 2004-12-06 22:46:35
|
Author: phd Date: 2004-12-06 22:46:33 +0000 (Mon, 06 Dec 2004) New Revision: 450 Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py Log: Fixed tableExists(): use sqlrepr() to quote tableName; removed a comment. Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py =================================================================== --- trunk/SQLObject/sqlobject/postgres/pgconnection.py 2004-12-06 13:51:10 UTC (rev 449) +++ trunk/SQLObject/sqlobject/postgres/pgconnection.py 2004-12-06 22:46:33 UTC (rev 450) @@ -105,9 +105,8 @@ return 'INT NOT NULL' def tableExists(self, tableName): - # @@: obviously broken - result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = '%s'" - % tableName) + result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = %s" + % self.sqlrepr(tableName)) return result[0] def addColumn(self, tableName, column): |
From: <sub...@co...> - 2004-12-06 13:51:13
|
Author: phd Date: 2004-12-06 13:51:10 +0000 (Mon, 06 Dec 2004) New Revision: 449 Modified: home/phd/SQLObject/inheritance/tests/test_sqlobject.py Log: Merged patch from revisions 447: removed .set(driver='james') - we've decided to not allow non-columns keywords in .set(). Modified: home/phd/SQLObject/inheritance/tests/test_sqlobject.py =================================================================== --- home/phd/SQLObject/inheritance/tests/test_sqlobject.py 2004-12-06 13:50:48 UTC (rev 448) +++ home/phd/SQLObject/inheritance/tests/test_sqlobject.py 2004-12-06 13:51:10 UTC (rev 449) @@ -1156,12 +1156,10 @@ # Also, check that passing a name that is not # a valid column doesn't break, but instead # just does a plain setattr. - obj.set(name='first', other='who', - third='yes', driver='james') + obj.set(name='first', other='who', third='yes') self.assertEqual(obj.name, 'first') self.assertEqual(obj.other, 'who') self.assertEqual(obj.third, 'yes') - self.assertEqual(obj.driver, 'james') assert obj.dirty assert not self.conn.didUpdate obj.syncUpdate() |
From: <sub...@co...> - 2004-12-06 13:50:51
|
Author: phd Date: 2004-12-06 13:50:48 +0000 (Mon, 06 Dec 2004) New Revision: 448 Modified: home/phd/SQLObject/postgres-7.2/tests/test_sqlobject.py Log: Merged patch from revisions 447: removed .set(driver='james') - we've decided to not allow non-columns keywords in .set(). Modified: home/phd/SQLObject/postgres-7.2/tests/test_sqlobject.py =================================================================== --- home/phd/SQLObject/postgres-7.2/tests/test_sqlobject.py 2004-12-06 13:46:24 UTC (rev 447) +++ home/phd/SQLObject/postgres-7.2/tests/test_sqlobject.py 2004-12-06 13:50:48 UTC (rev 448) @@ -1156,12 +1156,10 @@ # Also, check that passing a name that is not # a valid column doesn't break, but instead # just does a plain setattr. - obj.set(name='first', other='who', - third='yes', driver='james') + obj.set(name='first', other='who', third='yes') self.assertEqual(obj.name, 'first') self.assertEqual(obj.other, 'who') self.assertEqual(obj.third, 'yes') - self.assertEqual(obj.driver, 'james') assert obj.dirty assert not self.conn.didUpdate obj.syncUpdate() |
From: <sub...@co...> - 2004-12-06 13:46:27
|
Author: phd Date: 2004-12-06 13:46:24 +0000 (Mon, 06 Dec 2004) New Revision: 447 Modified: trunk/SQLObject/tests/test_sqlobject.py Log: Removed .set(driver='james') - we've decided to not allow non-columns keywords in .set(). Modified: trunk/SQLObject/tests/test_sqlobject.py =================================================================== --- trunk/SQLObject/tests/test_sqlobject.py 2004-12-06 13:31:56 UTC (rev 446) +++ trunk/SQLObject/tests/test_sqlobject.py 2004-12-06 13:46:24 UTC (rev 447) @@ -1156,12 +1156,10 @@ # Also, check that passing a name that is not # a valid column doesn't break, but instead # just does a plain setattr. - obj.set(name='first', other='who', - third='yes', driver='james') + obj.set(name='first', other='who', third='yes') self.assertEqual(obj.name, 'first') self.assertEqual(obj.other, 'who') self.assertEqual(obj.third, 'yes') - self.assertEqual(obj.driver, 'james') assert obj.dirty assert not self.conn.didUpdate obj.syncUpdate() |
From: <sub...@co...> - 2004-12-06 13:32:02
|
Author: phd Date: 2004-12-06 13:31:56 +0000 (Mon, 06 Dec 2004) New Revision: 446 Modified: home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py Log: Implemeted columnsFromSchemaOld() for postgres 7.2. Fixed dropTable() - drop primary key (id) sequence after the table. Modified: home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py =================================================================== --- home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py 2004-12-06 13:30:03 UTC (rev 445) +++ home/phd/SQLObject/postgres-7.2/sqlobject/postgres/pgconnection.py 2004-12-06 13:31:56 UTC (rev 446) @@ -98,8 +98,14 @@ def dropTable(self, tableName, cascade=False): if self.server_version[:3] <= "7.2": cascade=False + primaryKey = self._getPrimaryKey(tableName) + print "DROP TABLE and SEQUENCE..." self.query("DROP TABLE %s %s" % (tableName, cascade and 'CASCADE' or '')) + if self.server_version[:3] <= "7.2": + if len(tableName) + len("_%s_seq" % primaryKey) > 31: # max postgres name length + tableNem = tableName[:len("_%s_seq" % primaryKey)] + self.query("DROP SEQUENCE %s_%s_seq" % (tableName, primaryKey)) def joinSQLType(self, join): return 'INT NOT NULL' @@ -120,8 +126,69 @@ (tableName, column.dbName)) + def _getPrimaryKey(self, tableName): + + primaryKeyQuery = """ + SELECT a.attname FROM pg_attribute a, pg_index i, pg_class c + WHERE a.attnum = i.indkey[0] AND i.indisprimary = TRUE + AND a.attrelid = c.oid AND i.indrelid = c.oid AND c.relname = %s """ + + primaryData = self.queryOne(primaryKeyQuery % self.sqlrepr(tableName)) + primaryKey = None + if primaryData: + primaryKey = primaryData[0] + return primaryKey + + def columnsFromSchemaOld(self, tableName, soClass): + + # This query doesn't work, at least for me, because + # pg_relcheck table is empty. + keyQuery = """ + SELECT r.rcsrc + FROM pg_relcheck r, pg_class c + WHERE r.rcrelid = c.oid AND c.relname = %s""" + + colQuery = """ + SELECT a.attname, type.typname, a.attnotnull, a.atthasdef, def.adsrc + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_type type ON a.atttypid = type.oid + LEFT JOIN pg_attrdef def ON def.adrelid = c.oid AND def.adnum = a.attnum + WHERE c.relname = %s AND type.typname NOT IN ('oid', 'cid', 'tid', 'xid') + ORDER BY a.attnum""" + + keyData = self.queryAll(keyQuery % self.sqlrepr(tableName)) + keyRE = re.compile(r"\((.+)\) REFERENCES (.+)\(") + keymap = {} + + for (condef,) in keyData: + match = keyRE.search(condef) + if match: + field, reftable = match.groups() + keymap[field] = reftable.capitalize() + + primaryKey = self._getPrimaryKey(tableName) + + colData = self.queryAll(colQuery % self.sqlrepr(tableName)) + results = [] + for field, t, notnull, has_default, defaultstr in colData: + if field == primaryKey: + continue + colClass, kw = self.guessClass(t) + kw['name'] = soClass._style.dbColumnToPythonAttr(field) + kw['notNone'] = notnull + if has_default and defaultstr is not None: + kw['default'] = getattr(sqlbuilder.const, defaultstr) + if keymap.has_key(field): + kw['foreignKey'] = keymap[field] + results.append(colClass(**kw)) + return results + def columnsFromSchema(self, tableName, soClass): + if self.server_version[:3] <= "7.2": + return self.columnsFromSchemaOld(tableName, soClass) + keyQuery = """ SELECT pg_catalog.pg_get_constraintdef(oid) as condef FROM pg_catalog.pg_constraint r @@ -129,12 +196,12 @@ colQuery = """ SELECT a.attname, - pg_catalog.format_type(a.atttypid, a.atttypmod), a.attnotnull, - (SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d - WHERE d.adrelid=a.attrelid AND d.adnum = a.attnum) + pg_catalog.format_type(a.atttypid, a.atttypmod), a.attnotnull, + (SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d + WHERE d.adrelid=a.attrelid AND d.adnum = a.attnum) FROM pg_catalog.pg_attribute a WHERE a.attrelid =%s::regclass - AND a.attnum > 0 AND NOT a.attisdropped + AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum""" primaryKeyQuery = """ @@ -145,13 +212,12 @@ WHERE c.relname = %s AND c.oid = pg_index.indrelid AND pg_index.indexrelid = c2.oid - AND pg_index.indisprimary - """ + AND pg_index.indisprimary""" keyData = self.queryAll(keyQuery % self.sqlrepr(tableName)) keyRE = re.compile(r"\((.+)\) REFERENCES (.+)\(") keymap = {} - + for (condef,) in keyData: match = keyRE.search(condef) if match: |
From: <sub...@co...> - 2004-12-06 13:30:12
|
Author: phd Date: 2004-12-06 13:30:03 +0000 (Mon, 06 Dec 2004) New Revision: 445 Added: home/phd/SQLObject/postgres-7.2/ Log: Created a private branch for patches related to postgres 7.2. Copied: home/phd/SQLObject/postgres-7.2 (from rev 444, trunk/SQLObject) |
From: <sub...@co...> - 2004-12-03 14:48:43
|
Author: phd Date: 2004-12-03 14:48:39 +0000 (Fri, 03 Dec 2004) New Revision: 438 Modified: trunk/SQLObject/sqlobject/main.py Log: Merged patch from revisions 435:437: lookup column names in self._SO_columnDict in addition to self.__class__. Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2004-12-03 14:43:51 UTC (rev 437) +++ trunk/SQLObject/sqlobject/main.py 2004-12-03 14:48:39 UTC (rev 438) @@ -782,7 +782,8 @@ try: getattr(self.__class__, name) except AttributeError: - raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) + if name not in self._SO_columnDict: + raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: setattr(self, name, value) except AttributeError, e: @@ -820,7 +821,8 @@ try: getattr(self.__class__, name) except AttributeError: - raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) + if name not in self._SO_columnDict: + raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: setattr(self, name, value) except AttributeError, e: |
From: <sub...@co...> - 2004-12-03 14:43:54
|
Author: phd Date: 2004-12-03 14:43:51 +0000 (Fri, 03 Dec 2004) New Revision: 437 Modified: home/phd/SQLObject/inheritance/sqlobject/main.py Log: Test _SO_columnDict in addition to __class__. Modified: home/phd/SQLObject/inheritance/sqlobject/main.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 14:35:24 UTC (rev 436) +++ home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 14:43:51 UTC (rev 437) @@ -904,9 +904,12 @@ value = toPython(dbValue, self._SO_validatorState) setattr(self, instanceName(name), value) for name, value in extra.items(): - if name not in self._SO_columnDict: - raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: + getattr(self.__class__, name) + except AttributeError: + if name not in self._SO_columnDict: + raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) + try: setattr(self, name, value) except AttributeError, e: raise AttributeError, '%s (with attribute %r)' % (e, name) @@ -940,9 +943,12 @@ setattr(self, instanceName(name), value) toUpdate[name] = dbValue for name, value in extra.items(): - if name not in self._SO_columnDict: - raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: + getattr(self.__class__, name) + except AttributeError: + if name not in self._SO_columnDict: + raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) + try: setattr(self, name, value) except AttributeError, e: raise AttributeError, '%s (with attribute %r)' % (e, name) |
From: <sub...@co...> - 2004-12-03 14:35:27
|
Author: phd Date: 2004-12-03 14:35:24 +0000 (Fri, 03 Dec 2004) New Revision: 436 Modified: home/phd/SQLObject/inheritance/sqlobject/main.py Log: Fixed an inconsistency: there are columns that are not in the __class__, added with addColumn, for example, such as columns from the database. Modified: home/phd/SQLObject/inheritance/sqlobject/main.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 10:54:30 UTC (rev 435) +++ home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 14:35:24 UTC (rev 436) @@ -904,9 +904,7 @@ value = toPython(dbValue, self._SO_validatorState) setattr(self, instanceName(name), value) for name, value in extra.items(): - try: - getattr(self.__class__, name) - except AttributeError: + if name not in self._SO_columnDict: raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: setattr(self, name, value) @@ -942,9 +940,7 @@ setattr(self, instanceName(name), value) toUpdate[name] = dbValue for name, value in extra.items(): - try: - getattr(self.__class__, name) - except AttributeError: + if name not in self._SO_columnDict: raise TypeError, "%s.set() got an unexpected keyword argument %s" % (self.__class__.__name__, name) try: setattr(self, name, value) |
From: <sub...@co...> - 2004-12-03 10:54:34
|
Author: phd Date: 2004-12-03 10:54:30 +0000 (Fri, 03 Dec 2004) New Revision: 435 Modified: home/phd/SQLObject/inheritance/sqlobject/mysql/mysqlconnection.py Log: Merged patch from rev 434: 2013 is the SERVER_LOST error. Modified: home/phd/SQLObject/inheritance/sqlobject/mysql/mysqlconnection.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/mysql/mysqlconnection.py 2004-12-03 10:52:44 UTC (rev 434) +++ home/phd/SQLObject/inheritance/sqlobject/mysql/mysqlconnection.py 2004-12-03 10:54:30 UTC (rev 435) @@ -34,8 +34,7 @@ try: return cursor.execute(query) except MySQLdb.OperationalError, e: - if e.args[0] == 2013: - # This is a + if e.args[0] == 2013: # SERVER_LOST error if self.debug: self.printDebug(conn, str(e), 'ERROR') else: |
From: <sub...@co...> - 2004-12-03 10:52:48
|
Author: phd Date: 2004-12-03 10:52:44 +0000 (Fri, 03 Dec 2004) New Revision: 434 Modified: trunk/SQLObject/sqlobject/mysql/mysqlconnection.py Log: 2013 is the SERVER_LOST error. Modified: trunk/SQLObject/sqlobject/mysql/mysqlconnection.py =================================================================== --- trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2004-12-03 09:25:17 UTC (rev 433) +++ trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2004-12-03 10:52:44 UTC (rev 434) @@ -34,8 +34,7 @@ try: return cursor.execute(query) except MySQLdb.OperationalError, e: - if e.args[0] == 2013: - # This is a + if e.args[0] == 2013: # SERVER_LOST error if self.debug: self.printDebug(conn, str(e), 'ERROR') else: |
From: <sub...@co...> - 2004-12-03 09:25:19
|
Author: phd Date: 2004-12-03 09:25:17 +0000 (Fri, 03 Dec 2004) New Revision: 433 Modified: home/phd/SQLObject/inheritance/sqlobject/main.py Log: Merged patch for rev 432: convert dbValue back toPython. Modified: home/phd/SQLObject/inheritance/sqlobject/main.py =================================================================== --- home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 09:24:29 UTC (rev 432) +++ home/phd/SQLObject/inheritance/sqlobject/main.py 2004-12-03 09:25:17 UTC (rev 433) @@ -894,9 +894,14 @@ # _SO_creating is special, see _SO_setValue if self._SO_creating or self._lazyUpdate: for name, value in kw.items(): - fromPy = getattr(self, '_SO_fromPython_%s' % name, None) - if fromPy: - kw[name] = fromPy(value, self._SO_validatorState) + fromPython = getattr(self, '_SO_fromPython_%s' % name, None) + if fromPython: + kw[name] = dbValue = fromPython(value, self._SO_validatorState) + else: + dbValue = value + toPython = getattr(self, '_SO_toPython_%s' % name, None) + if toPython: + value = toPython(dbValue, self._SO_validatorState) setattr(self, instanceName(name), value) for name, value in extra.items(): try: @@ -930,9 +935,12 @@ dbValue = fromPython(value, self._SO_validatorState) else: dbValue = value - toUpdate[name] = dbValue + toPython = getattr(self, '_SO_toPython_%s' % name, None) + if toPython: + value = toPython(dbValue, self._SO_validatorState) if self._cacheValues: setattr(self, instanceName(name), value) + toUpdate[name] = dbValue for name, value in extra.items(): try: getattr(self.__class__, name) |
From: <sub...@co...> - 2004-12-03 09:24:36
|
Author: phd Date: 2004-12-03 09:24:29 +0000 (Fri, 03 Dec 2004) New Revision: 432 Modified: trunk/SQLObject/sqlobject/main.py Log: Convert dbValue back toPython. Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2004-12-02 19:57:06 UTC (rev 431) +++ trunk/SQLObject/sqlobject/main.py 2004-12-03 09:24:29 UTC (rev 432) @@ -769,9 +769,14 @@ # _SO_creating is special, see _SO_setValue if self._SO_creating or self._lazyUpdate: for name, value in kw.items(): - fromPy = getattr(self, '_SO_fromPython_%s' % name, None) - if fromPy: - kw[name] = fromPy(value, self._SO_validatorState) + fromPython = getattr(self, '_SO_fromPython_%s' % name, None) + if fromPython: + kw[name] = dbValue = fromPython(value, self._SO_validatorState) + else: + dbValue = value + toPython = getattr(self, '_SO_toPython_%s' % name, None) + if toPython: + value = toPython(dbValue, self._SO_validatorState) setattr(self, instanceName(name), value) for name, value in extra.items(): try: @@ -805,9 +810,12 @@ dbValue = fromPython(value, self._SO_validatorState) else: dbValue = value - toUpdate[name] = dbValue + toPython = getattr(self, '_SO_toPython_%s' % name, None) + if toPython: + value = toPython(dbValue, self._SO_validatorState) if self._cacheValues: setattr(self, instanceName(name), value) + toUpdate[name] = dbValue for name, value in extra.items(): try: getattr(self.__class__, name) |