]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merge 2684-2686 from trunk
authorJonathan Ellis <jbellis@gmail.com>
Tue, 12 Jun 2007 20:22:57 +0000 (20:22 +0000)
committerJonathan Ellis <jbellis@gmail.com>
Tue, 12 Jun 2007 20:22:57 +0000 (20:22 +0000)
README.unittests
lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/ext/sqlsoup.py
test/testbase.py

index 617d5fd6f07a04d0eb33a4f621a33621961555c5..729cd42a5d5755dec2048517a1b29f2b841aafcd 100644 (file)
@@ -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
 -----------------
index 425009f6dc70249e37c38481b12e9b28d27c68a3..0d5fc45e9e6433d7171b82405da29a88c702af45 100644 (file)
@@ -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:
index 31b5947846779a74f20d5a04f0c5f314ae91fab1..a9b93bc56414aa5dbf8b80214e5839ca33b202d6 100644 (file)
@@ -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:
index 51c5c6d7f191ba0ab29088379922d267b28a234b..29c5c8ff3419d401c09a7036a31a31c9f0181ebd 100644 (file)
@@ -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