From: Mike Bayer Date: Thu, 3 Nov 2005 02:23:41 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~398 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c83a5bb072d3671f20a6d5d1c1c7aab94e4fd28;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/doc/build/content/sqlconstruction.myt b/doc/build/content/sqlconstruction.myt index d65f88510e..29b7be3746 100644 --- a/doc/build/content/sqlconstruction.myt +++ b/doc/build/content/sqlconstruction.myt @@ -1,5 +1,6 @@ <%flags>inherit='document_base.myt' <&|doclib.myt:item, name="sql", description="Constructing SQL Queries via Python Expressions" &> +

Note: This section describes how to use SQLAlchemy to construct SQL queries and receive result sets. It does not cover the object relational mapping capabilities of SQLAlchemy; that is covered later on in <&formatting.myt:link, path="datamapping"&>. However, both areas of functionality work very similarly in how selection criterion is constructed, so if you are interested just in ORM, you should probably skim through basic <&formatting.myt:link, path="sql_select_whereclause"&> construction before moving on.

Once you have used the sqlalchemy.schema module to construct your tables and/or reflect them from the database, performing SQL queries using those table meta data objects is done via the sqlalchemy.sql package. This package defines a large set of classes, each of which represents a particular kind of lexical construct within a SQL query; all are descendants of the common base class sqlalchemy.sql.ClauseElement. A full query is represented via a structure of ClauseElements. A set of reasonably intuitive creation functions is provided by the sqlalchemy.sql package to create these structures; these functions are described in the rest of this section.

To execute a query, you create its structure, then call the resulting structure's execute() method, which returns a cursor-like object (more on that later). This method can be repeated as necessary. A ClauseElement is actually compiled into a string representation by an underlying SQLEngine object; this object is located by searching through the ClauseElement structure for a Table object, which provides a reference to its SQLEngine. @@ -20,7 +21,7 @@ # a table that stores mailing addresses associated with a specific user addresses = Table('addresses', db, Column('address_id', Integer, primary_key = True), - Column('user_id', Integer, ForeignKey(users.c.user_id)), + Column('user_id', Integer, ForeignKey("users.user_id")), Column('street', String(100)), Column('city', String(80)), Column('state', String(2)),