Commit Graph

82 Commits

Author SHA1 Message Date
Denis Kataev de804d7245 Implement SQLite ON CONFLICT for constraints
Implemented the SQLite ``ON CONFLICT`` clause as understood at the DDL
level, e.g. for primary key, unique, and CHECK constraints as well as
specified on a :class:`.Column` to satisfy inline primary key and NOT NULL.
Pull request courtesy Denis Kataev.

Fixes: #4360
Change-Id: I4cd4bafa8fca41e3101c87dbbfe169741bbda3f4
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/431
2018-11-07 18:26:40 -05:00
Phillip Cloud 893eac06e5 Fix quoting schemas in _get_table_sql for the SQLite backend
Fixed issue where the "schema" name used for a SQLite database within table
reflection would not quote the schema name correctly.  Pull request
courtesy Phillip Cloud.

Change-Id: I2770788c1f094a7743209250ec26b5ef5fb2d9e8
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/463
2018-07-18 10:48:27 -04:00
Ilja Everilä 62d59088df Sqlite json
Added support for SQLite's json functionality via the new
SQLite implementation for :class:`.sqltypes.JSON`, :class:`.sqlite.JSON`.
The name used for the type is ``JSON``, following an example found at
SQLite's own documentation. Pull request courtesy Ilja Everilä.

Fixes: #3850
Change-Id: I3d2714fb8655343a99d13dc751b16b93d05d7dda
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/434
2018-07-10 18:55:31 -04:00
Nils Philippsen 40a5d0a4b0 fix TypeReflectionTest for sqlite 3.24
Fixed issue in test suite where SQLite 3.24 added a new reserved word that
conflicted with a usage in TypeReflectionTest.  Pull request courtesy Nils
Philippsen.

Change-Id: I396562cecb5ca774f29e9234845bcc6a399fc5cb
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/452
2018-06-25 18:37:23 -04: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 fa6dd376bb Support python3.6
Corrects some warnings and adds tox config.  Adds DeprecationWarning
to the error category.   Large sweep for string literals w/ backslashes
as this is common in docstrings

Co-authored-by: Andrii Soldatenko
Fixes: #3886
Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
2017-01-13 10:57:41 -05: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
Sebastian Bank 3351f5f93c Add IS (NOT) DISTINCT FROM operators
None / True / False render as literals.
For SQLite, "IS" is used as SQLite lacks
"IS DISTINCT FROM" but its "IS" operator acts
this way for NULL.

Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I9227b81f7207b42627a0349d14d40b46aa756cce
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/248
2016-06-06 15:53:25 -04:00
Mike Bayer 991346d5bb - further adjustment to accomodate for the "ON" in "NO ACTION"
Change-Id: I734e4aec3701d7cf17813b561a1418cfeff1d473
2016-06-03 20:54:48 -04:00
Mike Bayer 061bae6e04 Ensure "options" present for unnamed / unlocatable FK
Also ensure the regular expression and subsequent matching
is case insensitive, add more tests

Change-Id: Ie4aa971dcbffca94e78965e22982478eccbf8597
2016-06-03 15:57:16 -04:00
Michal Petrucha 0e88bcc30e Reflect ON DELETE and ON UPDATE for SQLite foreign keys
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Icd77ddbf851b1950f767022d67c8142b1b3c50f3
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/244
2016-06-02 17:49:09 -04:00
Alex Grönholm a8e7bb8782 Implemented CHECK constraint reflection for SQLite and PostgreSQL
Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Ie6cf2d2958d1c567324db9e08fef2d3186e97350
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/80
2016-06-01 12:57:36 -04:00
Diana Clarke b3b3c68a4a sqlite: reflect primary key constraint names, fixes #3629 2016-01-27 22:54:05 -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 5bb2536cc5 - limit the search for schemas to not include "temp", which is sort of an implicit schema
- repair the CREATE INDEX ddl for schemas
- update provisioning to include support for setting up ATTACH DATABASE up front
for the test_schema; enable "schemas" testing for SQLite
- changelog / migration notes for new SQLite schema support
- include the "schema" as the "remote_schema" when we reflect SQLite FKs
2015-09-28 17:48:55 -04:00
Brian Van Klaveren 4d53b31247 Support get_schema_names for SQLite
Should return "main" and the names of attached databases.
2015-09-09 14:23:27 -07:00
Kai Groner 4a42bd5a2c Test for partial index support in sqlite dialects. 2015-01-26 14:48:23 -05:00
Mike Bayer 468db416db - rework sqlite FK and unique constraint system to combine both PRAGMA
and regexp parsing of SQL in order to form a complete picture of
constraints + their names.  fixes #3244 fixes #3261
- factor various PRAGMA work to be centralized into one call
2014-12-13 19:24:56 -05:00
Jon Nelson 85c04dd0bb - add test_get_unnamed_unique_constraints to SQLite reflection tests 2014-12-13 18:34:50 -05:00
Mike Bayer 0ce045bd85 - The SQLite dialect, when using the :class:.sqlite.DATE,
:class:`.sqlite.TIME`,
or :class:`.sqlite.DATETIME` types, and given a ``storage_format`` that
only renders numbers, will render the types in DDL as
``DATE_CHAR``, ``TIME_CHAR``, and ``DATETIME_CHAR``, so that despite the
lack of alpha characters in the values, the column will still
deliver the "text affinity".  Normally this is not needed, as the
textual values within the default storage formats already
imply text.
fixes #3257
2014-12-05 14:46:43 -05:00
Mike Bayer ec6214457e - pep8 2014-12-05 14:19:36 -05:00
Mike Bayer 4da020dae3 - rework tests for attached databases into individual tests,
test both memory and file-based
- When selecting from a UNION using an attached database file,
the pysqlite driver reports column names in cursor.description
as 'dbname.tablename.colname', instead of 'tablename.colname' as
it normally does for a UNION (note that it's supposed to just be
'colname' for both, but we work around it).  The column translation
logic here has been adjusted to retrieve the rightmost token, rather
than the second token, so it works in both cases.   Workaround
courtesy Tony Roberts.
fixes #3211
2014-09-29 18:09:25 -04:00
Mike Bayer 7864f80a62 Merge branch 'sqlite-temp-table-reflection' of https://bitbucket.org/jerdfelt/sqlalchemy/branch/sqlite-temp-table-reflection into pr31 2014-09-17 15:16:33 -04:00
Mike Bayer cb23fa243f - Added :meth:.Inspector.get_temp_table_names and
:meth:`.Inspector.get_temp_view_names`; currently, only the
SQLite dialect supports these methods.    The return of temporary
table and view names has been **removed** from SQLite's version
of :meth:`.Inspector.get_table_names` and
:meth:`.Inspector.get_view_names`; other database backends cannot
support this information (such as MySQL), and the scope of operation
is different in that the tables can be local to a session and
typically aren't supported in remote schemas.
fixes #3204
2014-09-17 15:15:21 -04:00
Johannes Erdfelt 9d402e204d Handle sqlite get_unique_constraints() call for temporary tables
The sqlite get_unique_constraints() implementation did not do a union
against the sqlite_temp_master table like other code does. This could
result in an exception being raised if get_unique_constraints() was
called against a temporary table.
2014-09-17 08:01:01 -07:00
Mike Bayer cca4d8fc73 - add tests for the savepoint recipe 2014-08-09 14:03:17 -04:00
Mike Bayer 5d2bfc4df4 - Fixed a few errant `u''` strings that would prevent tests from passing
in Py3.2.  Patch courtesy Arfrever Frehtes Taifersar Arahesis. fixes #2980
2014-03-22 18:48:59 -04:00
Mike Bayer b4d9795db1 - dont need this import and it's not in 2.6 anyway 2014-02-17 16:03:07 -05:00
Mike Bayer 00c6ebb440 - rewrite SQLite reflection tests into one consistent fixture, which tests
both _resolve_type_affinity() directly as well as round trip tests fully.
2014-02-16 18:14:10 -05:00
Mike Bayer 5e100a70c5 - The SQLite dialect will now skip unsupported arguments when reflecting
types; such as if it encounters a string like ``INTEGER(5)``, the
:class:`.INTEGER` type will be instantiated without the "5" being included,
based on detecting a ``TypeError`` on the first attempt.
2014-02-16 17:20:18 -05:00
Erich Blume e47f994503 SQLite dialect - support relection from affinity
SQLite allows column types that aren't technically understood in sqlite
by using 'data affinity', which is an algorithm for converting column
types in to some sort of useful type that can be stored and retrieved
from the db. Unfortunatly, this breaks reflection since we (previously)
expected a sqlite db to reflect column types that we permit in the
`ischema_names` for that dialect.

This patch changes the logic for 'unknown' column types during
reflection to instead run through SQLite's data affinity algorithm, and
assigns appropriate types from that.

It also expands the matching for column type to include column types
with spaces (strongly discouraged but allowed by sqlite) and also
completely empty column types (in which case the NullType is assigned,
which sqlite will treat as a Blob - or rather, Blob is treated as
NullType). These changes mean that SQLite will never raise an error for
an unknown type during reflection - there will always be some 'useful'
type returned, which follows the spirit of SQLite (accomodation before
sanity!).
2014-02-03 16:55:00 -08:00
Mike Bayer 63488b2d1e The newly added SQLite DATETIME arguments storage_format and
regexp apparently were not fully implemented correctly; while the
arguments were accepted, in practice they would have no effect;
this has been fixed.  Also in 0.8.3.
[ticket:2781]
2013-07-12 21:52:54 -04:00
Mike Bayer 1fb6c4a33d Added :class:.BIGINT to the list of type names that can be
reflected by the SQLite dialect; courtesy Russell Stuart.
[ticket:2764]
2013-07-02 18:10:08 -04:00
Mike Bayer 4e930a7f78 - add a test specific to sqlite testing cursor.description encoding (should
probably be one in test_query or test_unicode...)
- fix up test_unitofwork
2013-05-26 16:58:37 -04:00
Mike Bayer 62c7e0dbe6 sqlite tests 2013-05-26 13:10:00 -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 850e881ce2 More adjustment to this SQLite related issue which was released in
0.7.9, to intercept legacy SQLite quoting characters when reflecting
foreign keys.  In addition to intercepting double quotes, other
quoting characters such as brackets, backticks, and single quotes
are now also intercepted. [ticket:2568]
2012-12-14 10:29:46 -05:00
Mike Bayer be40b51cb0 getting everything to pass again 2012-09-27 16:33:54 -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 0c7b989ce5 - [feature] Added support for the localtimestamp()
SQL function implemented in SQLite, courtesy
Richard Mitchell.  Added test
2012-09-26 10:20:56 -04:00
Mike Bayer c7ab095fdb - [bug] Adjusted column default reflection code to
convert non-string values to string, to accommodate
old SQLite versions that don't deliver
default info as a string.  [ticket:2265]
- factor sqlite column reflection to be like we did for postgresql,
in a separate method.
2012-09-23 11:30:07 -04:00
Mike Bayer 9e3458c479 - [bug] Adjusted a very old bugfix which attempted
to work around a SQLite issue that itself was
    "fixed" as of sqlite 3.6.14, regarding quotes
    surrounding a table name when using
    the "foreign_key_list" pragma.  The fix has been
    adjusted to not interfere with quotes that
    are *actually in the name* of a column or table,
    to as much a degree as possible; sqlite still
    doesn't return the correct result for foreign_key_list()
    if the target table actually has quotes surrounding
    its name, as *part* of its name (i.e. """mytable""").
    [ticket:2568]
2012-09-19 00:34:30 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Nathan Wright 55b4295e39 Improve SQLite DATETIME storage format handling [ticket:2363]
This breaks backwards compatibility with old SQLite DATETIME, DATE,
and TIME storage_format strings. Formatting now occurs with named instead
of positional parameters. The regexp argument can still use positional
arguments, but named groupings are also supported. This means that you can
omit fields and change the order of date fields as desired.

SQLite's DATETIME and TIME also gained a truncate_microseconds argument.
This is shorthand for modifying the format string. Fortunately the
str_to_datetime and str_to_time processors written in C already support
omitting microseconds, so we don't have to resort to python processing
for this case.
2012-03-12 21:31:12 -07:00
Nathan Wright 754e7290b4 Move a SQLLite datetime test to a new DateTimeTest case 2012-03-12 15:48:29 -07:00
Mike Bayer 8c05a3bf65 - [feature] Added "false()" and "true()" expression
constructs to sqlalchemy.sql namespace, though
not part of __all__ as of yet.
- [bug] sql.false() and sql.true() compile to
0 and 1, respectively in sqlite [ticket:2368]
2012-01-18 12:42:54 -05:00
Mike Bayer fd13676039 that's not a "name=0", that's a counter. so name is None unconditonally.
[ticket:2348]
2012-01-07 19:49:25 -05:00
Mike Bayer a4a81f7b96 - [bug] the "name" of an FK constraint in SQLite
is reflected as "None", not "0" [ticket:2364].
SQLite does not appear to support constraint
naming in any case (the names are ignored).
2012-01-07 15:37:51 -05:00
Mike Bayer 757400f82f - Ensured that the same ValueError is raised for
illegal date/time/datetime string parsed from
    the database regardless of whether C
    extensions are in use or not.
2011-08-04 15:34:24 -04:00
Mike Bayer 086ae95614 - SQLite dialect no longer strips quotes
off of reflected default value, allowing
    a round trip CREATE TABLE to work.
    This is consistent with other dialects
    that also maintain the exact form of
    the default.  [ticket:2189]
2011-07-28 11:53:18 -04:00