Skip to content
Snippets Groups Projects
Commit 7cf84a54 authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

sql: test suite for BOOLEAN

This patch provides a test suite that allows us to make sure that
the SQL BOOLEAN type works as intended.

Part of #4228
parent 037bd58c
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
......@@ -293,683 +293,6 @@ box.execute("SELECT CAST(f AS INTEGER) FROM t1;")
box.space.T1:drop()
---
...
-- Test basic capabilities of boolean type.
--
box.execute("SELECT true;")
---
- metadata:
- name: 'true'
type: boolean
rows:
- [true]
...
box.execute("SELECT false;")
---
- metadata:
- name: 'false'
type: boolean
rows:
- [false]
...
box.execute("SELECT unknown;")
---
- metadata:
- name: unknown
type: scalar
rows:
- [null]
...
box.execute("SELECT true = false;")
---
- metadata:
- name: true = false
type: boolean
rows:
- [false]
...
box.execute("SELECT true = true;")
---
- metadata:
- name: true = true
type: boolean
rows:
- [true]
...
box.execute("SELECT true > false;")
---
- metadata:
- name: true > false
type: boolean
rows:
- [true]
...
box.execute("SELECT true < false;")
---
- metadata:
- name: true < false
type: boolean
rows:
- [false]
...
box.execute("SELECT null = true;")
---
- metadata:
- name: null = true
type: boolean
rows:
- [null]
...
box.execute("SELECT unknown = true;")
---
- metadata:
- name: unknown = true
type: boolean
rows:
- [null]
...
box.execute("SELECT 1 = true;")
---
- null
- 'Type mismatch: can not convert UNSIGNED to BOOLEAN'
...
box.execute("SELECT 'abc' = true;")
---
- null
- 'Type mismatch: can not convert TEXT to BOOLEAN'
...
box.execute("SELECT 1.123 > true;")
---
- null
- 'Type mismatch: can not convert REAL to BOOLEAN'
...
box.execute("SELECT true IN (1, 'abc', true)")
---
- metadata:
- name: true IN (1, 'abc', true)
type: boolean
rows:
- [true]
...
box.execute("SELECT true IN (1, 'abc', false)")
---
- metadata:
- name: true IN (1, 'abc', false)
type: boolean
rows:
- [false]
...
box.execute("SELECT 1 LIMIT true;")
---
- null
- 'Failed to execute SQL statement: Only positive integers are allowed in the LIMIT
clause'
...
box.execute("SELECT 1 LIMIT 1 OFFSET true;")
---
- null
- 'Failed to execute SQL statement: Only positive integers are allowed in the OFFSET
clause'
...
box.execute("SELECT 'abc' || true;")
---
- null
- 'Inconsistent types: expected TEXT or VARBINARY got BOOLEAN'
...
-- Boolean can take part in arithmetic operations.
--
box.execute("SELECT true + false;")
---
- null
- 'Type mismatch: can not convert false to numeric'
...
box.execute("SELECT true * 1;")
---
- null
- 'Type mismatch: can not convert true to numeric'
...
box.execute("SELECT false / 0;")
---
- null
- 'Type mismatch: can not convert false to numeric'
...
box.execute("SELECT not true;")
---
- metadata:
- name: not true
type: boolean
rows:
- [false]
...
box.execute("SELECT ~true;")
---
- null
- 'Type mismatch: can not convert true to integer'
...
box.execute("SELECT -true;")
---
- null
- 'Type mismatch: can not convert true to numeric'
...
box.execute("SELECT true << 1;")
---
- null
- 'Type mismatch: can not convert true to integer'
...
box.execute("SELECT true | 1;")
---
- null
- 'Type mismatch: can not convert true to integer'
...
box.execute("SELECT true and false;")
---
- metadata:
- name: true and false
type: boolean
rows:
- [false]
...
box.execute("SELECT true or unknown;")
---
- metadata:
- name: true or unknown
type: boolean
rows:
- [true]
...
box.execute("CREATE TABLE t (id INT PRIMARY KEY, b BOOLEAN);")
---
- row_count: 1
...
box.execute("INSERT INTO t VALUES (1, true);")
---
- row_count: 1
...
box.execute("INSERT INTO t VALUES (2, false);")
---
- row_count: 1
...
box.execute("INSERT INTO t VALUES (3, unknown)")
---
- row_count: 1
...
box.execute("SELECT b FROM t;")
---
- metadata:
- name: B
type: boolean
rows:
- [true]
- [false]
- [null]
...
box.execute("SELECT b FROM t WHERE b = false;")
---
- metadata:
- name: B
type: boolean
rows:
- [false]
...
box.execute("SELECT b FROM t WHERE b IS NULL;")
---
- metadata:
- name: B
type: boolean
rows:
- [null]
...
box.execute("SELECT b FROM t WHERE b IN (false, 1, 'abc')")
---
- metadata:
- name: B
type: boolean
rows:
- [false]
...
box.execute("SELECT b FROM t WHERE b BETWEEN false AND true;")
---
- metadata:
- name: B
type: boolean
rows:
- [true]
- [false]
...
box.execute("SELECT b FROM t WHERE b BETWEEN true AND false;")
---
- metadata:
- name: B
type: boolean
rows: []
...
box.execute("SELECT b FROM t ORDER BY b;")
---
- metadata:
- name: B
type: boolean
rows:
- [null]
- [false]
- [true]
...
box.execute("SELECT b FROM t ORDER BY +b;")
---
- metadata:
- name: B
type: boolean
rows:
- [null]
- [false]
- [true]
...
box.execute("SELECT b FROM t ORDER BY b LIMIT 1;")
---
- metadata:
- name: B
type: boolean
rows:
- [null]
...
box.execute("SELECT b FROM t GROUP BY b LIMIT 1;")
---
- metadata:
- name: B
type: boolean
rows:
- [null]
...
box.execute("SELECT b FROM t LIMIT true;")
---
- null
- 'Failed to execute SQL statement: Only positive integers are allowed in the LIMIT
clause'
...
-- Most of aggregates don't accept boolean arguments.
--
box.execute("SELECT sum(b) FROM t;")
---
- null
- 'Type mismatch: can not convert true to number'
...
box.execute("SELECT avg(b) FROM t;")
---
- null
- 'Type mismatch: can not convert true to number'
...
box.execute("SELECT total(b) FROM t;")
---
- null
- 'Type mismatch: can not convert true to number'
...
box.execute("SELECT min(b) FROM t;")
---
- metadata:
- name: min(b)
type: scalar
rows:
- [false]
...
box.execute("SELECT max(b) FROM t;")
---
- metadata:
- name: max(b)
type: scalar
rows:
- [true]
...
box.execute("SELECT count(b) FROM t;")
---
- metadata:
- name: count(b)
type: integer
rows:
- [2]
...
box.execute("SELECT group_concat(b) FROM t;")
---
- metadata:
- name: group_concat(b)
type: string
rows:
- ['true,false']
...
-- Check other built-in functions.
--
box.execute("SELECT lower(b) FROM t;")
---
- metadata:
- name: lower(b)
type: string
rows:
- ['true']
- ['false']
- [null]
...
box.execute("SELECT upper(b) FROM t;")
---
- metadata:
- name: upper(b)
type: string
rows:
- ['TRUE']
- ['FALSE']
- [null]
...
box.execute("SELECT abs(b) FROM t;")
---
- null
- 'Inconsistent types: expected number got BOOLEAN'
...
box.execute("SELECT typeof(b) FROM t;")
---
- metadata:
- name: typeof(b)
type: string
rows:
- ['boolean']
- ['boolean']
- ['boolean']
...
box.execute("SELECT quote(b) FROM t;")
---
- metadata:
- name: quote(b)
type: string
rows:
- ['true']
- ['false']
- ['NULL']
...
box.execute("SELECT LEAST(b, true) FROM t;")
---
- metadata:
- name: LEAST(b, true)
type: scalar
rows:
- [true]
- [false]
- [null]
...
box.execute("SELECT quote(b) FROM t;")
---
- metadata:
- name: quote(b)
type: string
rows:
- ['true']
- ['false']
- ['NULL']
...
-- Test index search using boolean values.
--
box.execute("CREATE INDEX ib ON t(b);")
---
- row_count: 1
...
box.execute("SELECT b FROM t WHERE b = false;")
---
- metadata:
- name: B
type: boolean
rows:
- [false]
...
box.execute("SELECT b FROM t WHERE b OR unknown ORDER BY b;")
---
- metadata:
- name: B
type: boolean
rows:
- [true]
...
-- Test UPDATE on boolean field.
--
box.execute("UPDATE t SET b = true WHERE b = false;")
---
- row_count: 1
...
box.execute("SELECT b FROM t;")
---
- metadata:
- name: B
type: boolean
rows:
- [true]
- [true]
- [null]
...
-- Test constraints functionality.
--
box.execute("CREATE TABLE parent (id INT PRIMARY KEY, a BOOLEAN UNIQUE);")
---
- row_count: 1
...
box.space.T:truncate()
---
...
box.execute("ALTER TABLE t ADD CONSTRAINT fk1 FOREIGN KEY (b) REFERENCES parent (a);")
---
- row_count: 1
...
box.execute("INSERT INTO t VALUES (1, true);")
---
- null
- 'Failed to execute SQL statement: FOREIGN KEY constraint failed'
...
box.execute("INSERT INTO parent VALUES (1, true);")
---
- row_count: 1
...
box.execute("INSERT INTO t VALUES (1, true);")
---
- row_count: 1
...
box.execute("ALTER TABLE t DROP CONSTRAINT fk1;")
---
- row_count: 1
...
box.space.PARENT:drop()
---
...
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, a BOOLEAN CHECK (a = true));")
---
- row_count: 1
...
box.execute("INSERT INTO t1 VALUES (1, false);")
---
- null
- 'Check constraint failed ''ck_unnamed_T1_1'': a = true'
...
box.execute("INSERT INTO t1 VALUES (1, true);")
---
- row_count: 1
...
box.space.T1:drop()
---
...
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, a BOOLEAN DEFAULT true);")
---
- row_count: 1
...
box.execute("INSERT INTO t1 (id) VALUES (1);")
---
- row_count: 1
...
box.space.T1:select()
---
- - [1, true]
...
box.space.T1:drop()
---
...
-- Check that VIEW inherits boolean type.
--
box.execute("CREATE VIEW v AS SELECT b FROM t;")
---
- row_count: 1
...
box.space.V:format()[1]['type']
---
- boolean
...
box.space.V:drop()
---
...
-- Test CAST facilities.
--
box.execute("SELECT CAST(true AS INTEGER);")
---
- metadata:
- name: CAST(true AS INTEGER)
type: integer
rows:
- [1]
...
box.execute("SELECT CAST(true AS TEXT);")
---
- metadata:
- name: CAST(true AS TEXT)
type: string
rows:
- ['TRUE']
...
box.execute("SELECT CAST(true AS NUMBER);")
---
- null
- 'Type mismatch: can not convert true to number'
...
box.execute("SELECT CAST(true AS SCALAR);")
---
- metadata:
- name: CAST(true AS SCALAR)
type: scalar
rows:
- [true]
...
box.execute("SELECT CAST(1 AS BOOLEAN);")
---
- metadata:
- name: CAST(1 AS BOOLEAN)
type: boolean
rows:
- [true]
...
box.execute("SELECT CAST(1.123 AS BOOLEAN);")
---
- metadata:
- name: CAST(1.123 AS BOOLEAN)
type: boolean
rows:
- [true]
...
box.execute("SELECT CAST(0.0 AS BOOLEAN);")
---
- metadata:
- name: CAST(0.0 AS BOOLEAN)
type: boolean
rows:
- [false]
...
box.execute("SELECT CAST(0.00000001 AS BOOLEAN);")
---
- metadata:
- name: CAST(0.00000001 AS BOOLEAN)
type: boolean
rows:
- [true]
...
box.execute("SELECT CAST('abc' AS BOOLEAN);")
---
- null
- 'Type mismatch: can not convert abc to boolean'
...
box.execute("SELECT CAST(' TrUe' AS BOOLEAN);")
---
- metadata:
- name: CAST(' TrUe' AS BOOLEAN)
type: boolean
rows:
- [true]
...
box.execute("SELECT CAST(' falsE ' AS BOOLEAN);")
---
- metadata:
- name: CAST(' falsE ' AS BOOLEAN)
type: boolean
rows:
- [false]
...
box.execute("SELECT CAST(' fals' AS BOOLEAN);")
---
- null
- 'Type mismatch: can not convert fals to boolean'
...
box.execute("SELECT CAST(X'4D6564766564' AS BOOLEAN);")
---
- null
- 'Type mismatch: can not convert Medved to boolean'
...
-- Make sure that SCALAR can handle boolean values.
--
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, s SCALAR);")
---
- row_count: 1
...
box.execute("INSERT INTO t1 SELECT * FROM t;")
---
- row_count: 1
...
box.execute("SELECT s FROM t1 WHERE s = true;")
---
- metadata:
- name: S
type: scalar
rows:
- [true]
...
box.execute("INSERT INTO t1 VALUES (3, 'abc'), (4, 12.5);")
---
- row_count: 2
...
box.execute("SELECT s FROM t1 WHERE s = true;")
---
- null
- 'Type mismatch: can not convert TEXT to BOOLEAN'
...
box.execute("SELECT s FROM t1 WHERE s < true;")
---
- null
- 'Type mismatch: can not convert TEXT to BOOLEAN'
...
box.execute("SELECT s FROM t1 WHERE s IN (true, 1, 'abcd')")
---
- metadata:
- name: S
type: scalar
rows:
- [true]
...
box.space.T:drop()
---
...
box.space.T1:drop()
---
...
-- Make sure that BOOLEAN is not implicitly converted to INTEGER
-- while inserted to PRIMARY KEY field.
--
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
---
- row_count: 1
...
box.execute("INSERT INTO t1 VALUES (true);")
---
- null
- 'Type mismatch: can not convert true to integer'
...
box.space.T1:drop()
---
...
--
-- gh-4103: If resulting value of arithmetic operations is
-- integers, then make sure its type also integer (not number).
......
......@@ -80,150 +80,6 @@ box.execute("INSERT INTO t1 VALUES('0.0'), ('1.5'), ('3.9312453');")
box.execute("SELECT CAST(f AS INTEGER) FROM t1;")
box.space.T1:drop()
-- Test basic capabilities of boolean type.
--
box.execute("SELECT true;")
box.execute("SELECT false;")
box.execute("SELECT unknown;")
box.execute("SELECT true = false;")
box.execute("SELECT true = true;")
box.execute("SELECT true > false;")
box.execute("SELECT true < false;")
box.execute("SELECT null = true;")
box.execute("SELECT unknown = true;")
box.execute("SELECT 1 = true;")
box.execute("SELECT 'abc' = true;")
box.execute("SELECT 1.123 > true;")
box.execute("SELECT true IN (1, 'abc', true)")
box.execute("SELECT true IN (1, 'abc', false)")
box.execute("SELECT 1 LIMIT true;")
box.execute("SELECT 1 LIMIT 1 OFFSET true;")
box.execute("SELECT 'abc' || true;")
-- Boolean can take part in arithmetic operations.
--
box.execute("SELECT true + false;")
box.execute("SELECT true * 1;")
box.execute("SELECT false / 0;")
box.execute("SELECT not true;")
box.execute("SELECT ~true;")
box.execute("SELECT -true;")
box.execute("SELECT true << 1;")
box.execute("SELECT true | 1;")
box.execute("SELECT true and false;")
box.execute("SELECT true or unknown;")
box.execute("CREATE TABLE t (id INT PRIMARY KEY, b BOOLEAN);")
box.execute("INSERT INTO t VALUES (1, true);")
box.execute("INSERT INTO t VALUES (2, false);")
box.execute("INSERT INTO t VALUES (3, unknown)")
box.execute("SELECT b FROM t;")
box.execute("SELECT b FROM t WHERE b = false;")
box.execute("SELECT b FROM t WHERE b IS NULL;")
box.execute("SELECT b FROM t WHERE b IN (false, 1, 'abc')")
box.execute("SELECT b FROM t WHERE b BETWEEN false AND true;")
box.execute("SELECT b FROM t WHERE b BETWEEN true AND false;")
box.execute("SELECT b FROM t ORDER BY b;")
box.execute("SELECT b FROM t ORDER BY +b;")
box.execute("SELECT b FROM t ORDER BY b LIMIT 1;")
box.execute("SELECT b FROM t GROUP BY b LIMIT 1;")
box.execute("SELECT b FROM t LIMIT true;")
-- Most of aggregates don't accept boolean arguments.
--
box.execute("SELECT sum(b) FROM t;")
box.execute("SELECT avg(b) FROM t;")
box.execute("SELECT total(b) FROM t;")
box.execute("SELECT min(b) FROM t;")
box.execute("SELECT max(b) FROM t;")
box.execute("SELECT count(b) FROM t;")
box.execute("SELECT group_concat(b) FROM t;")
-- Check other built-in functions.
--
box.execute("SELECT lower(b) FROM t;")
box.execute("SELECT upper(b) FROM t;")
box.execute("SELECT abs(b) FROM t;")
box.execute("SELECT typeof(b) FROM t;")
box.execute("SELECT quote(b) FROM t;")
box.execute("SELECT LEAST(b, true) FROM t;")
box.execute("SELECT quote(b) FROM t;")
-- Test index search using boolean values.
--
box.execute("CREATE INDEX ib ON t(b);")
box.execute("SELECT b FROM t WHERE b = false;")
box.execute("SELECT b FROM t WHERE b OR unknown ORDER BY b;")
-- Test UPDATE on boolean field.
--
box.execute("UPDATE t SET b = true WHERE b = false;")
box.execute("SELECT b FROM t;")
-- Test constraints functionality.
--
box.execute("CREATE TABLE parent (id INT PRIMARY KEY, a BOOLEAN UNIQUE);")
box.space.T:truncate()
box.execute("ALTER TABLE t ADD CONSTRAINT fk1 FOREIGN KEY (b) REFERENCES parent (a);")
box.execute("INSERT INTO t VALUES (1, true);")
box.execute("INSERT INTO parent VALUES (1, true);")
box.execute("INSERT INTO t VALUES (1, true);")
box.execute("ALTER TABLE t DROP CONSTRAINT fk1;")
box.space.PARENT:drop()
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, a BOOLEAN CHECK (a = true));")
box.execute("INSERT INTO t1 VALUES (1, false);")
box.execute("INSERT INTO t1 VALUES (1, true);")
box.space.T1:drop()
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, a BOOLEAN DEFAULT true);")
box.execute("INSERT INTO t1 (id) VALUES (1);")
box.space.T1:select()
box.space.T1:drop()
-- Check that VIEW inherits boolean type.
--
box.execute("CREATE VIEW v AS SELECT b FROM t;")
box.space.V:format()[1]['type']
box.space.V:drop()
-- Test CAST facilities.
--
box.execute("SELECT CAST(true AS INTEGER);")
box.execute("SELECT CAST(true AS TEXT);")
box.execute("SELECT CAST(true AS NUMBER);")
box.execute("SELECT CAST(true AS SCALAR);")
box.execute("SELECT CAST(1 AS BOOLEAN);")
box.execute("SELECT CAST(1.123 AS BOOLEAN);")
box.execute("SELECT CAST(0.0 AS BOOLEAN);")
box.execute("SELECT CAST(0.00000001 AS BOOLEAN);")
box.execute("SELECT CAST('abc' AS BOOLEAN);")
box.execute("SELECT CAST(' TrUe' AS BOOLEAN);")
box.execute("SELECT CAST(' falsE ' AS BOOLEAN);")
box.execute("SELECT CAST(' fals' AS BOOLEAN);")
box.execute("SELECT CAST(X'4D6564766564' AS BOOLEAN);")
-- Make sure that SCALAR can handle boolean values.
--
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY, s SCALAR);")
box.execute("INSERT INTO t1 SELECT * FROM t;")
box.execute("SELECT s FROM t1 WHERE s = true;")
box.execute("INSERT INTO t1 VALUES (3, 'abc'), (4, 12.5);")
box.execute("SELECT s FROM t1 WHERE s = true;")
box.execute("SELECT s FROM t1 WHERE s < true;")
box.execute("SELECT s FROM t1 WHERE s IN (true, 1, 'abcd')")
box.space.T:drop()
box.space.T1:drop()
-- Make sure that BOOLEAN is not implicitly converted to INTEGER
-- while inserted to PRIMARY KEY field.
--
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
box.execute("INSERT INTO t1 VALUES (true);")
box.space.T1:drop()
--
-- gh-4103: If resulting value of arithmetic operations is
-- integers, then make sure its type also integer (not number).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment