File: nullrep.sql

package info (click to toggle)
hsqldb1.8.0 1.8.0.10%2Bdfsg-10
  • links: PTS
  • area: main
  • in suites: buster
  • size: 13,432 kB
  • sloc: java: 75,802; xml: 11,392; sql: 1,556; sh: 847; makefile: 57
file content (114 lines) | stat: -rw-r--r-- 3,178 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * $Id: nullrep.sql,v 1.1 2007/08/09 03:28:37 unsaved Exp $
 *
 * Tests enforcement of null-representation token 
 */

/** This is the default on UNIX.
 *  Our *.dsv test files are stored as binaries, so this is required
 *  to run tests on Windows: */
* *DSV_ROW_DELIM = \n

CREATE TABLE t (i INT, vc VARCHAR);

INSERT INTO t VALUES(1, 'one');
/** For INPUT, the NULLREP is only used for DSV imports, since unquoted
 *  null works perfectly for other forms of input.
 *  Therefore, following should enter "[null]" literally.
 */
INSERT INTO t VALUES(2, '[null]');
INSERT INTO t VALUES(3, null);

* COUNT _
SELECT count(*) FROM t WHERE i = 2 AND vc IS NULL;
* if (*COUNT != 0)
    \q Seems that non-DSV insertion of '[null]' inserted a real NULL
* end if

* COUNT _
SELECT count(*) FROM t WHERE i = 3 AND vc IS null;
* if (*COUNT != 1)
    \q Seems that non-DSV insertion of plain null did not insert a SQL NULL
* end if
DROP TABLE t;


/* Now test nullrep tokens with DSV imports */
CREATE TABLE t (
    id VARCHAR PRIMARY KEY,
    i INTEGER,
    r REAL,
    d DATE,
    t TIMESTAMP,
    v VARCHAR,
    b BOOLEAN
);

\m nullrep.dsv
SELECT count(*) FROM t WHERE id = 'wspaces' AND i IS null;
*if (*? != 1)
    \q Insertion of INTEGER space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND r IS null;
*if (*? != 1)
    \q Insertion of REAL space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND d IS null;
*if (*? != 1)
    \q Insertion of DATE space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND t IS null;
*if (*? != 1)
    \q Insertion of TIMESTAMP space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND v = '  [null]  ';
*if (*? != 1)
    \q Insertion of VARCHAR w/ space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND b IS null;
*if (*? != 1)
    \q Insertion of BOOLEAN space-embedded null-rep-token failed
*end if

DELETE FROM t;

/** Repeat test with some non-default DSV settings */
* *NULL_REP_TOKEN = %%
* *DSV_COL_DELIM = :
* *DSV_ROW_DELIM = }\n

\m nullrep-alt.dsv
SELECT count(*) FROM t WHERE id = 'wspaces' AND i IS null;
*if (*? != 1)
    \q Insertion of INTEGER space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND r IS null;
*if (*? != 1)
    \q Insertion of REAL space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND d IS null;
*if (*? != 1)
    \q Insertion of DATE space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND t IS null;
*if (*? != 1)
    \q Insertion of TIMESTAMP space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND v = '  %%  ';
*if (*? != 1)
    \q Insertion of VARCHAR w/ space-embedded null-rep-token failed
*end if

SELECT count(*) FROM t WHERE id = 'wspaces' AND b IS null;
*if (*? != 1)
    \q Insertion of BOOLEAN space-embedded null-rep-token failed
*end if