[SQL-CVS] r1193 - in home/phd/SQLObject/paramstyles: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2005-11-02 20:37:37
|
Author: phd Date: 2005-11-02 20:37:21 +0000 (Wed, 02 Nov 2005) New Revision: 1193 Added: home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py Modified: home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt home/phd/SQLObject/paramstyles/docs/index.txt home/phd/SQLObject/paramstyles/sqlobject/conftest.py home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py home/phd/SQLObject/paramstyles/sqlobject/index.py home/phd/SQLObject/paramstyles/sqlobject/main.py Log: Merged patches from the revisions 1186:1192 from the trunk Modified: home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt =================================================================== --- home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/docs/SQLBuilder.txt 2005-11-02 20:37:21 UTC (rev 1193) @@ -34,7 +34,7 @@ >>> person.first_name != name person.first_name <> 'John' >>> AND(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') Most of the operators work properly: <, >, <=, >=, !=, ==, +, -, /, \*, \*\*, %. However, ``and``, ``or``, and ``not`` **do not work**. Modified: home/phd/SQLObject/paramstyles/docs/index.txt =================================================================== --- home/phd/SQLObject/paramstyles/docs/index.txt 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/docs/index.txt 2005-11-02 20:37:21 UTC (rev 1193) @@ -19,7 +19,7 @@ * `News and updates <News.html>`_ * `Main SQLObject documentation <SQLObject.html>`_ -* `sqlbuiler documentation <SQLBuilder.html>`_ +* `sqlbuilder documentation <SQLBuilder.html>`_ * `sqlobject-admin documentation <sqlobject-admin.html>`_ * `Frequently Asked Questions <FAQ.html>`_ * `Inheritance <Inheritance.html>`_ Modified: home/phd/SQLObject/paramstyles/sqlobject/conftest.py =================================================================== --- home/phd/SQLObject/paramstyles/sqlobject/conftest.py 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/sqlobject/conftest.py 2005-11-02 20:37:21 UTC (rev 1193) @@ -10,9 +10,14 @@ import py import os import sqlobject -import pkg_resources -pkg_resources.require('SQLObject') +try: + import pkg_resources +except ImportError: # Python 2.2 + pass +else: + pkg_resources.require('SQLObject') + connectionShortcuts = { 'mysql': 'mysql://test@localhost/test', 'dbm': 'dbm:///data', Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py =================================================================== --- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-11-02 20:37:21 UTC (rev 1193) @@ -631,11 +631,19 @@ self.sqlrepr(so.id))) def _SO_selectOneAlt(self, cls, columnNames, column, value): - return self.queryOne("SELECT %s FROM %s WHERE %s = %s" % + if isinstance(column, str): + column = (column,) + value = (value,) + if len(column) != len(value): + raise ValueError, "'column' and 'value' tuples must be of the same size" + columns = [] + for i in xrange(len(column)): + columns.append("%s = %s" % (column[i], self.sqlrepr(value[i]))) + condition = ' AND '.join(columns) + return self.queryOne("SELECT %s FROM %s WHERE %s" % (", ".join(columnNames), cls.sqlmeta.table, - column, - self.sqlrepr(value))) + condition)) def _SO_delete(self, so): self.query("DELETE FROM %s WHERE %s = %s" % Modified: home/phd/SQLObject/paramstyles/sqlobject/index.py =================================================================== --- home/phd/SQLObject/paramstyles/sqlobject/index.py 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/sqlobject/index.py 2005-11-02 20:37:21 UTC (rev 1193) @@ -14,6 +14,29 @@ self.descriptions = self.convertColumns(columns) self.unique = unique + def get(self, *args, **kw): + if not self.unique: + raise AttributeError, ( + "'%s' object has no attribute 'get' (index is not unique)" % self.name) + connection = col.popKey(kw, 'connection', None) + if args and kw: + raise TypeError, "You cannot mix named and unnamed arguments" + columns = [d['column'] for d in self.descriptions + if d.has_key('column')] + if kw: + args = [] + for i in xrange(len(columns)): + args.append(kw[columns[i].name]) + del kw[columns[i].name] + if kw or len(args) != len(columns): + raise TypeError, ("get() takes exactly %d argument and an optional " + "named argument 'connection' (%d given)" % ( + len(columns), len(args)+len(kw))) + cols = [c.name for c in columns] + dbcols = [c.dbName for c in columns] + return self.soClass._SO_fetchAlternateID(cols, dbcols, args, + connection=connection, idxName=self.name) + def convertColumns(self, columns): """ Converts all the columns to dictionary descriptors; Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py =================================================================== --- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-11-02 20:33:36 UTC (rev 1192) +++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-11-02 20:37:21 UTC (rev 1193) @@ -436,7 +436,8 @@ addColumnsFromDatabase = classmethod(addColumnsFromDatabase) - def delColumn(sqlmeta, column, changeSchema=False, connection=None): + def delColumn(cls, column, changeSchema=False, connection=None): + sqlmeta = cls soClass = sqlmeta.soClass if isinstance(column, str): column = sqlmeta.columns[column] @@ -578,6 +579,7 @@ cls.indexDefinitions.append(indexDef) index = indexDef.withClass(cls.soClass) cls.indexes.append(index) + setattr(cls.soClass, index.name, index) addIndex = classmethod(addIndex) ######################################## @@ -1290,10 +1292,17 @@ value), None _findAlternateID = classmethod(_findAlternateID) - def _SO_fetchAlternateID(cls, name, dbName, value, connection=None): + def _SO_fetchAlternateID(cls, name, dbName, value, connection=None, idxName=None): result, obj = cls._findAlternateID(name, dbName, value, connection) if not result: - raise SQLObjectNotFound, "The %s by alternateID %s=%s does not exist" % (cls.__name__, name, repr(value)) + if idxName is None: + raise SQLObjectNotFound, "The %s by alternateID %s = %s does not exist" % (cls.__name__, name, repr(value)) + else: + names = [] + for i in xrange(len(name)): + names.append("%s = %s" % (name[i], repr(value[i]))) + names = ', '.join(names) + raise SQLObjectNotFound, "The %s by unique index %s(%s) does not exist" % (cls.__name__, idxName, names) if obj: return obj if connection: Copied: home/phd/SQLObject/paramstyles/sqlobject/tests/test_index_get.py (from rev 1192, SQLObject/trunk/sqlobject/tests/test_index_get.py) |