Commit Graph

113 Commits

Author SHA1 Message Date
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 8574d5051a - find the remaining not cleaning up correctly test 2014-07-28 13:11:04 -04:00
Mike Bayer d2358629c9 - scale up for mysql, sqlite 2014-07-26 20:50:57 -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
Tony Locke fa80b73e3c PEP8 tidy of subset of test/sql/*.py 2014-07-07 07:32:33 +01:00
Tony Locke 73d00339c4 pg8000 passing test/sql 2014-07-06 23:13:44 +01:00
Mike Bayer 477b9e7f02 mark failing tests for buggy mysqlconnector 2014-03-28 17:26:45 -04:00
Mike Bayer 2f150bee28 - rename __multiple__ to __backend__, and apply __backend__ to a large number of tests.
- move out logging tests from test_execute to test_logging
2014-03-24 11:33:53 -04:00
Mike Bayer 8433a48fab - add more support for suite tests, moving some tests from test_query out to suite
and adding some more requirements
2014-03-13 18:54:56 -04:00
Mike Bayer ea05a23218 - Support has been added for pytest to run tests. This runner
is currently being supported in addition to nose, and will likely
be preferred to nose going forward.   The nose plugin system used
by SQLAlchemy has been split out so that it works under pytest as
well.  There are no plans to drop support for nose at the moment
and we hope that the test suite itself can continue to remain as
agnostic of testing platform as possible.  See the file
README.unittests.rst for updated information on running tests
with pytest.

The test plugin system has also been enhanced to support running
tests against mutiple database URLs at once, by specifying the ``--db``
and/or ``--dburi`` flags multiple times.  This does not run the entire test
suite for each database, but instead allows test cases that are specific
to certain backends make use of that backend as the test is run.
When using pytest as the test runner, the system will also run
specific test suites multiple times, once for each database, particularly
those tests within the "dialect suite".   The plan is that the enhanced
system will also be used by Alembic, and allow Alembic to run
migration operation tests against multiple backends in one run, including
third-party backends not included within Alembic itself.
Third party dialects and extensions are also encouraged to standardize
on SQLAlchemy's test suite as a basis; see the file README.dialects.rst
for background on building out from SQLAlchemy's test platform.
2014-03-03 15:55:17 -05:00
Mike Bayer 5c188f6c1c - More issues with [ticket:2932] first resolved in 0.9.2 where
using a column key of the form ``<tablename>_<columnname>``
matching that of an aliased column in the text would still not
match at the ORM level, which is ultimately due to a core
column-matching issue.  Additional rules have been added so that the
column ``_label`` is taken into account when working with a
:class:`.TextAsFrom` construct or with literal columns.
[ticket:2932]
2014-02-05 19:25:13 -05:00
Mike Bayer 29de1077b3 - Fixed bug in new :class:.TextAsFrom construct where :class:.Column-
oriented row lookups were not matching up to the ad-hoc :class:`.ColumnClause`
objects that :class:`.TextAsFrom` generates, thereby making it not
usable as a target in :meth:`.Query.from_statement`.  Also fixed
:meth:`.Query.from_statement` mechanics to not mistake a :class:`.TextAsFrom`
for a :class:`.Select` construct.  This bug is also an 0.9 regression
as the :meth:`.Text.columns` method is called to accommodate the
:paramref:`.text.typemap` argument. [ticket:2932]
2014-02-02 11:06:08 -05:00
Mike Bayer 00e78f5f76 - better way to do it 2014-01-29 14:57:18 -05:00
Mike Bayer 7d56e4f135 - add TypeError handling to the tests here, ensure TypeError
for the control is a TypeError for the row, as is raised on py3k when
less/greater operators are used on incompatible types
2014-01-29 14:55:58 -05:00
Mike Bayer d4c908ded1 - Fixed 0.9 regression where the new sortable support for :class:.RowProxy
would lead to ``TypeError`` when compared to non-tuple types as it attempted
to apply tuple() to the "other" object unconditionally.  The
full range of Python comparison operators have now been implemented on
:class:`.RowProxy`, using an approach that guarantees a comparison
system that is equivalent to that of a tuple, and the "other" object
is only coerced if it's an instance of RowProxy. [ticket:2924]
2014-01-28 23:43:14 -05:00
Mike Bayer f112dc1d53 - Fixed bug where SQL statement would be improperly ASCII-encoded
when a pre-DBAPI :class:`.StatementError` were raised within
:meth:`.Connection.execute`, causing encoding errors for
non-ASCII statements.  The stringification now remains within
Python unicode thus avoiding encoding errors. [ticket:2871]
2013-11-22 18:35:36 -05:00
Mike Bayer 02f21ffcf3 - The :class:.RowProxy object is now sortable in Python as a regular
tuple is; this is accomplished via ensuring tuple() conversion on
both sides within the ``__eq__()`` method as well as
the addition of a ``__lt__()`` method. [ticket:2848]
2013-11-19 19:29:18 -05:00
Mike Bayer 59ca4633ac - remove informix dialect, moved out to https://bitbucket.org/zzzeek/sqlalchemy_informixdb
- remove informix, maxdb, access symbols from tests etc.
2013-11-17 13:45:23 -05:00
Mike Bayer cd8a40284d - we dont actually need this unicode cast, on py3k + linux it seems the
has_table issues are OK.  On OSX forget it.
- still some issues with PY3k + pyodbc + decimal values it doesn't expect, not sure
2013-07-09 11:52:31 -04:00
Mike Bayer 3e52710a79 add an ORDER BY here 2013-06-26 15:03:50 -04:00
Mike Bayer c2a158c137 - some tweaks to try to help out mssql+pyodbc support a bit, py3k is really
not happening too well (I need to stick with linux + freetds 0.91, I know)
2013-06-03 12:54:56 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer a5ede47f12 A major fix to the way in which a select() object produces
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]
2013-04-11 16:14:23 -04:00
Mike Bayer b5b751e3de fix syntax error 2013-03-24 13:45:37 -04:00
Mike Bayer 35c5fd3fba Fixed bug whereby a DBAPI that can return "0"
for cursor.lastrowid would not function correctly
in conjunction with :attr:`.ResultProxy.inserted_primary_key`.
2013-03-23 19:00:11 -04:00
Mike Bayer 47858b85ec - add support for pulling in an external requirements file
- start filling in default versions of remaining requirements that are still only in test/
2013-02-06 17:50:11 -05:00
Mike Bayer 2121c1690a - add an "empty_inserts" requirement target plus a suite test
- add suite tests for basic explicit Sequence support, result-row column access (tests that name_normalize is set correctly among many other things)
2013-02-06 15:49:32 -05:00
Mike Bayer 8070cbde71 internally at least refer to multirow as "multivalues", to distinguish between
an INSERT that's used in executemany() as opposed to one which has a VALUES
clause with multiple entries.
2012-12-08 16:17:20 -05:00
Mike Bayer 927b985983 - multivalued inserts, [ticket:2623]
- 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.
2012-12-08 14:25:42 -05:00
Idan Kamara d57c1c2ddd compiler: add support for multirow inserts
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.
2012-12-06 00:11:52 +02:00
Mike Bayer 27db59b337 Fixed bug whereby using "key" with Column
in conjunction with "schema" for the owning
Table would fail to locate result rows due
to the MSSQL dialect's "schema rendering"
logic's failure to take .key into account.
Also in 0.7.10. [ticket:2607]
2012-11-13 23:43:31 -05:00
Mike Bayer 2484ef34c2 - [feature] The Query can now load entity/scalar-mixed
"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]
2012-10-15 20:07:13 -04:00
Mike Bayer b9ea55f861 - more tests, move some tests out of test_reflection, test_query 2012-09-27 16:11:32 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 444abbe847 - got firebird running
- add some failure cases
- [bug] Firebird now uses strict "ansi bind rules"
so that bound parameters don't render in the
columns clause of a statement - they render
literally instead.

- [bug] Support for passing datetime as date when
using the DateTime type with Firebird; other
dialects support this.
2012-09-23 18:09:18 -04:00
Mike Bayer 7e815c67a9 finished fixes for mxodbc; need to use at least version 3.2.1 2012-09-21 17:43:22 -04:00
Mike Bayer 626ae5b7a1 - fixes for mxODBC, some pyodbc
- enhancements to test suite including ability to set up a testing engine
for a whole test class, fixes to how noseplugin sets up/tears
down per-class context
2012-09-02 15:14:09 -04:00
Mike Bayer 51f1fdf3e4 - [bug] Fixed a regression since 0.6 regarding
result-row targeting.   It should be possible
    to use a select() statement with string
    based columns in it, that is
    select(['id', 'name']).select_from('mytable'),
    and have this statement be targetable by
    Column objects with those names; this is the
    mechanism by which
    query(MyClass).from_statement(some_statement)
    works.  At some point the specific case of
    using select(['id']), which is equivalent to
    select([literal_column('id')]), stopped working
    here, so this has been re-instated and of
    course tested. [ticket:2558]
2012-08-31 20:04:04 -04:00
Mike Bayer 326f2e4f60 - [feature] The "required" flag is set to
True by default, if not passed explicitly,
on bindparam() if the "value" or "callable"
parameters are not passed.
This will cause statement execution to check
for the parameter being present in the final
collection of bound parameters, rather than
implicitly assigning None. [ticket:2556]
2012-08-27 15:11:53 -04:00
Mike Bayer 752750ea7e - fix for pypy
- more oracle fixes
2012-08-25 13:30:58 -04:00
Mike Bayer 17f9bc5735 small tweaks to make insert() behavior more consistent, mostly tests, [ticket:2461] 2012-08-23 18:49:33 -04:00
Mike Bayer 8f5a31441a - [bug] Fixed cextension bug whereby the
"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.
2012-08-22 18:41:46 -04:00
Mike Bayer ffab937e4c fixes for pg9 2012-08-22 03:37:10 -04:00
Mike Bayer 2937f94e4a - all tests pass 2012-08-13 16:53:38 -04:00
Mike Bayer 5a02c9e73f - break out engine/base.py into base, interfaces, result, util.
- remove deprecated 0.7 engine methods
2012-08-07 12:01:19 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer c237ce43bd remove this test now covered in test_execute 2012-06-16 19:14:36 -04:00
Mike Bayer c6d4471af3 - [feature] Added SQLite execution option
"sqlite_raw_colnames=True", will bypass
    attempts to remove "." from column names
    returned by SQLite cursor.description.
    [ticket:2475]
2012-05-04 17:44:22 -04:00
Mike Bayer 87bbba32bc - [feature] The behavior of column targeting
in result sets is now case sensitive by
default.   SQLAlchemy for many years would
run a case-insensitive conversion on these values,
probably to alleviate early case sensitivity
issues with dialects like Oracle and
Firebird.   These issues have been more cleanly
solved in more modern versions so the performance
hit of calling lower() on identifiers is removed.
The case insensitive comparisons can be re-enabled
by setting "case_insensitive=False" on
create_engine().  [ticket:2423]
2012-04-24 16:03:00 -04:00