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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
test_run = require('test_run').new()
---
...
engine = test_run:get_cfg('engine')
---
...
_ = box.space._session_settings:update('sql_default_engine', {{'=', 2, engine}})
---
...
-- box.cfg()
-- create space
box.execute("CREATE TABLE zoobar (c1 INT, c2 INT PRIMARY KEY, c3 TEXT, c4 INT)")
---
- row_count: 1
...
box.execute("CREATE UNIQUE INDEX zoobar2 ON zoobar(c1, c4)")
---
- row_count: 1
...
-- Seed entry
for i=1, 100 do box.execute(string.format("INSERT INTO zoobar VALUES (%d, %d, 'c3', 444)", i+i, i)) end
---
...
-- Check table is not empty
box.execute("SELECT * FROM zoobar")
---
- metadata:
- name: C1
type: integer
- name: C2
type: integer
- name: C3
type: string
- name: C4
type: integer
rows:
- [2, 1, 'c3', 444]
- [4, 2, 'c3', 444]
- [6, 3, 'c3', 444]
- [8, 4, 'c3', 444]
- [10, 5, 'c3', 444]
- [12, 6, 'c3', 444]
- [14, 7, 'c3', 444]
- [16, 8, 'c3', 444]
- [18, 9, 'c3', 444]
- [20, 10, 'c3', 444]
- [22, 11, 'c3', 444]
- [24, 12, 'c3', 444]
- [26, 13, 'c3', 444]
- [28, 14, 'c3', 444]
- [30, 15, 'c3', 444]
- [32, 16, 'c3', 444]
- [34, 17, 'c3', 444]
- [36, 18, 'c3', 444]
- [38, 19, 'c3', 444]
- [40, 20, 'c3', 444]
- [42, 21, 'c3', 444]
- [44, 22, 'c3', 444]
- [46, 23, 'c3', 444]
- [48, 24, 'c3', 444]
- [50, 25, 'c3', 444]
- [52, 26, 'c3', 444]
- [54, 27, 'c3', 444]
- [56, 28, 'c3', 444]
- [58, 29, 'c3', 444]
- [60, 30, 'c3', 444]
- [62, 31, 'c3', 444]
- [64, 32, 'c3', 444]
- [66, 33, 'c3', 444]
- [68, 34, 'c3', 444]
- [70, 35, 'c3', 444]
- [72, 36, 'c3', 444]
- [74, 37, 'c3', 444]
- [76, 38, 'c3', 444]
- [78, 39, 'c3', 444]
- [80, 40, 'c3', 444]
- [82, 41, 'c3', 444]
- [84, 42, 'c3', 444]
- [86, 43, 'c3', 444]
- [88, 44, 'c3', 444]
- [90, 45, 'c3', 444]
- [92, 46, 'c3', 444]
- [94, 47, 'c3', 444]
- [96, 48, 'c3', 444]
- [98, 49, 'c3', 444]
- [100, 50, 'c3', 444]
- [102, 51, 'c3', 444]
- [104, 52, 'c3', 444]
- [106, 53, 'c3', 444]
- [108, 54, 'c3', 444]
- [110, 55, 'c3', 444]
- [112, 56, 'c3', 444]
- [114, 57, 'c3', 444]
- [116, 58, 'c3', 444]
- [118, 59, 'c3', 444]
- [120, 60, 'c3', 444]
- [122, 61, 'c3', 444]
- [124, 62, 'c3', 444]
- [126, 63, 'c3', 444]
- [128, 64, 'c3', 444]
- [130, 65, 'c3', 444]
- [132, 66, 'c3', 444]
- [134, 67, 'c3', 444]
- [136, 68, 'c3', 444]
- [138, 69, 'c3', 444]
- [140, 70, 'c3', 444]
- [142, 71, 'c3', 444]
- [144, 72, 'c3', 444]
- [146, 73, 'c3', 444]
- [148, 74, 'c3', 444]
- [150, 75, 'c3', 444]
- [152, 76, 'c3', 444]
- [154, 77, 'c3', 444]
- [156, 78, 'c3', 444]
- [158, 79, 'c3', 444]
- [160, 80, 'c3', 444]
- [162, 81, 'c3', 444]
- [164, 82, 'c3', 444]
- [166, 83, 'c3', 444]
- [168, 84, 'c3', 444]
- [170, 85, 'c3', 444]
- [172, 86, 'c3', 444]
- [174, 87, 'c3', 444]
- [176, 88, 'c3', 444]
- [178, 89, 'c3', 444]
- [180, 90, 'c3', 444]
- [182, 91, 'c3', 444]
- [184, 92, 'c3', 444]
- [186, 93, 'c3', 444]
- [188, 94, 'c3', 444]
- [190, 95, 'c3', 444]
- [192, 96, 'c3', 444]
- [194, 97, 'c3', 444]
- [196, 98, 'c3', 444]
- [198, 99, 'c3', 444]
- [200, 100, 'c3', 444]
...
-- Do clean up
box.execute("DELETE FROM zoobar")
---
- row_count: 100
...
-- Make sure table is empty
box.execute("SELECT * from zoobar")
---
- metadata:
- name: C1
type: integer
- name: C2
type: integer
- name: C3
type: string
- name: C4
type: integer
rows: []
...
-- Cleanup
box.execute("DROP INDEX zoobar2 ON zoobar")
---
- row_count: 1
...
box.execute("DROP TABLE zoobar")
---
- row_count: 1
...
-- Debug
-- require("console").start()
--
-- gh-4183: Check if there is a garbage in case of failure to
-- create a constraint, when more than one constraint of the same
-- type is created with the same name and in the same
-- CREATE TABLE statement.
--
box.execute("CREATE TABLE t1(id INT PRIMARY KEY, CONSTRAINT ck1 CHECK(id > 0), CONSTRAINT ck1 CHECK(id < 0));")
---
- null
- CHECK constraint 'CK1' already exists in space 'T1'
...
box.space.t1
---
- null
...
box.space._ck_constraint:select()
---
- []
...
box.execute("CREATE TABLE t2(id INT PRIMARY KEY, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t2, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t2);")
---
- null
- FOREIGN KEY constraint 'FK1' already exists in space 'T2'
...
box.space.t2
---
- null
...
box.space._fk_constraint:select()
---
- []
...
--
-- Make sure that keys for tuples inserted into system spaces were
-- not stored in temporary cells.
--
box.execute("CREATE TABLE t3(id INT PRIMARY KEY, CONSTRAINT ck1 CHECK(id > 0), CONSTRAINT ck1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT ck1 CHECK(id < 0));")
---
- null
- FOREIGN KEY constraint 'CK1' already exists in space 'T3'
...
box.space.t1
---
- null
...
box.space._ck_constraint:select()
---
- []
...
box.space._fk_constraint:select()
---
- []
...
|