summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
Commit message (Collapse)AuthorAgeFilesLines
* workaround for #2838 here. still need to figure out why an ENUM test is ↵Mike Bayer2013-10-141-0/+7
| | | | suddenly hitting this.
* - Fixed bug in default compiler plus those of postgresql, mysql, andMike Bayer2013-10-121-3/+4
| | | | | | | | | | | mssql to ensure that any literal SQL expression values are rendered directly as literals, instead of as bound parameters, within a CREATE INDEX statement. [ticket:2742] - don't need expression_as_ddl(); literal_binds and include_table take care of this functionality. Conflicts: lib/sqlalchemy/sql/util.py
* added "system=True" to Column, so that we generally don't have to botherMike Bayer2013-08-251-0/+3
| | | | with CreateColumn rules
* - The :class:`.CreateColumn` construct can be appled to a customMike Bayer2013-08-241-3/+5
| | | | | | | | | compilation rule which allows skipping of columns, by producing a rule that returns ``None``. Also in 0.8.3. Conflicts: doc/build/changelog/changelog_09.rst lib/sqlalchemy/sql/ddl.py
* Fixed regression dating back to 0.7.9 whereby the name of a CTE mightMike Bayer2013-08-181-1/+1
| | | | | | | | not be properly quoted if it was referred to in multiple FROM clauses. Also in 0.8.3, 0.7.11. [ticket:2801] Conflicts: doc/build/changelog/changelog_09.rst
* - Fixed bug in common table expression system where if the CTE wereMike Bayer2013-07-311-8/+14
| | | | | | used only as an ``alias()`` construct, it would not render using the WITH keyword. Also in 0.7.11. [ticket:2783]
* Fixed bug where the expression system relied upon the ``str()``Mike Bayer2013-07-121-2/+6
| | | | | | | | | | | | form of a some expressions when referring to the ``.c`` collection on a ``select()`` construct, but the ``str()`` form isn't available since the element relies on dialect-specific compilation constructs, notably the ``__getitem__()`` operator as used with a Postgresql ``ARRAY`` element. The fix also adds a new exception class :class:`.UnsupportedCompilationError` which is raised in those cases where a compiler is asked to compile something it doesn't know how to. [ticket:2780]
* - Added new method to the :func:`.insert` constructMike Bayer2013-07-051-1/+3
| | | | | | | | | | :meth:`.Insert.from_select`. Given a list of columns and a selectable, renders ``INSERT INTO (table) (columns) SELECT ..``. While this feature is highlighted as part of 0.9 it is also backported to 0.8.3. [ticket:722] - The :func:`.update`, :func:`.insert`, and :func:`.delete` constructs will now interpret ORM entities as FROM clauses to be operated upon, in the same way that select() already does.
* Fixed bug when using multi-table UPDATE where a supplementalMike Bayer2013-07-021-2/+2
| | | | | | | table is a SELECT with its own bound parameters, where the positioning of the bound parameters would be reversed versus the statement itself when using MySQL's special syntax. [ticket:2768]
* - rework of correlation, continuing on #2668, #2746Mike Bayer2013-06-261-22/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - add support for correlations to propagate all the way in; because correlations require context now, need to make sure a select enclosure of any level takes effect any number of levels deep. - fix what we said correlate_except() was supposed to do when we first released #2668 - "the FROM clause is left intact if the correlated SELECT is not used in the context of an enclosing SELECT..." - it was not considering the "existing_froms" collection at all, and prohibited additional FROMs from being placed in an any() or has(). - add test for multilevel any() - lots of docs, including glossary entries as we really need to define "WHERE clause", "columns clause" etc. so that we can explain correlation better - based on the insight that a SELECT can correlate anything that ultimately came from an enclosing SELECT that links to this one via WHERE/columns/HAVING/ORDER BY, have the compiler keep track of the FROM lists that correspond in this way, link it to the asfrom flag, so that we send to _get_display_froms() the exact list of candidate FROMs to correlate. no longer need any asfrom logic in the Select() itself - preserve 0.8.1's behavior for correlation when no correlate options are given, not to mention 0.7 and prior's behavior of not propagating implicit correlation more than one level.. this is to reduce surprises/hard-to-debug situations when a user isn't trying to correlate anything. Conflicts: doc/build/changelog/changelog_08.rst doc/build/changelog/changelog_09.rst lib/sqlalchemy/sql/compiler.py
* A major fix to the way in which a select() object producesMike Bayer2013-04-111-16/+18
| | | | | | | | | | | | | | | | | | | labeled columns when apply_labels() is used; this mode produces a SELECT where each column is labeled as in <tablename>_<columnname>, to remove column name collisions for a multiple table select. The fix is that if two labels collide when combined with the table name, i.e. "foo.bar_id" and "foo_bar.id", anonymous aliasing will be applied to one of the dupes. This allows the ORM to handle both columns independently; previously, 0.7 would in some cases silently emit a second SELECT for the column that was "duped", and in 0.8 an ambiguous column error would be emitted. The "keys" applied to the .c. collection of the select() will also be deduped, so that the "column being replaced" warning will no longer emit for any select() that specifies use_labels, though the dupe key will be given an anonymous label which isn't generally user-friendly. [ticket:2702]
* merge plus fix the test spelling tooMike Bayer2013-03-181-1/+1
|\
| * Fix typo.Richard Mitchell2013-03-181-1/+1
| |
* | no need to use getattr() hereMike Bayer2013-03-171-3/+3
|/
* Changed behavior of Select.correlate() to ignore correlations to froms that ↵Luke Cyca2013-03-071-7/+2
| | | | don't exist in the superquery.
* #2629Mike Bayer2013-01-251-0/+5
| | | | | insert().returning() raises an informative CompileError if attempted to compile on a dialect that doesn't support RETURNING.
* :class:`.Index` now supports arbitrary SQL expressions and/orMike Bayer2013-01-161-15/+26
| | | | | | | | functions, in addition to straight columns. Common modifiers include using ``somecolumn.desc()`` for a descending index and ``func.lower(somecolumn)`` for a case-insensitive index, depending on the capabilities of the target backend. [ticket:695]
* Tweaked the "REQUIRED" symbol used by the compiler to identifyMike Bayer2013-01-081-5/+14
| | | | | | INSERT/UPDATE bound parameters that need to be passed, so that it's more easily identifiable when writing custom bind-handling code. [ticket:2648]
* happy new year (see #2645)Diana Clarke2013-01-011-1/+1
|
* internally at least refer to multirow as "multivalues", to distinguish betweenMike Bayer2012-12-081-1/+1
| | | | | an INSERT that's used in executemany() as opposed to one which has a VALUES clause with multiple entries.
* - multivalued inserts, [ticket:2623]Mike Bayer2012-12-081-70/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - update "not supported" messages for empty inserts, mutlivalue inserts - rework the ValuesBase approach for multiple value sets so that stmt.parameters does store a list for multiple values; the _has_multiple_parameters flag now indicates which of the two modes the statement is within. it now raises exceptions if a subsequent call to values() attempts to call a ValuesBase with one mode in the style of the other mode; that is, you can't switch a single- or multi- valued ValuesBase to the other mode, and also if a multiple value is passed simultaneously with a kwargs set. Added tests for these error conditions - Calling values() multiple times in multivalue mode now extends the parameter list to include the new parameter sets. - add error/test if multiple *args were passed to ValuesBase.values() - rework the compiler approach for multivalue inserts, back to where _get_colparams() returns the same list of (column, value) as before, thereby maintaining the identical number of append() and other calls when multivalue is not enabled. In the case of multivalue, it makes a last-minute switch to return a list of lists instead of the single list. As it constructs the additional lists, the inline defaults and other calculated default parameters of the first parameter set are copied into the newly generated lists so that these features continue to function for a multivalue insert. Multivalue inserts now add no additional function calls to the compilation for regular insert constructs. - parameter lists for multivalue inserts now includes an integer index for all parameter sets. - add detailed documentation for ValuesBase.values(), including careful wording to describe the difference between multiple values and an executemany() call. - add a test for multivalue insert + returning - it works ! - remove the very old/never used "postgresql_returning"/"firebird_returning" flags.
* merge latest defaultMike Bayer2012-12-081-1/+9
|\
| * visit_DECIMAL should include precision and scale (when provided) just like ↵Diana Clarke2012-12-031-1/+9
| | | | | | | | visit_NUMERIC see #2618
* | compiler: add support for multirow insertsIdan Kamara2012-12-061-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some databases support this syntax for inserts: INSERT INTO table (id, name) VALUES ('v1', 'v2'), ('v3', 'v4'); which greatly increases INSERT speed. It is now possible to pass a list of lists/tuples/dictionaries as the values param to the Insert construct. We convert it to a flat dictionary so we can continue using bind params. The above query will be converted to: INSERT INTO table (id, name) VALUES (:id, :name), (:id0, :name0); Currently only supported on postgresql, mysql and sqlite.
* | compiler: adjust _get_colparams to return the columns and parameters in ↵Idan Kamara2012-12-051-50/+49
|/ | | | separate lists
* just a pep8 pass of lib/sqlalchemy/sql/Diana Clarke2012-11-191-65/+62
|
* improve some autodoc linksMike Bayer2012-10-311-4/+4
|
* Fixed bug where keyword arguments passed toMike Bayer2012-10-241-3/+11
| | | | | | | | :meth:`.Compiler.process` wouldn't get propagated to the column expressions present in the columns clause of a SELECT statement. In particular this would come up when used by custom compilation schemes that relied upon special flags. [ticket:2593]
* The auto-correlation feature of :func:`.select`, andMike Bayer2012-10-221-1/+6
| | | | | | | | | by proxy that of :class:`.orm.Query`, will not take effect for a SELECT statement that is being rendered directly in the FROM list of the enclosing SELECT. Correlation in SQL only applies to column expressions such as those in the WHERE, ORDER BY, columns clause. [ticket:2595]
* - [feature] The Query can now load entity/scalar-mixedMike Bayer2012-10-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | "tuple" rows that contain types which aren't hashable, by setting the flag "hashable=False" on the corresponding TypeEngine object in use. Custom types that return unhashable types (typically lists) can set this flag to False. [ticket:2592] - [bug] Applying a column expression to a select statement using a label with or without other modifying constructs will no longer "target" that expression to the underlying Column; this affects ORM operations that rely upon Column targeting in order to retrieve results. That is, a query like query(User.id, User.id.label('foo')) will now track the value of each "User.id" expression separately instead of munging them together. It is not expected that any users will be impacted by this; however, a usage that uses select() in conjunction with query.from_statement() and attempts to load fully composed ORM entities may not function as expected if the select() named Column objects with arbitrary .label() names, as these will no longer target to the Column objects mapped by that entity. [ticket:2591]
* - [feature] Added "collation" parameter to allMike Bayer2012-10-101-9/+20
| | | | | | | | | | | String types. When present, renders as COLLATE <collation>. This to support the COLLATE keyword now supported by several databases including MySQL, SQLite, and Postgresql. [ticket:2276] - [change] The Text() type renders the length given to it, if a length was specified.
* - [feature] Various API tweaks to the "dialect"Mike Bayer2012-10-081-3/+6
| | | | | | | API to better support highly specialized systems such as the Akiban database, including more hooks to allow an execution context to access type processors.
* - fix the fixture here that wasn't creating consistentlyMike Bayer2012-10-011-0/+3
| | | | | | | - rewrite --dropfirst to be more industrial strength, includes views - fix order_by="foreign_key" to maintain the same ordering as metadata.sorted_tables. Not ideal that this was the other way throughout 0.7 but this is still a little-used method, in contrast to metadata.sorted_tables.
* spacingMike Bayer2012-09-301-5/+5
|
* - [bug] Fixed bug in over() construct wherebyMike Bayer2012-09-301-11/+11
| | | | | | | | passing an empty list for either partition_by or order_by, as opposed to None, would fail to generate correctly. Courtesy Gunnlaugur Por Briem. [ticket:2574]
* - [bug] The CreateIndex construct in OracleMike Bayer2012-09-301-5/+11
| | | | | | | | will now schema-qualify the name of the index to be that of the parent table. Previously this name was omitted which apparently creates the index in the default schema, rather than that of the table.
* - [bug] Fixed the DropIndex construct to supportMike Bayer2012-09-241-7/+17
| | | | | an Index associated with a Table in a remote schema. [ticket:2571]
* - [feature] Added a hook to the system of renderingMike Bayer2012-09-091-10/+23
| | | | | | | CREATE TABLE that provides access to the render for each Column individually, by constructing a @compiles function against the new schema.CreateColumn construct. [ticket:2463]
* - type expressions invoke in SQL, but are only for the benefit of columnsMike Bayer2012-09-031-8/+6
| | | | | | delivered to a result set. therefore these expressions should only be rendered for those columns that are being delivered to the result, thereby preventing the expression from stacking onto itself within nesting scenarios.
* - repair type expressions for columns when we aren't using ↵Mike Bayer2012-09-011-2/+5
| | | | | | select.apply_labels(), label should be the column name.
* - [feature] Reworked the startswith(), endswith(),Mike Bayer2012-08-271-1/+45
| | | | | | | | | | | | contains() operators to do a better job with negation (NOT LIKE), and also to assemble them at compilation time so that their rendered SQL can be altered, such as in the case for Firebird STARTING WITH [ticket:2470] - [feature] firebird - The "startswith()" operator renders as "STARTING WITH", "~startswith()" renders as "NOT STARTING WITH", using FB's more efficient operator. [ticket:2470]
* - more oracle tweaks for returning; the method here is still kind of brittle ↵Mike Bayer2012-08-251-1/+3
| | | | | | and might have issues with pks, multiple function calls
* a few oracle fixesMike Bayer2012-08-251-2/+3
|
* - [bug] Fixed bug whereby usage of a UNIONMike Bayer2012-08-221-7/+11
| | | | | | | | or similar inside of an embedded subquery would interfere with result-column targeting, in the case that a result-column had the same ultimate name as a name inside the embedded UNION. [ticket:2552]
* - [bug] Fixed cextension bug whereby theMike Bayer2012-08-221-29/+35
| | | | | | | | | | | | | | | | | | | "ambiguous column error" would fail to function properly if the given index were a Column object and not a string. Note there are still some column-targeting issues here which are fixed in 0.8. [ticket:2553] - find more cases where column targeting is being inaccurate, add more information to result_map to better differentiate "ambiguous" results from "present" or "not present". In particular, result_map is sensitive to dupes, even though no error is raised; the conflicting columns are added to the "obj" member of the tuple so that the two are both directly accessible in the result proxy - handwringing over the damn "name fallback" thing in results. can't really make it perfect yet - fix up oracle returning clause. not sure why its guarding against labels, remove that for now and see what the bot says.
* - MySQL's update does work. add some logic to compiler to convert from ORM ↵Mike Bayer2012-08-201-3/+7
| | | | column to Table column
* - [feature] The Core oeprator system now includesMike Bayer2012-08-201-14/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the `getitem` operator, i.e. the bracket operator in Python. This is used at first to provide index and slice behavior to the Postgresql ARRAY type, and also provides a hook for end-user definition of custom __getitem__ schemes which can be applied at the type level as well as within ORM-level custom operator schemes. Note that this change has the effect that descriptor-based __getitem__ schemes used by the ORM in conjunction with synonym() or other "descriptor-wrapped" schemes will need to start using a custom comparator in order to maintain this behavior. - [feature] postgresql.ARRAY now supports indexing and slicing. The Python [] operator is available on all SQL expressions that are of type ARRAY; integer or simple slices can be passed. The slices can also be used on the assignment side in the SET clause of an UPDATE statement by passing them into Update.values(); see the docs for examples. - [feature] Added new "array literal" construct postgresql.array(). Basically a "tuple" that renders as ARRAY[1,2,3].
* - [feature] The prefix_with() method is now availableMike Bayer2012-08-191-12/+32
| | | | | | | | on each of select(), insert(), update(), delete(), all with the same API, accepting multiple prefix calls, as well as a "dialect name" so that the prefix can be limited to one kind of dialect. [ticket:2431]
* - fix the labeled column with column_expression() issue, finishes [ticket:1534]Mike Bayer2012-08-181-2/+9
| | | | | | | | | | | - epic documentation sweep for new operator system, making ORM links consistent and complete, full documentation and examples for type/SQL expression feature - type_coerce() explicitly accepts BindParamClause objects - change UserDefinedType to coerce the other side to itself by default as this is much more likely what's desired - make coerce_compared_type() fully public on all types - have profiling run the test no matter what so that the test_zoomarks don't fail when callcounts are missing
* - [feature] To complement [ticket:2547], typesMike Bayer2012-08-171-48/+88
| | | | | | | | | | | | | | | | can now provide "bind expressions" and "column expressions" which allow compile-time injection of SQL expressions into statements on a per-column or per-bind level. This is to suit the use case of a type which needs to augment bind- and result- behavior at the SQL level, as opposed to in the Python level. Allows for schemes like transparent encryption/ decryption, usage of Postgis functions, etc. [ticket:1534] - update postgis example fully. - still need to repair the result map propagation here to be transparent for cases like "labeled column".