whereB.test 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. # 2009 August 13
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing WHERE clause conditions with
  13. # subtle affinity issues.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # For this set of tests:
  18. #
  19. # * t1.y holds an integer value with affinity NONE
  20. # * t2.b holds a text value with affinity TEXT
  21. #
  22. # These values are not equal and because neither affinity is NUMERIC
  23. # no type conversion occurs.
  24. #
  25. do_test whereB-1.1 {
  26. db eval {
  27. CREATE TABLE t1(x,y); -- affinity of t1.y is NONE
  28. INSERT INTO t1 VALUES(1,99);
  29. CREATE TABLE t2(a, b TEXT); -- affinity of t2.b is TEXT
  30. CREATE INDEX t2b ON t2(b);
  31. INSERT INTO t2 VALUES(2,99);
  32. SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
  33. }
  34. } {1 2 0}
  35. do_test whereB-1.2 {
  36. db eval {
  37. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  38. }
  39. } {}
  40. do_test whereB-1.3 {
  41. db eval {
  42. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  43. }
  44. } {}
  45. do_test whereB-1.4 {
  46. db eval {
  47. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  48. }
  49. } {}
  50. do_test whereB-1.100 {
  51. db eval {
  52. DROP INDEX t2b;
  53. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  54. }
  55. } {}
  56. do_test whereB-1.101 {
  57. db eval {
  58. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  59. }
  60. } {}
  61. do_test whereB-1.102 {
  62. db eval {
  63. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  64. }
  65. } {}
  66. # For this set of tests:
  67. #
  68. # * t1.y holds a text value with affinity TEXT
  69. # * t2.b holds an integer value with affinity NONE
  70. #
  71. # These values are not equal and because neither affinity is NUMERIC
  72. # no type conversion occurs.
  73. #
  74. do_test whereB-2.1 {
  75. db eval {
  76. DROP TABLE t1;
  77. DROP TABLE t2;
  78. CREATE TABLE t1(x, y TEXT); -- affinity of t1.y is TEXT
  79. INSERT INTO t1 VALUES(1,99);
  80. CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
  81. CREATE INDEX t2b ON t2(b);
  82. INSERT INTO t2 VALUES(2,99);
  83. SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
  84. }
  85. } {1 2 0}
  86. do_test whereB-2.2 {
  87. db eval {
  88. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  89. }
  90. } {}
  91. do_test whereB-2.3 {
  92. db eval {
  93. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  94. }
  95. } {}
  96. do_test whereB-2.4 {
  97. db eval {
  98. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  99. }
  100. } {}
  101. do_test whereB-2.100 {
  102. db eval {
  103. DROP INDEX t2b;
  104. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  105. }
  106. } {}
  107. do_test whereB-2.101 {
  108. db eval {
  109. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  110. }
  111. } {}
  112. do_test whereB-2.102 {
  113. db eval {
  114. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  115. }
  116. } {}
  117. # For this set of tests:
  118. #
  119. # * t1.y holds a text value with affinity NONE
  120. # * t2.b holds an integer value with affinity NONE
  121. #
  122. # These values are not equal and because neither affinity is NUMERIC
  123. # no type conversion occurs.
  124. #
  125. do_test whereB-3.1 {
  126. db eval {
  127. DROP TABLE t1;
  128. DROP TABLE t2;
  129. CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
  130. INSERT INTO t1 VALUES(1,99);
  131. CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
  132. CREATE INDEX t2b ON t2(b);
  133. INSERT INTO t2 VALUES(2,'99');
  134. SELECT x, a, y=b FROM t1, t2;
  135. }
  136. } {1 2 0}
  137. do_test whereB-3.2 {
  138. db eval {
  139. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  140. }
  141. } {}
  142. do_test whereB-3.3 {
  143. db eval {
  144. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  145. }
  146. } {}
  147. do_test whereB-3.4 {
  148. db eval {
  149. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  150. }
  151. } {}
  152. do_test whereB-3.100 {
  153. db eval {
  154. DROP INDEX t2b;
  155. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  156. }
  157. } {}
  158. do_test whereB-3.101 {
  159. db eval {
  160. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  161. }
  162. } {}
  163. do_test whereB-3.102 {
  164. db eval {
  165. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  166. }
  167. } {}
  168. # For this set of tests:
  169. #
  170. # * t1.y holds a text value with affinity NONE
  171. # * t2.b holds an integer value with affinity NUMERIC
  172. #
  173. # Because t2.b has a numeric affinity, type conversion should occur
  174. # and the two fields should be equal.
  175. #
  176. do_test whereB-4.1 {
  177. db eval {
  178. DROP TABLE t1;
  179. DROP TABLE t2;
  180. CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
  181. INSERT INTO t1 VALUES(1,'99');
  182. CREATE TABLE t2(a, b NUMERIC); -- affinity of t2.b is NUMERIC
  183. CREATE INDEX t2b ON t2(b);
  184. INSERT INTO t2 VALUES(2,99);
  185. SELECT x, a, y=b FROM t1, t2;
  186. }
  187. } {1 2 1}
  188. do_test whereB-4.2 {
  189. db eval {
  190. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  191. }
  192. } {1 2 1}
  193. do_test whereB-4.3 {
  194. db eval {
  195. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  196. }
  197. } {1 2 1}
  198. do_test whereB-4.4 {
  199. # In this case the unary "+" operator removes the column affinity so
  200. # the columns compare false
  201. db eval {
  202. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  203. }
  204. } {}
  205. do_test whereB-4.100 {
  206. db eval {
  207. DROP INDEX t2b;
  208. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  209. }
  210. } {1 2 1}
  211. do_test whereB-4.101 {
  212. db eval {
  213. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  214. }
  215. } {1 2 1}
  216. do_test whereB-4.102 {
  217. # In this case the unary "+" operator removes the column affinity so
  218. # the columns compare false
  219. db eval {
  220. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  221. }
  222. } {}
  223. # For this set of tests:
  224. #
  225. # * t1.y holds a text value with affinity NONE
  226. # * t2.b holds an integer value with affinity INTEGER
  227. #
  228. # Because t2.b has a numeric affinity, type conversion should occur
  229. # and the two fields should be equal.
  230. #
  231. do_test whereB-5.1 {
  232. db eval {
  233. DROP TABLE t1;
  234. DROP TABLE t2;
  235. CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
  236. INSERT INTO t1 VALUES(1,'99');
  237. CREATE TABLE t2(a, b INT); -- affinity of t2.b is INTEGER
  238. CREATE INDEX t2b ON t2(b);
  239. INSERT INTO t2 VALUES(2,99);
  240. SELECT x, a, y=b FROM t1, t2;
  241. }
  242. } {1 2 1}
  243. do_test whereB-5.2 {
  244. db eval {
  245. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  246. }
  247. } {1 2 1}
  248. do_test whereB-5.3 {
  249. db eval {
  250. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  251. }
  252. } {1 2 1}
  253. do_test whereB-5.4 {
  254. # In this case the unary "+" operator removes the column affinity so
  255. # the columns compare false
  256. db eval {
  257. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  258. }
  259. } {}
  260. do_test whereB-5.100 {
  261. db eval {
  262. DROP INDEX t2b;
  263. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  264. }
  265. } {1 2 1}
  266. do_test whereB-5.101 {
  267. db eval {
  268. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  269. }
  270. } {1 2 1}
  271. do_test whereB-5.102 {
  272. # In this case the unary "+" operator removes the column affinity so
  273. # the columns compare false
  274. db eval {
  275. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  276. }
  277. } {}
  278. # For this set of tests:
  279. #
  280. # * t1.y holds a text value with affinity NONE
  281. # * t2.b holds an integer value with affinity REAL
  282. #
  283. # Because t2.b has a numeric affinity, type conversion should occur
  284. # and the two fields should be equal.
  285. #
  286. do_test whereB-6.1 {
  287. db eval {
  288. DROP TABLE t1;
  289. DROP TABLE t2;
  290. CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
  291. INSERT INTO t1 VALUES(1,'99');
  292. CREATE TABLE t2(a, b REAL); -- affinity of t2.b is REAL
  293. CREATE INDEX t2b ON t2(b);
  294. INSERT INTO t2 VALUES(2,99.0);
  295. SELECT x, a, y=b FROM t1, t2;
  296. }
  297. } {1 2 1}
  298. do_test whereB-6.2 {
  299. db eval {
  300. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  301. }
  302. } {1 2 1}
  303. do_test whereB-6.3 {
  304. db eval {
  305. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  306. }
  307. } {1 2 1}
  308. do_test whereB-6.4 {
  309. # In this case the unary "+" operator removes the column affinity so
  310. # the columns compare false
  311. db eval {
  312. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  313. }
  314. } {}
  315. do_test whereB-6.100 {
  316. db eval {
  317. DROP INDEX t2b;
  318. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  319. }
  320. } {1 2 1}
  321. do_test whereB-6.101 {
  322. db eval {
  323. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  324. }
  325. } {1 2 1}
  326. do_test whereB-6.102 {
  327. # In this case the unary "+" operator removes the column affinity so
  328. # the columns compare false
  329. db eval {
  330. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  331. }
  332. } {}
  333. # For this set of tests:
  334. #
  335. # * t1.y holds an integer value with affinity NUMERIC
  336. # * t2.b holds a text value with affinity NONE
  337. #
  338. # Because t1.y has a numeric affinity, type conversion should occur
  339. # and the two fields should be equal.
  340. #
  341. do_test whereB-7.1 {
  342. db eval {
  343. DROP TABLE t1;
  344. DROP TABLE t2;
  345. CREATE TABLE t1(x, y NUMERIC); -- affinity of t1.y is NUMERIC
  346. INSERT INTO t1 VALUES(1,99);
  347. CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
  348. CREATE INDEX t2b ON t2(b);
  349. INSERT INTO t2 VALUES(2,'99');
  350. SELECT x, a, y=b FROM t1, t2;
  351. }
  352. } {1 2 1}
  353. do_test whereB-7.2 {
  354. db eval {
  355. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  356. }
  357. } {1 2 1}
  358. do_test whereB-7.3 {
  359. db eval {
  360. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  361. }
  362. } {1 2 1}
  363. do_test whereB-7.4 {
  364. # In this case the unary "+" operator removes the column affinity so
  365. # the columns compare false
  366. db eval {
  367. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  368. }
  369. } {}
  370. do_test whereB-7.100 {
  371. db eval {
  372. DROP INDEX t2b;
  373. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  374. }
  375. } {1 2 1}
  376. do_test whereB-7.101 {
  377. db eval {
  378. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  379. }
  380. } {1 2 1}
  381. do_test whereB-7.102 {
  382. # In this case the unary "+" operator removes the column affinity so
  383. # the columns compare false
  384. db eval {
  385. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  386. }
  387. } {}
  388. # For this set of tests:
  389. #
  390. # * t1.y holds an integer value with affinity INTEGER
  391. # * t2.b holds a text value with affinity NONE
  392. #
  393. # Because t1.y has a numeric affinity, type conversion should occur
  394. # and the two fields should be equal.
  395. #
  396. do_test whereB-8.1 {
  397. db eval {
  398. DROP TABLE t1;
  399. DROP TABLE t2;
  400. CREATE TABLE t1(x, y INT); -- affinity of t1.y is INTEGER
  401. INSERT INTO t1 VALUES(1,99);
  402. CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
  403. CREATE INDEX t2b ON t2(b);
  404. INSERT INTO t2 VALUES(2,'99');
  405. SELECT x, a, y=b FROM t1, t2;
  406. }
  407. } {1 2 1}
  408. do_test whereB-8.2 {
  409. db eval {
  410. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  411. }
  412. } {1 2 1}
  413. do_test whereB-8.3 {
  414. db eval {
  415. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  416. }
  417. } {1 2 1}
  418. do_test whereB-8.4 {
  419. # In this case the unary "+" operator removes the column affinity so
  420. # the columns compare false
  421. db eval {
  422. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  423. }
  424. } {}
  425. do_test whereB-8.100 {
  426. db eval {
  427. DROP INDEX t2b;
  428. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  429. }
  430. } {1 2 1}
  431. do_test whereB-8.101 {
  432. db eval {
  433. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  434. }
  435. } {1 2 1}
  436. do_test whereB-8.102 {
  437. # In this case the unary "+" operator removes the column affinity so
  438. # the columns compare false
  439. db eval {
  440. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  441. }
  442. } {}
  443. # For this set of tests:
  444. #
  445. # * t1.y holds an integer value with affinity REAL
  446. # * t2.b holds a text value with affinity NONE
  447. #
  448. # Because t1.y has a numeric affinity, type conversion should occur
  449. # and the two fields should be equal.
  450. #
  451. do_test whereB-9.1 {
  452. db eval {
  453. DROP TABLE t1;
  454. DROP TABLE t2;
  455. CREATE TABLE t1(x, y REAL); -- affinity of t1.y is REAL
  456. INSERT INTO t1 VALUES(1,99.0);
  457. CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
  458. CREATE INDEX t2b ON t2(b);
  459. INSERT INTO t2 VALUES(2,'99');
  460. SELECT x, a, y=b FROM t1, t2;
  461. }
  462. } {1 2 1}
  463. do_test whereB-9.2 {
  464. db eval {
  465. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  466. }
  467. } {1 2 1}
  468. do_test whereB-9.3 {
  469. db eval {
  470. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  471. }
  472. } {1 2 1}
  473. do_test whereB-9.4 {
  474. # In this case the unary "+" operator removes the column affinity so
  475. # the columns compare false
  476. db eval {
  477. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  478. }
  479. } {}
  480. do_test whereB-9.100 {
  481. db eval {
  482. DROP INDEX t2b;
  483. SELECT x, a, y=b FROM t1, t2 WHERE y=b;
  484. }
  485. } {1 2 1}
  486. do_test whereB-9.101 {
  487. db eval {
  488. SELECT x, a, y=b FROM t1, t2 WHERE b=y;
  489. }
  490. } {1 2 1}
  491. do_test whereB-9.102 {
  492. # In this case the unary "+" operator removes the column affinity so
  493. # the columns compare false
  494. db eval {
  495. SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
  496. }
  497. } {}
  498. finish_test