Kirill Simonov avatar Kirill Simonov committed 0b270d5

`length(null())=0` across all the backends.

Comments (0)

Files changed (6)

src/htsql/tr/fn/encode.py

     adapts_none()
 
 
+class EncodeLength(EncodeFunction):
+
+    adapts(LengthSig)
+
+    def __call__(self):
+        code = super(EncodeLength, self).__call__()
+        zero = LiteralCode(0, code.domain, code.binding)
+        return FormulaCode(IfNullSig(), code.domain, code.binding,
+                           lop=code, rop=zero)
+
+
 class EncodeContains(EncodeFunction):
 
     adapts(ContainsSig)

src/htsql_oracle/tr/encode.py

-#
-# Copyright (c) 2006-2011, Prometheus Research, LLC
-# Authors: Clark C. Evans <cce@clarkevans.com>,
-#          Kirill Simonov <xi@resolvent.net>
-#
-
-
-from htsql.adapter import adapts
-from htsql.domain import StringDomain
-from htsql.tr.code import LiteralCode, FormulaCode
-from htsql.tr.encode import EncodeLiteral
-from htsql.tr.fn.encode import EncodeFunction
-from htsql.tr.signature import IfNullSig
-from htsql.tr.fn.signature import LengthSig
-
-
-class OracleEncodeLength(EncodeFunction):
-
-    adapts(LengthSig)
-
-    def __call__(self):
-        code = super(OracleEncodeLength, self).__call__()
-        zero = LiteralCode(0, code.domain, code.binding)
-        return FormulaCode(IfNullSig(), code.domain, code.binding,
-                           lop=code, rop=zero)
-
-

test/regress/output/mssql.yaml

             -+----------------+-
              | length(null()) |
             -+----------------+-
-             |                |
+             |              0 |
                         (1 row)
 
              ----
              /{length(null())}
-             SELECT LEN(NULL)
+             SELECT COALESCE(LEN(NULL), 0)
         - uri: /{length(date(2010-04-15))}
           status: 400 Bad Request
           headers:

test/regress/output/mysql.yaml

             -+----------------+-
              | length(null()) |
             -+----------------+-
-             |                |
+             |              0 |
                         (1 row)
 
              ----
              /{length(null())}
-             SELECT CHARACTER_LENGTH(NULL)
+             SELECT COALESCE(CHARACTER_LENGTH(NULL), 0)
         - uri: /{length(date(2010-04-15))}
           status: 400 Bad Request
           headers:

test/regress/output/pgsql.yaml

             -+----------------+-
              | length(null()) |
             -+----------------+-
-             |                |
+             |              0 |
                         (1 row)
 
              ----
              /{length(null())}
-             SELECT CHARACTER_LENGTH(NULL)
+             SELECT COALESCE(CHARACTER_LENGTH(NULL), 0)
         - uri: /{length(date(2010-04-15))}
           status: 400 Bad Request
           headers:

test/regress/output/sqlite.yaml

             -+----------------+-
              | length(null()) |
             -+----------------+-
-             |                |
+             |              0 |
                         (1 row)
 
              ----
              /{length(null())}
-             SELECT LENGTH(NULL)
+             SELECT COALESCE(LENGTH(NULL), 0)
         - uri: /{length(date(2010-04-15))}
           status: 400 Bad Request
           headers:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.