Commit Graph

48 Commits

Author SHA1 Message Date
Ben Shen cd3db26cc9 Fix / consolidate for SQL Server BINARY, VARBINARY
Fixed bug where sqltypes.BINARY and sqltypes.VARBINARY datatypes
would not include correct bound-value handlers for pyodbc,
which allows the pyodbc.NullParam value to be passed that
helps with FreeTDS.

Co-authored by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I6e3c16a69465b4fbc7b17a1927fb5e66acee93cb
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/386
Fixes: #4121
2017-10-25 10:50:54 -04:00
Mike Bayer f34b180ca9 Modernize SQL server binary tests
In preparation for I6e3c16a69465b4fbc7b17a1927fb5e66acee93cb
let's first use simplified binary test fixtures.

Change-Id: Ie0ac3ad194a64019bfcea0e5001cc8bdcf8a05e5
2017-10-24 12:40:25 -04:00
Mike Bayer fadebedff0 Add SQL Server TIMESTAMP / ROWVERSION datatypes
SQL Server has an entirely different use for the TIMESTAMP
datatype that is unrelated to the SQL standard's version of this
type.   It is a read-only type that returns an incrementing
binary value.  The ROWVERSION name will supersede the TIMESTAMP
name.  Implement datatype objects for both, separate from the
base DateTime/TIMESTAMP class hierarchy, and also implement
an optional integer coercion feature.

Change-Id: Ie2bd43b7aac57760b8ec6ff6e26460e2086a95eb
Fixes: #4086
2017-10-04 09:27:31 -04:00
Mike Bayer 6a38697261 Add full list of pyodbc error codes for MSSQL
Moved the SQL server error codes out of connnectors/pyodbc.py
and into mssql/pyodbc.py.  Added complete list
of odbc-related disconnect codes.

Change-Id: Icd84a920dbfa1f188847f859654ff6f7a48170f1
Fixes: #4095
2017-09-28 09:39:54 -04:00
Mike Bayer 2efd89d029 Add SQL Server CI coverage
Change-Id: Ida0d01ae9bcc0573b86e24fddea620a38c962822
2017-08-31 17:20:26 -04:00
Mike Bayer b1369b4721 Add placeholder XML support
Added a placeholder type :class:`.mssql.XML` to the SQL Server
dialect, so that a reflected table which includes this type can
be re-rendered as a CREATE TABLE.  The type has no special round-trip
behavior nor does it currently support additional qualifying
arguments.

Change-Id: I651fa729bd8e9b31a0b5effe0839aff077d77c46
Fixes: #3973
2017-05-26 11:24:25 -04:00
Mike Bayer 9f82afea25 Recognize brackets, quoted_name in SQL Server schema
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
2017-04-04 13:45:06 -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 5fba7db9be Quote URL tokens with semicolons for pyodbc, adodbapi
Fixed bug in pyodbc dialect (as well as in the mostly non-working
adodbapi dialect) whereby a semicolon present in the password
or username fields could be interpreted as a separator for another
token; the values are now quoted when semicolons are present.

Change-Id: I5f99fd8db53ebf8e805e7d9d60bc09b8f1af603f
Fixes: #3762
2016-11-11 13:30:25 -05:00
Mike Bayer f38f890849 Deprecate FromClause.count()
count() here is misleading in that it not only
counts from an arbitrary column in the table, it also
does not make accommodations for DISTINCT, JOIN, etc.
as the ORM-level function does.  Core should not be
attempting to provide a function like this.

Change-Id: I9916fc51ef744389a92c54660ab08e9695b8afc2
Fixes: #3724
2016-06-14 11:48:04 -04:00
Saulius Žemaitaitis a5f92314ed Allow creating explicit non-clustered keys and indexes MS SQL.
mssql_clustered=False on Index, UniqueConstraint,
PrimaryKeyConstraint now renders NONCLUSTERED.
The default of mssql_clustered is now None.

Co-Authored-By: mike bayer <mike_mp@zzzcomputing.com>
Change-Id: Id6b8d840e355be8f8fa72360cb4b6d2617ba72cf
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/252
2016-06-06 14:27:31 -04:00
Sheila Allen 3f55039e7f Use new mxODBC 3.3.4 varbinary null symbol
Use new mxODBC 3.3.4 varbinary null symbol with VARBINARY
data types when value is None(based on similar change to pyodbc).
Fix a test to pass on mxODBC starting w 3.3.3 version

Change-Id: Id703ecb51ebc5db149c81fef124f673433606c7f
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/58
2016-05-31 11:03:34 -04:00
Mike Bayer 0604116814 Fix label referencing in SQL Server OFFSET logic
Fixed bug where by ROW_NUMBER OVER clause applied for OFFSET
selects in SQL Server would inappropriately substitute a plain column
from the local statement that overlaps with a label name used by
the ORDER BY criteria of the statement.

Change-Id: Ic2500c886cbfc83a1ad5a2681783f008b9f23838
Fixes: #3711
2016-05-10 12:55:23 -04:00
Mike Bayer 6713817e11 - update the mssql autoincrement reflection test to accommodate
the new behavior of the autoincrement flag as per ref #3216
2016-02-20 20:43:36 -05:00
Mike Bayer 8ad968f331 - reworked the way the "select_wraps_for" expression is
handled within visit_select(); this attribute was added in the
1.0 series to accommodate the subquery wrapping behavior of
SQL Server and Oracle while also working with positional
column targeting and no longer relying upon "key fallback"
in order to target columns in such a statement.  The IBM DB2
third-party dialect also has this use case, but its implementation
is using regular expressions to rewrite the textual SELECT only
and does not make use of a "wrapped" select at this time.
The logic no longer attempts to reconcile proxy set collections as
this was not deterministic, and instead assumes that the select()
and the wrapper select() match their columns postionally,
at least for the column positions they have in common,
so it is now very simple and safe.  fixes #3657.
- as a side effect of #3657 it was also revealed that the
strategy of calling upon a ResultProxy._getter was not
correctly calling into NoSuchColumnError when an expected
column was not present, and instead returned None up to
loading.instances() to produce NoneType failures; added
a raiseerr argument to _getter() which is called when we
aren't expecting None, fixes #3658.
2016-02-20 20:22:38 -05:00
Mike Bayer 6831c67b8e - add missing __backend__ directives for SQL server 2016-02-08 14:20:12 -05:00
Mike Bayer 0ff3f95d5b - there was a DATEPART test after all, fix format 2016-01-14 17:50:03 -05:00
Mike Bayer 215167d8d3 - changelog for pr bitbucket:70, fixes #3624 2016-01-12 09:53:09 -05:00
Mike Bayer 03a3b5ffd3 - A descriptive ValueError is now raised in the event that SQL server
returns an invalid date or time format from a DATE or TIME
column, rather than failing with a NoneType error.  Pull request
courtesy Ed Avis.
pullreq github:206
2015-11-30 12:19:26 -05:00
Mike Bayer 0847097c29 - extend pullreq github:213 to also include DATETIMEOFFSET and TIME,
which also accept zero precision
- extend test case here to include a backend-agnostic suite
- changelog for MSSQL date fix
2015-11-14 12:38:45 -05:00
Jacobo de Vera 80ce23f6fd Pass precision value to mssql.DATETIME2 when it is 0
The simple check on the precision results in DATETIME2(0) generating a
DATETIME2 column, with default precision, which is 7.
2015-11-13 20:51:05 +01:00
Mike Bayer 3dfcb10bef - The `legacy_schema_aliasing` flag, introduced in version 1.0.5
as part of 🎫`3424` to allow disabling of the MSSQL dialect's
attempts to create aliases for schema-qualified tables, now defaults
to False; the old behavior is now disabled unless explicitly turned on.
fixes #3434
2015-09-19 18:06:23 -04:00
Mike Bayer b653fedca5 - fix the postgresql_jsonb requirement to include the 9.4 requirement
- new test for json col['x']['y']['z'] seems to fail pre PG 9.4,
fails on comparisons for non-compatible data instead of not matching
- no need to call SpecPredicate(db) directly in exclusion functions,
by using Predicate.as_predicate() the spec strings can have version
comparisons
2015-08-18 13:30:21 -04:00
Mike Bayer dd6110eed3 - Fixed issue where the SQL Server dialect would reflect a string-
or other variable-length column type with unbounded length
by assigning the token ``"max"`` to the
length attribute of the string.   While using the ``"max"`` token
explicitly is supported by the SQL Server dialect, it isn't part
of the normal contract of the base string types, and instead the
length should just be left as None.   The dialect now assigns the
length to None on reflection of the type so that the type behaves
normally in other contexts.
fixes #3504
2015-07-30 10:34:36 -04:00
Mike Bayer 78095940a4 - Fixed issue when using :class:.VARBINARY type in conjunction with
an INSERT of NULL + pyodbc; pyodbc requires a special
object be passed in order to persist NULL.  As the :class:`.VARBINARY`
type is now usually the default for :class:`.LargeBinary` due to
🎫`3039`, this issue is partially a regression in 1.0.
The pymssql driver appears to be unaffected.
fixes #3464
2015-06-22 15:24:41 -04:00
Mike Bayer 5a17d73648 - fix this test to not require pyodbc installed 2015-06-03 10:45:45 -04:00
Mike Bayer a50dcb31b9 - Fixed bug where known boolean values used by
:func:`.engine_from_config` were not being parsed correctly;
these included ``pool_threadlocal`` and the psycopg2 argument
``use_native_unicode``. fixes #3435
- add legacy_schema_aliasing config parsing for mssql
- move use_native_unicode config arg to the psycopg2 dialect
2015-05-26 10:56:23 -04:00
Mike Bayer 9157911013 - Added a new dialect flag to the MSSQL dialect
``legacy_schema_aliasing`` which when set to False will disable a
very old and obsolete behavior, that of the compiler's
attempt to turn all schema-qualified table names into alias names,
to work around old and no longer locatable issues where SQL
server could not parse a multi-part identifier name in all
circumstances.   The behavior prevented more
sophisticated statements from working correctly, including those which
use hints, as well as CRUD statements that embed correlated SELECT
statements.  Rather than continue to repair the feature to work
with more complex statements, it's better to just disable it
as it should no longer be needed for any modern SQL server
version.  The flag defaults to True for the 1.0.x series, leaving
current behavior unchanged for this version series.  In the 1.1
series, it will default to False.  For the 1.0 series,
when not set to either value explicitly, a warning is emitted
when a schema-qualified table is first used in a statement, which
suggests that the flag be set to False for all modern SQL Server
versions.
fixes #3424
fixes #3430
2015-05-24 21:02:29 -04:00
Mike Bayer 0198d9aa5f - break out binary insert against None, disable for freetds for now 2015-05-24 17:08:02 -04:00
Mike Bayer 96f49085b8 - autopep8 2015-05-24 17:07:54 -04:00
Mike Bayer 7c9a0e18be - fix some more result_map calls 2015-03-08 14:16:59 -04:00
Mike Bayer 17b2fd3fba - the change for #918 was of course not nearly that simple.
The "wrapping" employed by the mssql and oracle dialects using the
"iswrapper" argument was not being used intelligently by the compiler,
and the result map was being written incorrectly, using
*more* columns in the result map than were actually returned by
the statement, due to "row number" columns that are inside the
subquery.   The compiler now writes out result map on the
"top level" select in all cases
fully, and for the mssql/oracle wrapping case extracts out
the "proxied" columns in a second step, which only includes
those columns that are proxied outwards to the top level.

This change might have implications for 3rd party dialects that
might be imitating oracle's approach.   They can safely continue
to use the "iswrapper" kw which is now ignored, but they may
need to also add the _select_wraps argument as well.
2015-03-07 23:03:27 -05:00
Mike Bayer f5d4f2685f - rework assertsql system, fixes #3293 2015-01-18 20:57:26 -05:00
Mike Bayer c8817e6087 - SQL Server 2012 now recommends VARCHAR(max), NVARCHAR(max),
VARBINARY(max) for large text/binary types.  The MSSQL dialect will
now respect this based on version detection, as well as the new
``deprecate_large_types`` flag.
fixes #3039
2014-12-06 13:43:39 -05:00
Mike Bayer 95cd2003bb pep8 2014-12-06 12:39:18 -05:00
Mike Bayer a19b2f419c - The :attr:.Column.key attribute is now used as the source of
anonymous bound parameter names within expressions, to match the
existing use of this value as the key when rendered in an INSERT
or UPDATE statement.   This allows :attr:`.Column.key` to be used
as a "substitute" string to work around a difficult column name
that doesn't translate well into a bound parameter name.   Note that
the paramstyle is configurable on :func:`.create_engine` in any case,
and most DBAPIs today support a named and positional style.
fixes #3245
2014-11-10 17:37:26 -05:00
Mike Bayer a985f84ed6 - Fixed the version string detection in the pymssql dialect to
work with Microsoft SQL Azure, which changes the word "SQL Server"
to "SQL Azure".
fixes #3151
2014-09-16 17:40:06 -04:00
Mike Bayer 4399431b53 - The hostname-based connection format for SQL Server when using
pyodbc will no longer specify a default "driver name", and a warning
is emitted if this is missing.  The optimal driver name for SQL Server
changes frequently and is per-platform, so hostname based connections
need to specify this. DSN-based connections are preferred.
fixes #3182
2014-09-03 10:31:29 -04:00
Mike Bayer 81959af6d3 - more tests, including backend tests
- implement for SQL server, use window functions when simple limit/offset not available
2014-05-16 15:33:39 -04:00
Alex Gaynor 1caa7fafbd Fix many typos throughout the codebase
Found using: https://github.com/intgr/topy
2014-04-26 13:13:13 -07:00
donkopotamus 3593548960 Support mssql_clustered option on UniqueConstraint (plus docs and test) 2014-01-17 10:46:16 +13:00
donkopotamus 1de7259093 Remove support for mssql_clustered on Table 2014-01-17 10:38:31 +13:00
donkopotamus 40563e9355 Support mssql_clustered option in mssql dialect for both Table and PrimaryKeyConstraint 2014-01-14 12:44:05 +13:00
Mike Bayer 4b923d37bd - support addition of fails_if()/only_on(), just wraps the decorators
- update a few exclusions to support current pymssql.  passes all of test_suite and dialect/mssql
2014-01-02 14:23:14 -05:00
John Anderson 3147ca3040 Remove terminated connections from the pool.
In pymssql, if you terminate a long running query manually
it will give you a connection reset by peer message, but this
connection remains in the pool and will be re-used.
2013-12-16 12:50:10 -08:00
Mike Bayer 3621e4b8de - changelog + test for pullreq #7, MSSQL dialect for DROP INDEX 2013-12-05 18:36:59 -05:00
Mike Bayer 9bc9d5c106 - Fixed bug in default compiler plus those of postgresql, mysql, and
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.
2013-10-12 20:04:55 -04:00
Mike Bayer 1c23741b8e refactor test suites for postgresql, mssql, mysql into packages. 2013-06-28 22:30:11 -04:00