summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
Commit message (Collapse)AuthorAgeFilesLines
* Refactor for cx_Oracle version 6oracle_numericMike Bayer2017-09-111-0/+9
| | | | | | | | | Drops support for cx_Oracle prior to version 5.x, reworks numeric and binary support. Fixes: #4064 Change-Id: Ib9ae9aba430c15cd2a6eeb4e5e3fd8e97b5fe480
* Ensure custom ops have consistent typing behavior, boolean supportMike Bayer2017-09-014-12/+69
| | | | | | | | | | | | | | Refined the behavior of :meth:`.Operators.op` such that in all cases, if the :paramref:`.Operators.op.is_comparison` flag is set to True, the return type of the resulting expression will be :class:`.Boolean`, and if the flag is False, the return type of the resulting expression will be the same type as that of the left-hand expression, which is the typical default behavior of other operators. Also added a new parameter :paramref:`.Operators.op.return_type` as well as a helper method :meth:`.Operators.bool_op`. Change-Id: Ifc8553cd4037d741b84b70a9702cbd530f1a9de0 Fixes: #4063
* Enable native boolean for SQL ServerMike Bayer2017-08-301-6/+6
| | | | | | | | | | | | | | | | SQL Server supports what SQLAlchemy calls "native boolean" with its BIT type, as this type only accepts 0 or 1 and the DBAPIs return its value as True/False. So the SQL Server dialects now enable "native boolean" support, in that a CHECK constraint is not generated for a :class:`.Boolean` datatype. The only difference vs. other native boolean is that there are no "true" / "false" constants so "1" and "0" are still rendered here. Tests are implicit in the existing suites. Change-Id: I75bbcd549884099fb1a177e68667bf880c40fa7c Fixes: #4061
* Merge "Apply percent sign escaping to literal binds, comments"mike bayer2017-08-281-0/+4
|\
| * Apply percent sign escaping to literal binds, commentsMike Bayer2017-08-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed bug in new percent-sign support (e.g. :ticket:`3740`) where a bound parameter rendered with literal_binds would fail to escape percent-signs for relevant dialects. In addition, ensured new table / column comment support feature also fully makes use of literal-rendered parameters so that this percent sign support takes place with table / column comment DDL as well, allowing percent sign support for the mysql / psycopg2 backends that require escaping of percent signs. Change-Id: Ia4136a300933e9bc6a01a7b9afd5c7b9a3fee4e3 Fixes: #4054 Fixes: #4052
* | Allow for multiple FOLLOWING/PRECEDING in a window rangeMike Bayer2017-08-252-25/+26
|/ | | | | | | | | | | Altered the range specification for window functions to allow for two of the same PRECEDING or FOLLOWING keywords in a range by allowing for the left side of the range to be positive and for the right to be negative, e.g. (1, 3) is "1 FOLLOWING AND 3 FOLLOWING". Change-Id: I7d3a6c641151bb49219104968d18dac2266f3db8 Fixes: #4053
* Ensure Oracle index w/ col DESC etc. is reflectedMike Bayer2017-08-142-1/+14
| | | | | | | | | | | | | | | | | | | | Fixed bug where an index reflected under Oracle with an expression like "column DESC" would not be returned, if the table also had no primary key, as a result of logic that attempts to filter out the index implicitly added by Oracle onto the primary key columns. Reworked the "filter out the primary key index" logic in oracle get_indexes() to be clearer. This changeset also adds an internal check to ColumnCollection to accomodate for the case of a column being added twice, as well as adding a private _table argument to Index such that reflection can specify the Table explicitly. The _table argument can become part of public API in a later revision or release if needed. Change-Id: I745711e03b3e450b7f31185fc70e10d3823063fa Fixes: #4042
* Add support for CACHE and ORDER to sequencesDavid Moore2017-07-052-2/+21
| | | | | | | | | | | Added new keywords :paramref:`.Sequence.cache` and :paramref:`.Sequence.order` to :class:`.Sequence`, to allow rendering of the CACHE parameter understood by Oracle and PostgreSQL, and the ORDER parameter understood by Oracle. Pull request courtesy David Moore. Change-Id: I082c3f8ef56ef89dbaad5da9d5695be5313b0614 Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/96
* Coerce to float for Float with all native decimal backendsMike Bayer2017-06-261-0/+2
| | | | | | | | | | | | | The result processor for the :class:`.Float` type now unconditionally runs values through the ``float()`` processor if the dialect specifies that it also supports "native decimal" mode. While most backends will deliver Python ``float`` objects for a floating point datatype, the MySQL backends in some cases lack the typing information in order to provide this and return ``Decimal`` unless the float conversion is done. Change-Id: I638f1480fb00a507036efaf0e0080f26893d98ad Fixes: #4020
* Return given type when it matches the adaptationMike Bayer2017-06-261-38/+32
| | | | | | | | | | | | | The rules for type coercion between :class:`.Numeric`, :class:`.Integer`, and date-related types now include additional logic that will attempt to preserve the settings of the incoming type on the "resolved" type. Currently the target for this is the ``asdecimal`` flag, so that a math operation between :class:`.Numeric` or :class:`.Float` and :class:`.Integer` will preserve the "asdecimal" flag as well as if the type should be the :class:`.Float` subclass. Change-Id: Idfaba17220d6db21ca1ca4dcb4c19834cd397817 Fixes: #4018
* Merge "Coerce float Python type to Float; ensure Python float coming back"mike bayer2017-06-261-1/+1
|\
| * Coerce float Python type to Float; ensure Python float coming backMike Bayer2017-06-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | Added some extra strictness to the handling of Python "float" values passed to SQL statements. A "float" value will be associated with the :class:`.Float` datatype and not the Decimal-coercing :class:`.Numeric` datatype as was the case before, eliminating a confusing warning emitted on SQLite as well as unecessary coercion to Decimal. Change-Id: I1bb1810ff1d198c0d929ccba5656e55401d74119 Fixes: #4017
* | Don't erase reflected comment in _init_existingEloy Felix2017-06-201-2/+3
|/ | | | | Change-Id: Ie0b78c79367933486528ca0ba686d4a9f16922b1 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/370
* Repair WithinGroup.get_children()Mike Bayer2017-06-161-1/+1
| | | | | | | | Fixed AttributeError which would occur in :class:`.WithinGroup` construct during an iteration of the structure. Change-Id: I563882d93c8c32292463a605b636aa60c77e9406 Fixes: #4012
* Merge branch 'fix-typo' of https://github.com/lelit/sqlalchemyMike Bayer2017-06-021-5/+5
|\
| * Fix a few doc typosLele Gaifax2017-06-021-5/+5
| |
* | Merge "Raise if ForeignKeyConstraint created with different numbers of local ↵mike bayer2017-05-251-0/+16
|\ \ | | | | | | | | | and remote columns."
| * | Raise if ForeignKeyConstraint created with different numbers ofMike Bayer2017-05-251-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | local and remote columns. An :class:`.ArgumentError` is now raised if a :class:`.ForeignKeyConstraint` object is created with a mismatched number of "local" and "remote" columns, which otherwise causes the internal state of the constraint to be incorrect. Note that this also impacts the condition where a dialect's reflection process produces a mismatched set of columns for a foreign key constraint. Downstream DB2 dialect has been reported as potentially causing this scenario. Change-Id: Id51c34a6c43749bb582639f9c1dc28723482f0e5 Fixes: #3949 References: #3998
* | | Flatten operator precedence for comparison operatorsMichael Birtwell2017-05-251-12/+13
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | The operator precedence for all comparison operators such as LIKE, IS, IN, MATCH, equals, greater than, less than, etc. has all been merged into one level, so that expressions which make use of these against each other will produce parentheses between them. This suits the stated operator precedence of databases like Oracle, MySQL and others which place all of these operators as equal precedence, as well as Postgresql as of 9.5 which has also flattened its operator precendence. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #3999 Change-Id: I3f3d5124a64af0d376361cdf15a97e2e703be56f Pull-request: https://github.com/zzzeek/sqlalchemy/pull/367
* | Add with_for_update() support in session.refresh()Mike Bayer2017-05-241-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Session.refresh() is still hardcoded to legacy lockmode, come up with a new API so that the newer argument style works with it. Added new argument :paramref:`.with_for_update` to the :meth:`.Session.refresh` method. When the :meth:`.Query.with_lockmode` method were deprecated in favor of :meth:`.Query.with_for_update`, the :meth:`.Session.refresh` method was never updated to reflect the new option. Change-Id: Ia02a653746b7024699b515451525a88d7a17d63a Fixes: #3991
* | Allow metadata.reflect() to recover from unreflectable tablesMike Bayer2017-05-221-1/+4
|/ | | | | | | | | | | | | Added support for views that are unreflectable due to stale table definitions, when calling :meth:`.MetaData.reflect`; a warning is emitted for the table that cannot respond to ``DESCRIBE`` but the operation succeeds. The MySQL dialect now raises UnreflectableTableError which is in turn caught by MetaData.reflect(). Reflecting the view standalone raises this error directly. Change-Id: Id8005219d8e073c154cc84a873df911b4a6cf4d6 Fixes: #3871
* - Document the most transparent way to set JSON.NULL forMike Bayer2017-05-181-0/+16
| | | | | | | | | | | | | | | a column default. The JSON.NULL value is special in that while it is a Python-side value, it represents "do this special behavior", and is not at all like any other Python-side value for which normally, that's exactly the type of data we want back. So in this case, encourage the user to use a SQL expression that is exact, so in the ORM context, you get back what was actually persisted in the column. There's some variants of this such as literal(JSON.NULL, JSON) but text("'null'") is simpler. Change-Id: I0339fafdc03e4b2f533d53970b2f74c774f2687b Fixes: #3923
* Add links to with_only_columns to Select.column, append_columnMike Bayer2017-05-121-19/+16
| | | | | | | | | | | Provide a brief example for these two methods indicating that typically a table-bound (or other selectable) column is appended here, then link to with_only_columns documentation which has in-depth guidelines already including that one should not append columns from the current select to itself. Change-Id: I0742405a7f3c41450d337b9c633519d9cc101dfb Fixes: #3987
* - big rewrite of the Sequence documentation:Mike Bayer2017-05-051-20/+28
| | | | | | | | | | | | | | 1. Sequence should be associated with MetaData always, except in the really weird case someone is sharing a Sequence among multiple metadatas. Make this a "best practice", end the confusion of #3951, #3979 2. "optional" is not a thing people use, trim this way down 3. remove confusing language Change-Id: Iab5aec319da2582092fe2615ee50430f76441aff (cherry picked from commit a1dcf23e371695d8d3be2e1d7875fad10f16a656)
* - add another note re: 339e2c13b0fc8e95a47d00c0f8fc5afc4b6dff9aMike Bayer2017-05-051-0/+12
| | | | | | | | which clarifies that ForeignKey circumvents this logic as a "convenience". issue #3978 is updated to address trying to make this consistent. Change-Id: I089acaa89f11b7a6310c2bf32916e26eb62ab9c0
* - add a note to MetaData.schema indicating that the TableMike Bayer2017-05-051-0/+13
| | | | | | | will be cataloged in the .tables collection with its fully qualified name. Fixes #3978 Change-Id: I65fa063918efc22658e93c39a0680cb83553dec8
* Enforce boolean result type for all eq_, is_, isnot, comparisonMike Bayer2017-04-273-4/+11
| | | | | | | | | | | | Repaired issue where the type of an expression that used :meth:`.ColumnOperators.is_` or similar would not be a "boolean" type, instead the type would be "nulltype", as well as when using custom comparison operators against an untyped expression. This typing can impact how the expression behaves in larger contexts as well as in result-row-handling. Change-Id: Ib810ff686de500d8db26ae35a51005fab29603b6 Fixes: #3873
* Add _negate() to Label to negate inner elementMike Bayer2017-04-211-1/+7
| | | | | | | | | Fixed the negation of a :class:`.Label` construct so that the inner element is negated correctly, when the :func:`.not_` modifier is applied to the labeled expression. Change-Id: Ia99917b2959bdfbff28689c962b4203911c57b85 Fixes: #3969
* Set up base ARRAY to be compatible with postgresql.ARRAY.Mike Bayer2017-04-111-1/+18
| | | | | | | | | | For some reason, when ARRAY was added to the base it was never linked to postgresql.ARRAY. Link the two types and also make base ARRAY the schema event target so that it supports the same features as postgresql.ARRAY. Change-Id: I82fa6c9d2b8c5028dba3a009715f7bc296b2bc0b Fixes: #3964
* Add new "expanding" feature to bindparam()Mike Bayer2017-04-073-12/+62
| | | | | | | | | | | | | | | | Added a new kind of :func:`.bindparam` called "expanding". This is for use in ``IN`` expressions where the list of elements is rendered into individual bound parameters at statement execution time, rather than at statement compilation time. This allows both a single bound parameter name to be linked to an IN expression of multiple elements, as well as allows query caching to be used with IN expressions. The new feature allows the related features of "select in" loading and "polymorphic in" loading to make use of the baked query extension to reduce call overhead. This feature should be considered to be **experimental** for 1.2. Fixes: #3953 Change-Id: Ie708414a3ab9c0af29998a2c7f239ff7633b1f6e
* Merge "Double percent signs based on paramstyle, not dialect"mike bayer2017-04-051-8/+20
|\
| * Double percent signs based on paramstyle, not dialectMike Bayer2017-04-051-8/+20
| | | | | | | | | | | | | | | | | | | | | | | | This patch moves the "doubling" of percent signs into the base compiler and makes it completely a product of whether or not the paramstyle is format/pyformat or not. Without this paramstyle, percent signs are not doubled across text(), literal_column(), and column(). Change-Id: Ie2f278ab1dbb94b5078f85c0096d74dbfa049197 Fixes: #3740
* | Recognize brackets, quoted_name in SQL Server schemaMike Bayer2017-04-043-4/+10
|/ | | | | | | | | | | | | The SQL Server dialect now allows for a database and/or owner name with a dot inside of it, using brackets explicitly in the string around the owner and optionally the database name as well. In addition, sending the :class:`.quoted_name` construct for the schema name will not split on the dot and will deliver the full string as the "owner". :class:`.quoted_name` is also now available from the ``sqlalchemy.sql`` import space. Change-Id: I77491d63ce47638bd23787d903ccde2f35a9d43d Fixes: #2626
* Apply SQL compilation to sqltext for column-level CHECK constraintMike Bayer2017-04-041-1/+3
| | | | | | | | | | | | | Fixed bug where a column-level :class:`.CheckConstraint` would fail to compile the SQL expression using the underlying dialect compiler as well as apply proper flags to generate literal values as inline, in the case that the sqltext is a Core expression and not just a plain string. This was long-ago fixed for table-level check constraints in 0.9 as part of :ticket:`2742`, which more commonly feature Core SQL expressions as opposed to plain string expressions. Change-Id: I1301ba4b40063e91bc47726aecc5f4990ffcaeda Fixes: #3957
* Merge "Use consistent method signature for Alias.self_group()"mike bayer2017-04-031-4/+4
|\
| * Use consistent method signature for Alias.self_group()Mike Bayer2017-04-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | Fixed bug where the use of an :class:`.Alias` object in a column context would raise an argument error when it tried to group itself into a parenthesized expression. Using :class:`.Alias` in this way is not yet a fully supported API, however it applies to some end-user recipes and may have a more prominent role in support of some future Postgresql features. Change-Id: I81717e30416e0350f08d1e022c3d84656e0a9735 Fixes: #3939
* | Return self when Variant.coerce_compared_value would return implMike Bayer2017-04-011-1/+5
|/ | | | | | | | | | | | | Fixed regression released in 1.1.5 due to :ticket:`3859` where adjustments to the "right-hand-side" evaluation of an expression based on :class:`.Variant` to honor the underlying type's "right-hand-side" rules caused the :class:`.Variant` type to be inappropriately lost, in those cases when we *do* want the left-hand side type to be transferred directly to the right hand side so that bind-level rules can be applied to the expression's argument. Change-Id: Ia54dbbb19398549d654b74668753c4152599d900 Fixes: #3952
* Apply type processing to untyped preexec default clauseMike Bayer2017-03-301-0/+8
| | | | | | | | | | | | | | | | Fixed bug where a SQL-oriented Python-side column default could fail to be executed properly upon INSERT in the "pre-execute" codepath, if the SQL itself were an untyped expression, such as plain text. The "pre- execute" codepath is fairly uncommon however can apply to non-integer primary key columns with SQL defaults when RETURNING is not used. Tests exist here to ensure typing is applied to a typed expression for default, but in the case of an untyped SQL value, we know the type from the column, so apply this. Change-Id: I5d8b391611c137b9f700115a50a2bf5b30abfe94 Fixes: #3923
* Treat collation names as identifiersMike Bayer2017-03-232-2/+14
| | | | | | | | | | | The expression used for COLLATE as rendered by the column-level :func:`.expression.collate` and :meth:`.ColumnOperators.collate` is now quoted as an identifier when the name is case sensitive, e.g. has uppercase characters. Note that this does not impact type-level collation, which is already quoted. Change-Id: I83d5d9cd1e66a4f20b96303bb84c5f360d5d6a1a Fixes: #3785
* Merge branch 'master' of https://bitbucket.org/jalessio/sqlalchemyMike Bayer2017-03-181-2/+2
|\
| * Fix typos ('expicit' -> 'explicit')Jamie Alessio2017-03-141-2/+2
| |
* | New features from python 2.7Катаев Денис2017-03-175-11/+11
| | | | | | | | | | | | | | After bump minimum supported version to 2.7 (1da9d3752160430c91534a8868ceb8c5ad1451d4), we can use new syntax. Change-Id: Ib064c75a00562e641d132f9c57e5e69744200e05 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/347
* | Implement comments for tables, columnsFrazer McLean2017-03-173-5/+80
|/ | | | | | | | | | | | | | Added support for SQL comments on :class:`.Table` and :class:`.Column` objects, via the new :paramref:`.Table.comment` and :paramref:`.Column.comment` arguments. The comments are included as part of DDL on table creation, either inline or via an appropriate ALTER statement, and are also reflected back within table reflection, as well as via the :class:`.Inspector`. Supported backends currently include MySQL, Postgresql, and Oracle. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #1546 Change-Id: Ib90683850805a2b4ee198e420dc294f32f15d35d
* Merge "Add "empty in" strategies; default to "static""mike bayer2017-03-143-17/+62
|\
| * Add "empty in" strategies; default to "static"Mike Bayer2017-03-143-17/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The longstanding behavior of the :meth:`.Operators.in_` and :meth:`.Operators.not_in_` operators emitting a warning when the right-hand condition is an empty sequence has been revised; a new flag :paramref:`.create_engine.empty_in_strategy` allows an empty "IN" expression to generate a simple boolean expression, or to invoke the previous behavior of dis-equating the expression to itself, with or without a warning. The default behavior is now to emit the simple boolean expression, allowing an empty IN to be evaulated without any performance penalty. Change-Id: I65cc37f2d7cf65a59bf217136c42fee446929352 Fixes: #3907
* | Improve serializer behaviorMike Bayer2017-03-141-0/+3
|/ | | | | | | | | | Fix an issue where the Annotated system needs to have a __reduce__ method, also see why we can't default to HIGHEST_PROTOCOL. This latter part might not be a good idea until 1.2 for compatibility reasons. Change-Id: I0239e38259fc768c9e3b6c448c29161e271a969c Fixes: #3918
* add autoescape option to startswith, endswith, and containsDiana Clarke2017-03-141-13/+110
| | | | | | Fixes: #2694 Change-Id: I34c0bdcb01c2b76b9ab6cd315dae13e3dd8a502b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/207
* - add a note as to why we have this very complicated AnnotatedMike Bayer2017-03-091-0/+7
| | | | | | system Change-Id: I7d4048b92fcd3a7c7630c43aa9390d983f447c0a
* Allow SchemaType and Variant to work togetherMike Bayer2017-03-072-11/+79
| | | | | | | | | | | | | | Added support for the :class:`.Variant` and the :class:`.SchemaType` objects to be compatible with each other. That is, a variant can be created against a type like :class:`.Enum`, and the instructions to create constraints and/or database-specific type objects will propagate correctly as per the variant's dialect mapping. Also added testing for some potential double-event scenarios on TypeDecorator but it seems usually this doesn't occur. Change-Id: I4a7e7c26b4133cd14e870f5bc34a1b2f0f19a14a Fixes: #2892
* - document ForeignKeyConstraint columns / elements, fixes #2904Mike Bayer2017-03-071-0/+22
| | | | Change-Id: Ia50a3100d1bd88020c30224932b16aeadd7f4c75