33 Commits

Author SHA1 Message Date
Mike Bayer 18abd47af3 Post black reformatting
Applied on top of a pure run of black -l 79 in
I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9,  this set of changes
resolves all remaining flake8 conditions for those codes
we have enabled in setup.cfg.

Included are resolutions for all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
2019-01-06 11:51:20 -05:00
Mike Bayer 580139598f Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.

The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines.   The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
2019-01-06 01:31:01 -05:00
Mike Bayer 8ef6f0901f Move CRUDTest, InlineDefaultTest from test_compiler
test_compiler is mostly related to SELECT statements as well
as smaller SQL elements.  While it still has some DDL related
tests, move out all the remaining insert/update tests into
the already present test_insert.py, test_update.py

Fixes: #2630
Change-Id: I4167618543fd1235d12d1717c8c629d2374b325a
(cherry picked from commit 87cdda0086)
2018-12-01 14:30:51 -05:00
Mike Bayer 6529c474af render WITH clause after INSERT for INSERT..SELECT on Oracle, MySQL
Fixed INSERT FROM SELECT with CTEs for the Oracle and MySQL dialects, where
the CTE was being placed above the entire statement as is typical with
other databases, however Oracle and MariaDB 10.2 wants the CTE underneath
the "INSERT" segment. Note that the Oracle and MySQL dialects don't yet
work when a CTE is applied to a subquery inside of an UPDATE or DELETE
statement, as the CTE is still applied to the top rather than inside the
subquery.

Also adds test suite support CTEs against backends.

Change-Id: I8ac337104d5c546dd4f0cd305632ffb56ac8bf90
Fixes: #4275
Fixes: #4230
(cherry picked from commit 3619edcb8a)
2018-06-18 09:13:03 -04:00
Aubrey Stark-Toller ab2165e6d6 ValuesBase.values inconsistency fix
Fixed bug in :meth:`.Insert.values` where using the "multi-values"
format in combination with :class:`.Column` objects as keys rather
than strings would fail.   Pull request courtesy Aubrey Stark-Toller.

Change-Id: I9d3b40b5950df8f5bfdc8b1d22f9c3afb277f17f
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/412
Fixes: #4162
2018-01-12 11:28:41 -05:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 4fec72f178 Pass **kw to bound params in multi values
Fixed bug where literal_binds compiler flag was not honored by the
:class:`.Insert` construct for the "multiple values" feature; the
subsequent values are now rendered as literals.

Change-Id: I81ac358fd59995885d482e7571620090210865d2
Fixes: #3880
2017-01-09 17:37:25 -05:00
Mike Bayer d5bb919aa6 Call nextval() on sequence when doing INSERT from SELECT
Fixed bug where an INSERT from SELECT where the source table contains
an autoincrementing Sequence would fail to compile correctly.

Change-Id: I41eb9f65789a4007712ae61ed5fa23a9839a5128
Fixes: #3877
2016-12-21 13:39:56 -05:00
Mike Bayer 88ca587eae Count columns using PrimaryKeyConstraint.__len__ directly
PrimaryKeyConstraint is present on Table however
on table() and others it's a ColumnSet.  The warning
here only needs len() and PrimaryKeyConstraint supports that
directly in the same way as ColumnSet.

Change-Id: I19c11a39110bfef48cdea49a471e7ab80b537538
Fixes: #3842
2016-11-12 12:34:01 -05:00
Mike Bayer f917b353e8 Add a qualifying character to multi INSERT..VALUES parameter names
Changed the naming convention used when generating bound parameters
for a multi-VALUES insert statement, so that the numbered parameter
names don't conflict with the anonymized parameters of a WHERE clause,
as is now common in a PostgreSQL ON CONFLICT construct.

Change-Id: I3188d100fe4d322a47d344d6a63d3e40b915f228
Fixes: #3828
2016-10-17 12:14:41 -04:00
Mike Bayer 8a13957db7 Change autoincrement compileerror to a warning
Users are complaining that IntegrityError is no longer
raised.

Change-Id: I0855d5b7a98d4338f0910501b6e6d404ba33634d
Fixes: #3216
2016-10-07 09:54:39 -04:00
Mike Bayer 6b7c207801 - move out unconsumed names tests from test_compiler out to test_insert, test_update
- establish consistent names between existing unconsumed names tests and new ones
added per ref #3666
2016-03-02 20:24:49 -05:00
Athena Yao a1de176d23 Add test for inserting multiple values 2016-03-02 11:43:09 -08:00
Mike Bayer e5f1a3fb7d - CTE functionality has been expanded to support all DML, allowing
INSERT, UPDATE, and DELETE statements to both specify their own
WITH clause, as well as for these statements themselves to be
CTE expressions when they include a RETURNING clause.
fixes #2551
2016-02-11 12:27:28 -05:00
Mike Bayer e57bf79616 - Fixed issue within the :meth:.Insert.from_select construct whereby
the :class:`.Select` construct would have its ``._raw_columns``
collection mutated in-place when compiling the :class:`.Insert`
construct, when the target :class:`.Table` has Python-side defaults.
The :class:`.Select` construct would compile standalone with the
erroneous column present subsequent to compilation of the
:class:`.Insert`, and the the :class:`.Insert` statement itself would
fail on a second compile attempt due to duplicate bound parameters.
fixes #3603
2015-12-09 18:15:25 -05:00
Mike Bayer 414af7b612 - The system by which a :class:.Column considers itself to be an
"auto increment" column has been changed, such that autoincrement
is no longer implicitly enabled for a :class:`.Table` that has a
composite primary key.  In order to accommodate being able to enable
autoincrement for a composite PK member column while at the same time
maintaining SQLAlchemy's long standing behavior of enabling
implicit autoincrement for a single integer primary key, a third
state has been added to the :paramref:`.Column.autoincrement` parameter
``"auto"``, which is now the default. fixes #3216
- The MySQL dialect no longer generates an extra "KEY" directive when
generating CREATE TABLE DDL for a table using InnoDB with a
composite primary key with AUTO_INCREMENT on a column that isn't the
first column;  to overcome InnoDB's limitation here, the PRIMARY KEY
constraint is now generated with the AUTO_INCREMENT column placed
first in the list of columns.
2015-10-07 10:02:45 -04:00
Mike Bayer c39ff9978d - Fixed regression in 1.0-released default-processor for multi-VALUES
insert statement, 🎫`3288`, where the column type for the
default-holding column would not be propagated to the compiled
statement in the case where the default was being used,
leading to bind-level type handlers not being invoked.
fixes #3520
2015-08-31 11:30:03 -04:00
Mike Bayer eb1bb84fbc - Added official support for a CTE used by the SELECT present
inside of :meth:`.Insert.from_select`.  This behavior worked
accidentally up until 0.9.9, when it no longer worked due to
unrelated changes as part of 🎫`3248`.   Note that this
is the rendering of the WITH clause after the INSERT, before the
SELECT; the full functionality of CTEs rendered at the top
level of INSERT, UPDATE, DELETE is a new feature targeted for a
later release.
fixes #3418
2015-05-08 12:37:55 -04:00
Eric Streeper e467db9edb PEP8 cleanup in /test/sql 2015-03-18 21:38:57 -07:00
Mike Bayer 92cc232726 - The multi-values version of :meth:.Insert.values has been
repaired to work more usefully with tables that have Python-
side default values and/or functions, as well as server-side
defaults. The feature will now work with a dialect that uses
"positional" parameters; a Python callable will also be
invoked individually for each row just as is the case with an
"executemany" style invocation; a server- side default column
will no longer implicitly receive the value explicitly
specified for the first row, instead refusing to invoke
without an explicit value. fixes #3288
2015-01-13 14:33:33 -05:00
Mike Bayer 95be42c06f - :meth:.Insert.from_select now includes Python and SQL-expression
defaults if otherwise unspecified; the limitation where non-
server column defaults aren't included in an INSERT FROM
SELECT is now lifted and these expressions are rendered as
constants into the SELECT statement.
2014-10-10 17:15:19 -04:00
Mike Bayer 7c6a45c480 - The :func:~.expression.column and :func:~.expression.table
constructs are now importable from the "from sqlalchemy" namespace,
just like every other Core construct.
- The implicit conversion of strings to :func:`.text` constructs
when passed to most builder methods of :func:`.select` as
well as :class:`.Query` now emits a warning with just the
plain string sent.   The textual conversion still proceeds normally,
however.  The only method that accepts a string without a warning
are the "label reference" methods like order_by(), group_by();
these functions will now at compile time attempt to resolve a single
string argument to a column or label expression present in the
selectable; if none is located, the expression still renders, but
you get the warning again. The rationale here is that the implicit
conversion from string to text is more unexpected than not these days,
and it is better that the user send more direction to the Core / ORM
when passing a raw string as to what direction should be taken.
Core/ORM tutorials have been updated to go more in depth as to how text
is handled.
fixes #2992
2014-09-01 20:19:54 -04:00
Mike Bayer 71ca494f51 - The INSERT...FROM SELECT construct now implies `inline=True`
on :class:`.Insert`.  This helps to fix a bug where an
INSERT...FROM SELECT construct would inadvertently be compiled
as "implicit returning" on supporting backends, which would
cause breakage in the case of an INSERT that inserts zero rows
(as implicit returning expects a row), as well as arbitrary
return data in the case of an INSERT that inserts multiple
rows (e.g. only the first row of many).
A similar change is also applied to an INSERT..VALUES
with multiple parameter sets; implicit RETURNING will no longer emit
for this statement either.  As both of these constructs deal
with varible numbers of rows, the
:attr:`.ResultProxy.inserted_primary_key` accessor does not
apply.   Previously, there was a documentation note that one
may prefer ``inline=True`` with INSERT..FROM SELECT as some databases
don't support returning and therefore can't do "implicit" returning,
but there's no reason an INSERT...FROM SELECT needs implicit returning
in any case.   Regular explicit :meth:`.Insert.returning` should
be used to return variable numbers of result rows if inserted
data is needed.
fixes #3169
2014-08-20 20:14:20 -04:00
Mike Bayer bb5f4392a4 - update the flake8 rules again
- apply autopep8 + manual fixes to most of test/sql/
2014-07-18 17:40:58 -04:00
Mike Bayer eb4abda811 - Fixed bug where multi-valued :class:.Insert construct would fail
to check subsequent values entries beyond the first one given
for literal SQL expressions.
fixes #3069
2014-07-14 18:28:07 -04:00
Mike Bayer 482a67e1c6 - Fixed bug in INSERT..FROM SELECT construct where selecting from a
UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
fixes #3044
2014-05-25 14:08:41 -04:00
Mike Bayer 77ed036525 - Fixed bug where calling :meth:.Insert.values with an empty list
or tuple would raise an IndexError.   It now produces an empty
insert construct as would be the case with an empty dictionary.
2014-02-19 15:18:22 -05:00
Mike Bayer 5f76f29c15 - Fixed bug with :meth:.Insert.from_select method where the order
of the given names would not be taken into account when generating
the INSERT statement, thus producing a mismatch versus the column
names in the given SELECT statement.  Also noted that
:meth:`.Insert.from_select` implies that Python-side insert defaults
cannot be used, since the statement has no VALUES clause. [ticket:2895]
2013-12-19 16:02:14 -05:00
Mike Bayer cec89cae15 - Added new method to the :func:.insert construct
: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.  Also in 0.8.3.
2013-07-05 15:51:24 -04:00
Mike Bayer 6bdd3bb93f - reinstate insert returning back into test_insert.py; defaultdialect
needs to be explicit here since tablestest sticks testing.db onto metadata.bind
2013-04-01 15:41:57 -04:00
Diana Clarke 25c6732019 moving insert returning test back into CRUD test class until I figure out why moving it broke the oracle/postgres builds 2013-03-30 09:30:58 -04:00
Diana Clarke e6d6cfbf6b fixing tests for --db=mysql: VARCHAR requires a length on dialect mysql 2013-03-30 01:01:59 -04:00
Diana Clarke 17487a0db7 move the insert tests from CRUDTest into sql/test_insert.py (see #2630) 2013-03-29 19:10:01 -04:00