From: Jonathan Ellis Date: Tue, 12 Jun 2007 20:22:57 +0000 (+0000) Subject: merge 2684-2686 from trunk X-Git-Tag: rel_0_4_6~205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32310c713feb8825d957072f98cfb952c5d15d75;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git merge 2684-2686 from trunk --- diff --git a/README.unittests b/README.unittests index 617d5fd6f0..729cd42a5d 100644 --- a/README.unittests +++ b/README.unittests @@ -9,13 +9,19 @@ Python 2.4 or greater is required since the unit tests use decorators. cd into the SQLAlchemy distribution directory. -Set up the PYTHONPATH: +Set up the PYTHONPATH. In bash: export PYTHONPATH=./test/ -The unittest framework will automatically prepend './lib/' to sys.path. this forces the local -version of SQLAlchemy to be used, bypassing any setuptools-installed installations -(setuptools places .egg files ahead of plain directories, even if on PYTHONPATH, unfortunately). +On windows: + + set PYTHONPATH=test\ + +The unittest framework will automatically prepend the lib directory to +sys.path. This forces the local version of SQLAlchemy to be used, +bypassing any setuptools-installed installations (setuptools places +.egg files ahead of plain directories, even if on PYTHONPATH, +unfortunately). RUNNING ALL TESTS ----------------- diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 425009f6dc..0d5fc45e9e 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -151,10 +151,10 @@ class SQLiteDialect(ansisql.ANSIDialect): self.supports_cast = (self.dbapi is None or vers(self.dbapi.sqlite_version) >= vers("3.2.3")) if self.dbapi is not None: sqlite_ver = self.dbapi.version_info - if sqlite_ver < (2,2) and sqlite_ver != (2,1,'3'): - warnings.warn(RuntimeWarning("The installed version of pysqlite2 is out-dated, and will cause errors in some cases. Version 2.1.3 or greater is recommended.")) + if sqlite_ver < (2,1,'3'): + warnings.warn(RuntimeWarning("The installed version of pysqlite2 (%s) is out-dated, and will cause errors in some cases. Version 2.1.3 or greater is recommended." % '.'.join([str(subver) for subver in sqlite_ver]))) if vers(self.dbapi.sqlite_version) < vers("3.3.13"): - warnings.warn(RuntimeWarning("The installed version of sqlite is out-dated, and will cause errors in some cases. Version 3.3.13 or greater is recommended.")) + warnings.warn(RuntimeWarning("The installed version of sqlite (%s) is out-dated, and will cause errors in some cases. Version 3.3.13 or greater is recommended." % self.dbapi.sqlite_version)) def dbapi(cls): try: diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index 31b5947846..a9b93bc564 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -65,12 +65,17 @@ single column. This allows using keyword arguments as column names:: >>> db.users.selectone_by(name='Bhargan Basepair') MappedUsers(name='Bhargan Basepair',email='basepair@example.edu',password='basepair',classname=None,admin=1) +Since name is the primary key, this is equivalent to + + >>> db.users.get('Bhargan Basepair') + MappedUsers(name='Bhargan Basepair',email='basepair@example.edu',password='basepair',classname=None,admin=1) + Select variants --------------- All the SQLAlchemy Query select variants are available. Here's a -quick summary of these methods:: +quick summary of these methods: - ``get(PK)``: load a single object identified by its primary key (either a scalar, or a tuple) @@ -101,7 +106,7 @@ for general info and examples, `sql construction`__ for details on constructing ``WHERE`` clauses. __ http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_query -__http://www.sqlalchemy.org/docs/sqlconstruction.myt +__ http://www.sqlalchemy.org/docs/sqlconstruction.myt Modifying objects @@ -241,11 +246,22 @@ mapping a Select is reusability, both standalone and in Joins. (And if you go to full SQLAlchemy, you can perform mappings like this directly to your object models.) +An easy way to save mapped selectables like this is to just hang them on +your db object:: + + >>> db.years_with_count = years_with_count + +Python is flexible like that! + Raw SQL ------- -You can access the SqlSoup's `engine` attribute to compose SQL +SqlSoup works fine with SQLAlchemy's `text block support`__. + +__ http://www.sqlalchemy.org/docs/documentation.myt#sql_textual + +You can also access the SqlSoup's `engine` attribute to compose SQL directly. The engine's ``execute`` method corresponds to the one of a DBAPI cursor, and returns a ``ResultProxy`` that has ``fetch`` methods you would also see on a cursor:: @@ -271,7 +287,7 @@ Boring tests here. Nothing of real expository value. >>> db.nopk Traceback (most recent call last): ... - PKNotFoundError: table 'nopk' does not have a primary key defined + PKNotFoundError: table 'nopk' does not have a primary key defined [columns: i] >>> db.nosuchtable Traceback (most recent call last): @@ -302,7 +318,7 @@ from sqlalchemy.exceptions import * _testsql = """ CREATE TABLE books ( - id integer PRIMARY KEY, -- auto-SERIAL in sqlite + id integer PRIMARY KEY, -- auto-increments in sqlite title text NOT NULL, published_year char(4) NOT NULL, authors text NOT NULL @@ -452,12 +468,12 @@ def class_for_table(selectable, **mapper_kwargs): for m in ['__cmp__', '__repr__']: setattr(klass, m, eval(m)) klass._table = selectable - klass._mapper = mapper(klass, - selectable, - extension=objectstore.mapper_extension, - allow_null_pks=_is_outer_join(selectable), - **mapper_kwargs) - klass._query = Query(klass._mapper) + mappr = mapper(klass, + selectable, + extension=objectstore.mapper_extension, + allow_null_pks=_is_outer_join(selectable), + **mapper_kwargs) + klass._query = Query(mappr) return klass class SqlSoup: @@ -516,7 +532,7 @@ class SqlSoup: except KeyError: table = Table(attr, self._metadata, autoload=True, schema=self.schema) if not table.primary_key.columns: - raise PKNotFoundError('table %r does not have a primary key defined' % attr) + raise PKNotFoundError('table %r does not have a primary key defined [columns: %s]' % (attr, ','.join(table.c.keys()))) if table.columns: t = class_for_table(table) else: diff --git a/test/testbase.py b/test/testbase.py index 51c5c6d7f1..29c5c8ff34 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -3,9 +3,9 @@ instruments SQLAlchemy dialect/engine to track SQL statements for assertion purp provides base test classes for common test scenarios.""" import sys -sys.path.insert(0, './lib/') import os, unittest, StringIO, re, ConfigParser, optparse +sys.path.insert(0, os.path.join(os.getcwd(), 'lib')) import sqlalchemy from sqlalchemy import sql, engine, pool, BoundMetaData from sqlalchemy.orm import clear_mappers