summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
authorGord Thompson <gord@gordthompson.com>2020-08-01 15:56:12 -0600
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-19 11:05:52 -0400
commit0c7a867ac73f1ed0ecfa134e907654fd4f7c084b (patch)
treec645f7514e9f6b977b2440413b6572b40c0edbd5 /lib/sqlalchemy/dialects/mysql/base.py
parent0901190bb440580f0664fe3f6310173762b908e0 (diff)
downloadsqlalchemy-0c7a867ac73f1ed0ecfa134e907654fd4f7c084b.tar.gz
Add JSON support for mssql
Added support for the :class:`_types.JSON` datatype on the SQL Server dialect using the :class:`_mssql.JSON` implementation, which implements SQL Server's JSON functionality against the ``NVARCHAR(max)`` datatype as per SQL Server documentation. Implementation courtesy Gord Thompson. Fixes: #4384 Change-Id: I28af79a4d8fafaa68ea032228609bba727784f18
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 34afc81a7..1d032b600 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1417,15 +1417,20 @@ class MySQLCompiler(compiler.SQLCompiler):
# explicitly return true/false constants
type_expression = "WHEN true THEN true ELSE false"
elif binary.type._type_affinity is sqltypes.String:
- # this fails with a JSON value that's a four byte unicode
+ # (gord): this fails with a JSON value that's a four byte unicode
# string. SQLite has the same problem at the moment
+ # (zzzeek): I'm not really sure. let's take a look at a test case
+ # that hits each backend and maybe make a requires rule for it?
type_expression = "ELSE JSON_UNQUOTE(JSON_EXTRACT(%s, %s))" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw),
)
else:
# other affinity....this is not expected right now
- type_expression = "ELSE JSON_EXTRACT(%s, %s)"
+ type_expression = "ELSE JSON_EXTRACT(%s, %s)" % (
+ self.process(binary.left, **kw),
+ self.process(binary.right, **kw),
+ )
return case_expression + " " + type_expression + " END"