Author: phd
Date: 2005-10-27 16:27:58 +0000 (Thu, 27 Oct 2005)
New Revision: 1154
Added:
home/phd/SQLObject/paramstyles/sqlobject/tests/test_csvexport.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py
home/phd/SQLObject/paramstyles/sqlobject/util/csvexport.py
Modified:
home/phd/SQLObject/paramstyles/docs/DeveloperGuide.txt
home/phd/SQLObject/paramstyles/docs/FAQ.txt
home/phd/SQLObject/paramstyles/docs/News.txt
home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt
home/phd/SQLObject/paramstyles/docs/SQLObject.txt
home/phd/SQLObject/paramstyles/docs/interface.py
home/phd/SQLObject/paramstyles/setup.cfg
home/phd/SQLObject/paramstyles/sqlobject/col.py
home/phd/SQLObject/paramstyles/sqlobject/conftest.py
home/phd/SQLObject/paramstyles/sqlobject/firebird/firebirdconnection.py
home/phd/SQLObject/paramstyles/sqlobject/joins.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
home/phd/SQLObject/paramstyles/sqlobject/manager/command.py
home/phd/SQLObject/paramstyles/sqlobject/maxdb/maxdbconnection.py
home/phd/SQLObject/paramstyles/sqlobject/mssql/mssqlconnection.py
home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
home/phd/SQLObject/paramstyles/sqlobject/postgres/pgconnection.py
home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py
home/phd/SQLObject/paramstyles/sqlobject/sresults.py
home/phd/SQLObject/paramstyles/sqlobject/sybase/sybaseconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py
Log:
Merged patches from revisions 1073:1150 from the trunk
Modified: home/phd/SQLObject/paramstyles/docs/DeveloperGuide.txt
===================================================================
--- home/phd/SQLObject/paramstyles/docs/DeveloperGuide.txt 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/DeveloperGuide.txt 2005-10-27 16:27:58 UTC (rev 1154)
@@ -25,7 +25,7 @@
Then do the same for SQLObject::
- $ svn co http://svn.colorstudy.com/trunk/SQLObject SQLObject
+ $ svn co http://svn.colorstudy.com/SQLObject/trunk SQLObject
$ cd SQLObject
$ sudo python setup.py develop
@@ -149,7 +149,7 @@
its `getting started`_ document for more.
.. __: http://codespeak.net/py/current/doc/test.html
-.. _getting started: http://codespeak.net/py/current/doc/getting_started.html
+.. _getting started: http://codespeak.net/py/current/doc/getting-started.html
To actually run the test, you have to give it a database to connect
to. You do this with the ``TESTDB`` environmental variable (right now
Modified: home/phd/SQLObject/paramstyles/docs/FAQ.txt
===================================================================
--- home/phd/SQLObject/paramstyles/docs/FAQ.txt 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/FAQ.txt 2005-10-27 16:27:58 UTC (rev 1154)
@@ -279,14 +279,13 @@
Non-Integer IDs
---------------
-Yes, you can use non-integer IDs, but only in CVS_ now.
+Yes, you can use non-integer IDs.
-.. _CVS: http://sqlobject.org/#anonymous-cvs
+If you use non-integer IDs, you will not be able to use automatic ``CREATE
+TABLE`` generation (i.e., ``createTable``); SQLObject can create tables
+with int or str IDs. You also will have to give your own ID values when
+creating an object, like::
-If you use non-integer IDs, you will not be able to use automatic
-``CREATE TABLE`` generation (i.e., ``createTable``). You also will
-have to give your own ID values when creating an object, like::
-
color = Something(id="blue", r=0, b=100, g=0)
IDs are, and always will in future versions, be considered immutable.
@@ -308,7 +307,7 @@
This will be resolved in a future version when ID column types can be
declared like other columns.
-Additionally you can set _idType = str in you SQLObject class.
+Additionally you can set idType=str in you SQLObject class.
Binary Values
Modified: home/phd/SQLObject/paramstyles/docs/News.txt
===================================================================
--- home/phd/SQLObject/paramstyles/docs/News.txt 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/News.txt 2005-10-27 16:27:58 UTC (rev 1154)
@@ -23,6 +23,12 @@
* Added ``TimeCol``.
+* ``RelatedJoin`` and ``SQLRelatedJoin`` objects have a
+ ``createRelatedTable`` keyword argument (default ``True``). If
+ ``False``, then the related table won't be automatically created;
+ instead you must manually create it (e.g., with explicit SQLObject
+ classes for the joins).
+
SQLObject 0.7.0
===============
Modified: home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt
===================================================================
--- home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt 2005-10-27 16:27:58 UTC (rev 1154)
@@ -3,7 +3,7 @@
``````````
A number of variables from SQLBuilder are included with ``from
-SQLObject import *`` -- see the `relevant SQLObject documentation`_
+sqlobject import *`` -- see the `relevant SQLObject documentation`_
for more. Its functionality is also available through the special
``q`` attribute of `SQLObject` classes.
@@ -20,7 +20,7 @@
of a table class -- this gives you an object that represents the
field. Maybe explanations aren't as good. Here's some examples::
- >>> from SQLBuilder import *
+ >>> from sqlobject.sqlbuilder import *
>>> person = table.person
# person is now equivalent to the Person.q object from the SQLObject
# documentation
@@ -43,7 +43,7 @@
# This isn't what you want:
>> person.first_name == 'John' & person.last_name == 'Doe'
- (person.first_name = ('John' AND person.last_name)) = 'Doe'
+ (person.first_name = ('John' AND person.last_name)) = 'Doe')
# This is:
>> (person.first_name == 'John') & (person.last_name == 'Doe')
((person.first_name = 'John') AND (person.last_name == 'Doe'))
Modified: home/phd/SQLObject/paramstyles/docs/SQLObject.txt
===================================================================
--- home/phd/SQLObject/paramstyles/docs/SQLObject.txt 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/SQLObject.txt 2005-10-27 16:27:58 UTC (rev 1154)
@@ -1396,11 +1396,12 @@
Non-Integer Keys
----------------
-While not strictly a legacy database issue, this fits into the
-category of "irregularities". If you use non-integer keys, all
-primary key management is up to you. You must create the table
-yourself, and when you create instances you must pass a ``id`` keyword
-argument into constructor (like ``Person(id='555-55-5555', ...)``).
+While not strictly a legacy database issue, this fits into the category of
+"irregularities". If you use non-integer keys, all primary key management
+is up to you. You must create the table yourself (SQLObject can create
+tables with int or str IDs), and when you create instances you must pass a
+``id`` keyword argument into constructor
+(like ``Person(id='555-55-5555', ...)``).
DBConnection: Database Connections
==================================
@@ -1667,6 +1668,15 @@
and ALL(). The last 3 are used with comparison operators, like this:
"somevalue = ANY(Select(...))".
+Utilities
+---------
+
+Some useful utility functions are included with SQLObject. For more
+information see their module docstrings.
+
+* `sqlobject.util.csvexport
+ <http://sqlobject.org/module-sqlobject.util.csvexport.html>`_
+
SQLBuilder
----------
Modified: home/phd/SQLObject/paramstyles/docs/interface.py
===================================================================
--- home/phd/SQLObject/paramstyles/docs/interface.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/docs/interface.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -254,7 +254,22 @@
Adds the index to the class.
"""
+ def asDict():
+ """
+ Returns the SQLObject instance as a dictionary (column names
+ as keys, column values as values).
+ Use like::
+
+ ASQLObjectClass(a=1, b=2).asDict()
+
+ Which should return ``{'a': 1, 'b': 2}``.
+
+ Note: this is a *copy* of the object's columns; changing the
+ dictionary will not effect the object it was created from.
+ """
+
+
class ICol(Interface):
def __init__(name=None, **kw):
Modified: home/phd/SQLObject/paramstyles/setup.cfg
===================================================================
--- home/phd/SQLObject/paramstyles/setup.cfg 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/setup.cfg 2005-10-27 16:27:58 UTC (rev 1154)
@@ -31,5 +31,9 @@
[publish]
doc-dir = docs/html
-doc-dest = scp://ianbicking@shell.sf.net/home/groups/s/sq/sqlobject/htdocs/
make-dirs = 1
+
+## For live documentation:
+# doc-dest = scp://ianbicking@shell.sf.net/home/groups/s/sq/sqlobject/htdocs/
+## For in-development documentation:
+doc-dest = scp://ianbicking@shell.sf.net/home/groups/s/sq/sqlobject/htdocs/devel/
Modified: home/phd/SQLObject/paramstyles/sqlobject/col.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/col.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/col.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -687,31 +687,22 @@
class SOKeyCol(SOCol):
+ key_type = {int: "INT", str: "TEXT"}
# 3-03 @@: this should have a simplified constructor
# Should provide foreign key information for other DBs.
- def _mysqlType(self):
- return 'INT'
+ def _sqlType(self):
+ return self.key_type[self.soClass.sqlmeta.idType]
- def _sqliteType(self):
- return 'INT'
-
- def _postgresType(self):
- return 'INT'
-
def _sybaseType(self):
- return 'NUMERIC(18,0) NULL'
+ key_type = {int: "NUMERIC(18,0) NULL", str: "TEXT"}
+ return key_type[self.soClass.sqlmeta.idType]
def _mssqlType(self):
- return 'INT NULL'
+ key_type = {int: "INT NULL", str: "TEXT"}
+ return key_type[self.soClass.sqlmeta.idType]
- def _firebirdType(self):
- return 'INT'
-
- def _maxdbType(self):
- return 'INT'
-
class KeyCol(Col):
baseClass = SOKeyCol
@@ -758,6 +749,31 @@
'sTName': sTName})
return constraint
+ def mysqlCreateSQL(self):
+ sql = SOKeyCol.mysqlCreateSQL(self)
+ other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ if self.cascade is not None:
+ if self.cascade == 'null':
+ action = 'ON DELETE SET NULL'
+ elif self.cascade:
+ action = 'ON DELETE CASCADE'
+ else:
+ action = 'ON DELETE RESTRICT'
+ else:
+ action = ''
+ constraint = ('CONSTRAINT %(colName)s_exists '
+ 'FOREIGN KEY (%(colName)s) '
+ 'REFERENCES %(tName)s (%(idName)s) '
+ '%(action)s' %
+ {'tName': tName,
+ 'colName': self.dbName,
+ 'idName': idName,
+ 'action': action})
+ sql = ', '.join([sql, constraint])
+ return sql
+
def sybaseCreateSQL(self):
sql = SOKeyCol.sybaseCreateSQL(self)
other = findClass(self.foreignKey)
Modified: home/phd/SQLObject/paramstyles/sqlobject/conftest.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/conftest.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/conftest.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -17,7 +17,7 @@
'postgres': 'postgres:///test',
'postgresql': 'postgres:///test',
'pygresql': 'pygresql://localhost/test',
- 'sqlite': 'sqlite:///%s/data/sqlite.data' % os.getcwd(),
+ 'sqlite': 'sqlite:/:memory:',
'sybase': 'sybase://test:test123@sybase/test?autoCommit=0',
'firebird': 'firebird://sysdba:masterkey@localhost/var/lib/firebird/data/test.gdb',
'mssql': 'mssql://sa:@127.0.0.1/test'
Modified: home/phd/SQLObject/paramstyles/sqlobject/firebird/firebirdconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/firebird/firebirdconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/firebird/firebirdconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -131,7 +131,8 @@
return col.firebirdCreateSQL()
def createIDColumn(self, soClass):
- return '%s INT NOT NULL PRIMARY KEY' % soClass.sqlmeta.idName
+ key_type = {int: "INT", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s NOT NULL PRIMARY KEY' % (soClass.sqlmeta.idName, key_type)
def createIndexSQL(self, soClass, index):
return index.firebirdCreateIndexSQL(soClass)
Modified: home/phd/SQLObject/paramstyles/sqlobject/joins.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/joins.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/joins.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -154,9 +154,12 @@
def __init__(self,
otherColumn=None,
- intermediateTable=None, **kw):
+ intermediateTable=None,
+ createRelatedTable=True,
+ **kw):
self.intermediateTable = intermediateTable
self.otherColumn = otherColumn
+ self.createRelatedTable = createRelatedTable
SOMultipleJoin.__init__(self, **kw)
classregistry.registry(
self.soClass.sqlmeta.registry).addClassCallback(
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -7,15 +7,17 @@
SQLObject is a object-relational mapper. See SQLObject.html or
SQLObject.txt for more.
-Modified by
+Modified by:
- Daniel Savard, Xsoli Inc <sqlobject xsoli.com> 7 Feb 2004
- - Added support for simple table inheritance.
+* Daniel Savard, Xsoli Inc <sqlobject xsoli.com> 7 Feb 2004
+ Added support for simple table inheritance.
- Oleg Broytmann, SIA "ANK" <ph...@ph...> 3 Feb 2005
- - Split inheritance support into a number of separate modules and classes -
- InheritableSQLObject at al.
+* Oleg Broytmann, SIA "ANK" <ph...@ph...> 3 Feb 2005
+ Split inheritance support into a number of separate modules and classes -
+ InheritableSQLObject at al.
+* And others...
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
@@ -562,6 +564,16 @@
cls.indexes.append(index)
addIndex = classmethod(addIndex)
+ ########################################
+ ## Utility methods
+ ########################################
+
+ def asDict(self):
+ result = {}
+ for key in self.columns:
+ result[key] = getattr(self.instance, key)
+ return result
+
sqlhub = dbconnection.ConnectionHub()
class _sqlmeta_attr(object):
@@ -1329,6 +1341,9 @@
def createJoinTables(cls, ifNotExists=False, connection=None):
conn = connection or cls._connection
for join in cls._getJoinsToCreate():
+ if not getattr(join, 'createRelatedTable', True):
+ # This join has requested not to be created
+ continue
if (ifNotExists and
conn.tableExists(join.intermediateTable)):
continue
@@ -1339,6 +1354,9 @@
conn = connection or cls._connection
sql = []
for join in cls._getJoinsToCreate():
+ if not getattr(join, 'createRelatedTable', True):
+ # This join has requested not to be created
+ continue
sql.append(conn._SO_createJoinTableSQL(join))
return '\n'.join(sql)
createJoinTablesSQL = classmethod(createJoinTablesSQL)
Modified: home/phd/SQLObject/paramstyles/sqlobject/manager/command.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/manager/command.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/manager/command.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -427,7 +427,7 @@
if not dist.has_metadata('sqlobject.txt'):
if warn_no_sqlobject:
print 'No sqlobject.txt in %s egg info' % egg_spec
- return {}
+ return None, {}
result = {}
for line in dist.get_metadata_lines('sqlobject.txt'):
line = line.strip()
@@ -436,7 +436,7 @@
name, value = line.split('=', 1)
name = name.strip().lower()
if name in result:
- print 'Warning: %s appears more than one in sqlobject.txt' % name
+ print 'Warning: %s appears more than once in sqlobject.txt' % name
result[name.strip().lower()] = value.strip()
return dist, result
@@ -859,6 +859,12 @@
+ '_' + dbName + '.sql')
if sim:
continue
+ create, constraints = cls.createTableSQL()
+ if constraints:
+ constraints = '\n-- Constraints:\n%s\n' % (
+ '\n'.join(constraints))
+ else:
+ constraints = ''
files[fn] = ''.join([
'-- Exported definition from %s\n'
% time.strftime('%Y-%m-%dT%H:%M:%S'),
@@ -866,8 +872,9 @@
% (cls.__module__, cls.__name__),
'-- Database: %s\n'
% dbName,
- cls.createTableSQL().strip(),
- '\n'])
+ create.strip(),
+ '\n',
+ constraints])
last_version_dir = self.find_last_version()
if last_version_dir and not self.options.force_create:
if v > 1:
Modified: home/phd/SQLObject/paramstyles/sqlobject/maxdb/maxdbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/maxdb/maxdbconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/maxdb/maxdbconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -1,16 +1,17 @@
"""
-Contributed by Edigram SAS,Paris France
-Tel:01 44 77 94 00
+Contributed by Edigram SAS, Paris France Tel:01 44 77 94 00
Ahmed MOHAMED ALI <ahm...@ya...> 27 April 2004
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-connection creation sample
-__connection__ = DBConnection.maxdbConnection(
- host=hostname, database=dbname,
- user=user_name, password=user_password,autoCommit=1,debug=1)
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+connection creation sample::
+
+ __connection__ = DBConnection.maxdbConnection(
+ host=hostname, database=dbname,
+ user=user_name, password=user_password,autoCommit=1,debug=1)
"""
from sqlobject.dbconnection import DBAPI
from sqlobject import col
@@ -172,7 +173,8 @@
return col.maxdbCreateSQL()
def createIDColumn(self, soClass):
- return '%s INT PRIMARY KEY' % soClass.sqlmeta.idName
+ key_type = {int: "INT", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s PRIMARY KEY' % (soClass.sqlmeta.idName, key_type)
def createIndexSQL(self, soClass, index):
return index.maxdbCreateIndexSQL(soClass)
Modified: home/phd/SQLObject/paramstyles/sqlobject/mssql/mssqlconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/mssql/mssqlconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/mssql/mssqlconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -72,7 +72,7 @@
def _hasIdentity(self, conn, table):
query = self.HAS_IDENTITY % table
c = conn.cursor()
- DBAPI._executeRetry(self, conn, c, query)
+ c.execute(query)
r = c.fetchone()
return r is not None
@@ -105,7 +105,7 @@
q = self._insertSQL(table, names, values)
if self.debug:
print 'QueryIns: %s' % q
- DBAPI._executeRetry(self, conn, c, q)
+ c.execute(q)
if has_identity:
c.execute('SET IDENTITY_INSERT %s OFF' % table)
@@ -129,7 +129,8 @@
return col.mssqlCreateSQL()
def createIDColumn(self, soClass):
- return '%s INT IDENTITY UNIQUE' % soClass.sqlmeta.idName
+ key_type = {int: "INT", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s IDENTITY UNIQUE' % (soClass.sqlmeta.idName, key_type)
def createIndexSQL(self, soClass, index):
return index.mssqlCreateIndexSQL(soClass)
@@ -212,7 +213,7 @@
if auto == 0:
option = "OFF"
c = conn.cursor()
- c.execute("SET AUTOCOMMIT " + option)
+ c.execute("SET AUTOCOMMIT "+option)
conn.setconnectoption(SQL.AUTOCOMMIT, option)
def guessClass(self, t, size):
Modified: home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -99,6 +99,8 @@
return index.mysqlCreateIndexSQL(soClass)
def createIDColumn(self, soClass):
+ if soClass.sqlmeta.idType == str:
+ return '%s TEXT PRIMARY KEY' % soClass.sqlmeta.idName
return '%s INT PRIMARY KEY AUTO_INCREMENT' % soClass.sqlmeta.idName
def joinSQLType(self, join):
Modified: home/phd/SQLObject/paramstyles/sqlobject/postgres/pgconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/postgres/pgconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/postgres/pgconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -145,7 +145,8 @@
return index.postgresCreateIndexSQL(soClass)
def createIDColumn(self, soClass):
- return '%s SERIAL PRIMARY KEY' % soClass.sqlmeta.idName
+ key_type = {int: "SERIAL", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s PRIMARY KEY' % (soClass.sqlmeta.idName, key_type)
def dropTable(self, tableName, cascade=False):
if self.server_version[:3] <= "7.2":
@@ -248,7 +249,7 @@
def guessClass(self, t):
if t.count('int'):
return col.IntCol, {}
- elif t.count('varying'):
+ elif t.count('varying') or t.count('varchar'):
if '(' in t:
return col.StringCol, {'length': int(t[t.index('(')+1:-1])}
else: # varchar without length in Postgres means any length
@@ -256,10 +257,16 @@
elif t.startswith('character('):
return col.StringCol, {'length': int(t[t.index('(')+1:-1]),
'varchar': False}
+ elif t.count('float') or t.count('real') or t.count('double'):
+ return col.FloatCol, {}
elif t == 'text':
return col.StringCol, {}
+ elif t.startswith('timestamp'):
+ return col.DateTimeCol, {}
elif t.startswith('datetime'):
return col.DateTimeCol, {}
+ elif t.startswith('date'):
+ return col.DateCol, {}
elif t.startswith('bool'):
return col.BoolCol, {}
elif t.startswith('bytea'):
Modified: home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -120,7 +120,8 @@
return None
def createIDColumn(self, soClass):
- return '%s INTEGER PRIMARY KEY' % soClass.sqlmeta.idName
+ key_type = {int: "INTEGER", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s PRIMARY KEY' % (soClass.sqlmeta.idName, key_type)
def joinSQLType(self, join):
return 'INT NOT NULL'
Modified: home/phd/SQLObject/paramstyles/sqlobject/sresults.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/sresults.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/sresults.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -91,7 +91,13 @@
self.clauseTables, **self.ops)
def filter(self, filter_clause):
- return self.newClause(sqlbuilder.AND(self.clause, filter_clause))
+ if filter_clause is None:
+ # None doesn't filter anything, it's just a no-op:
+ return self
+ clause = self.clause
+ if isinstance(clause, (str, unicode)):
+ clause = sqlbuilder.SQLConstant('(%s)' % self.clause)
+ return self.newClause(sqlbuilder.AND(clause, filter_clause))
def __getitem__(self, value):
if type(value) is type(slice(1)):
Modified: home/phd/SQLObject/paramstyles/sqlobject/sybase/sybaseconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/sybase/sybaseconnection.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/sybase/sybaseconnection.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -102,7 +102,8 @@
return col.sybaseCreateSQL()
def createIDColumn(self, soClass):
- return '%s NUMERIC(18,0) IDENTITY UNIQUE' % soClass.sqlmeta.idName
+ key_type = {int: "NUMERIC(18,0)", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s IDENTITY UNIQUE' % (soClass.sqlmeta.idName, key_type)
def createIndexSQL(self, soClass, index):
return index.sybaseCreateIndexSQL(soClass)
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -211,15 +211,17 @@
def d(**kw):
"""
- Because dict(**kw) doesn't work in Python 2.2, this is a
+ Because ``dict(**kw)`` doesn't work in Python 2.2, this is a
replacement.
"""
return kw
def inserts(cls, data, schema=None):
"""
- Creates a bunch of rows. You can use it like::
+ Creates a bunch of rows.
+ You can use it like::
+
inserts(Person, [{'fname': 'blah', 'lname': 'doe'}, ...])
Or::
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py 2005-10-27 16:24:26 UTC (rev 1153)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py 2005-10-27 16:27:58 UTC (rev 1154)
@@ -275,3 +275,9 @@
assert dep1.other is None
assert dep2.other is None
assert dep3.other is obj2
+
+def testAsDict():
+ setupGetters(TestSO1)
+ bob = TestSO1.selectBy(name='bob')[0]
+ assert bob.sqlmeta.asDict() == {'passwd': 'tbq', 'name': 'bob'}
+
Copied: home/phd/SQLObject/paramstyles/sqlobject/tests/test_csvexport.py (from rev 1150, SQLObject/trunk/sqlobject/tests/test_csvexport.py)
Copied: home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py (from rev 1150, SQLObject/trunk/sqlobject/tests/test_string_id.py)
Copied: home/phd/SQLObject/paramstyles/sqlobject/util/csvexport.py (from rev 1150, SQLObject/trunk/sqlobject/util/csvexport.py)
|