sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / vec1 / test / vec1create.test
| 1 | # 2026-08-19 |
| 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 | # |
| 12 | # |
| 13 | |
| 14 | source [file join [file dirname [info script]] vec1_common.tcl] |
| 15 | set testprefix vec1config |
| 16 | vec1_load db |
| 17 | |
| 18 | do_execsql_test 1.0 { |
| 19 | CREATE VIRTUAL TABLE v1 USING vec1("vector column", "meta column"); |
| 20 | } |
| 21 | |
| 22 | do_execsql_test 1.1 { |
| 23 | SELECT v1."vector column", v1."meta column" FROM v1 |
| 24 | } |
| 25 | |
| 26 | |
| 27 | foreach {tn cols err} { |
| 28 | 1 { vector BLOB } {vec1: trailing characters after column name} |
| 29 | 2 { v, col BLOB } {vec1: trailing characters after column name} |
| 30 | 3 { v, [col BLOB]x } {vec1: trailing characters after column name} |
| 31 | 4 { "vector col" BLOB } {vec1: trailing characters after column name} |
| 32 | 5 { v, +i } {vec1: near "+": syntax error} |
| 33 | } { |
| 34 | execsql { DROP TABLE IF EXISTS v1 } |
| 35 | do_catchsql_test 1.2.$tn " |
| 36 | CREATE VIRTUAL TABLE v1 USING vec1( $cols ) |
| 37 | " [list 1 $err] |
| 38 | } |
| 39 | |
| 40 | foreach {tn cols lCol} { |
| 41 | 1 { vector } {vector} |
| 42 | 2 { "vector col" } {{vector col}} |
| 43 | 3 { v, 'meta 1' } {v {meta 1}} |
| 44 | 4 { v, 'Dave''s col' } {v {Dave's col}} |
| 45 | 5 { v, [column [[[] } {v {column [[[}} |
| 46 | } { |
| 47 | execsql { DROP TABLE IF EXISTS v1 } |
| 48 | |
| 49 | do_test 1.3.$tn { |
| 50 | execsql "CREATE VIRTUAL TABLE v1 USING vec1( $cols );" |
| 51 | set ret [list] |
| 52 | db eval { PRAGMA table_info = v1 } a { |
| 53 | lappend ret $a(name) |
| 54 | } |
| 55 | set ret |
| 56 | } $lCol |
| 57 | } |
| 58 | |
| 59 | #------------------------------------------------------------------------- |
| 60 | reset_db |
| 61 | vec1_load db |
| 62 | |
| 63 | do_execsql_test 2.0 { |
| 64 | CREATE VIRTUAL TABLE "Count Duckula's 11" USING vec1( |
| 65 | "vector column", "meta column" |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | do_execsql_test 2.1 { |
| 70 | SELECT * FROM "Count Duckula's 11"; |
| 71 | } |
| 72 | |
| 73 | do_execsql_test 2.2 { |
| 74 | ALTER TABLE "Count Duckula's 11" RENAME TO "Bill's table"; |
| 75 | } |
| 76 | |
| 77 | do_execsql_test 2.3 { |
| 78 | INSERT INTO "Bill's table" VALUES(random_vector(10), 1100); |
| 79 | INSERT INTO "Bill's table" VALUES(random_vector(10), 'text'); |
| 80 | INSERT INTO "Bill's table"(cmd, arg) VALUES('rebuild', '{index:"flat"}'); |
| 81 | PRAGMA integrity_check; |
| 82 | } {ok} |
| 83 | |
| 84 | do_execsql_test 2.4 { |
| 85 | ALTER TABLE "Bill's table" RENAME TO "a b c ''' d e f"; |
| 86 | PRAGMA integrity_check; |
| 87 | } {ok} |
| 88 | |
| 89 | #------------------------------------------------------------------------- |
| 90 | # Try to create tables with reserved column names "rowid" or "distance". |
| 91 | # Report https://sqlite.org/vec1/forumpost/05e888d619 |
| 92 | # |
| 93 | reset_db |
| 94 | vec1_load db |
| 95 | |
| 96 | breakpoint |
| 97 | foreach {tn cols err} { |
| 98 | 1 "rowid" {1 {vec1: reserved column name: rowid}} |
| 99 | 2 "ROWID" {1 {vec1: reserved column name: ROWID}} |
| 100 | 3 " [rowid] " {1 {vec1: reserved column name: [rowid]}} |
| 101 | 4 " \"rowid\" " {1 {vec1: reserved column name: "rowid"}} |
| 102 | 5 " 'roWid' " {1 {vec1: reserved column name: 'roWid'}} |
| 103 | 6 " [ rowid]" {0 {}} |
| 104 | 5 " 'ro''Wid' " {0 {}} |
| 105 | } { |
| 106 | execsql { DROP TABLE IF EXISTS g1 } |
| 107 | do_catchsql_test 3.$tn " |
| 108 | CREATE VIRTUAL TABLE g1 USING vec1 ( $cols ) |
| 109 | " $err |
| 110 | } |
| 111 | |
| 112 | |
| 113 | finish_test |
| 114 |