interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / import01.sql

225 lines · 5979 bytes Raw Blame History
1#!sqlite3
2#
3# 2025-12-28
4#
5# The author disclaims copyright to this source code. In place of
6# a legal notice, here is a blessing:
7#
8# May you do good and not evil.
9# May you find forgiveness for yourself and forgive others.
10# May you share freely, never taking more than you give.
11#
12#***********************************************************************
13#
14# Test cases for the ".import" command of the CLI.
15# To run these tests:
16#
17# ./sqlite3 test/import01.sql
18#
19
20.testcase setup
21.open :memory:
22.mode tty
23.check ''
24
25.if NOT capable('vtab')
26.exit
27.endif
28
29.testcase 100
30CREATE TABLE t1(a,b,c);
31.import -csv <<END t1
32111,222,333
33abc,def,ghi
34END
35SELECT * FROM t1;
36.check <<END
37╭───────┬───────┬───────╮
38│ a │ b │ c │
39╞═══════╪═══════╪═══════╡
40│ '111' │ '222' │ '333' │
41│ abc │ def │ ghi │
42╰───────┴───────┴───────╯
43END
44
45.testcase 110
46DELETE FROM t1;
47.import -colsep ";" <<END t1
48this;is a;test
49one;two;three
50END
51SELECT * FROM t1;
52.check <<END
53╭──────┬──────┬───────╮
54│ a │ b │ c │
55╞══════╪══════╪═══════╡
56│ this │ is a │ test │
57│ one │ two │ three │
58╰──────┴──────┴───────╯
59END
60
61.testcase 120
62DELETE FROM t1;
63.import -colsep "," -rowsep ';' <<END t1
64this,is a,test;one,two,three;
65END
66SELECT * FROM t1;
67.check <<END
68╭──────┬──────┬───────╮
69│ a │ b │ c │
70╞══════╪══════╪═══════╡
71│ this │ is a │ test │
72│ one │ two │ three │
73╰──────┴──────┴───────╯
74END
75
76.testcase 130
77DELETE FROM t1;
78.import -csv -colsep "," -rowsep "\n" <<END t1
79this,"is a","test ""with quotes"""
80"second",,"line"
81END
82SELECT * FROM t1;
83.check <<END
84╭────────┬──────┬────────────────────╮
85│ a │ b │ c │
86╞════════╪══════╪════════════════════╡
87│ this │ is a │ test "with quotes" │
88│ second │ │ line │
89╰────────┴──────┴────────────────────╯
90END
91.testcase 131
92DELETE FROM t1;
93.import -ascii -colsep "," -rowsep "\n" <<END t1
94this,"is a","test ""with quotes"""
95"second",,"line"
96END
97SELECT * FROM t1;
98.check <<END
99╭──────────┬────────┬────────────────────────╮
100│ a │ b │ c │
101╞══════════╪════════╪════════════════════════╡
102│ this │ "is a" │ "test ""with quotes""" │
103│ "second" │ │ "line" │
104╰──────────┴────────┴────────────────────────╯
105END
106
107.testcase 140
108DROP TABLE t1;
109.import -csv <<END t1
110"abc","def","xy z"
111"This","is","a"
112"test","...",
113END
114SELECT * FROM t1;
115.check <<END
116╭──────┬─────┬──────╮
117│ abc │ def │ xy z │
118╞══════╪═════╪══════╡
119│ This │ is │ a │
120│ test │ ... │ │
121╰──────┴─────┴──────╯
122END
123.testcase 141
124SELECT sql FROM sqlite_schema WHERE name='t1';
125.check <<END
126╭───────────────────────╮
127│ sql │
128╞═══════════════════════╡
129│ CREATE TABLE "t1"( │
130│ "abc", "def", "xy z") │
131╰───────────────────────╯
132END
133
134.testcase 150
135DROP TABLE t1;
136.import -csv -v <<END t1
137"abc","def","xy z"
138"This","is","a"
139"test","...",
140END
141SELECT * FROM t1;
142.check <<END
143Column separator ",", row separator "\n"
144CREATE TABLE "main"."t1"(
145"abc", "def", "xy z")
146
147Added 2 rows with 0 errors using 3 lines of input
148╭──────┬─────┬──────╮
149│ abc │ def │ xy z │
150╞══════╪═════╪══════╡
151│ This │ is │ a │
152│ test │ ... │ │
153╰──────┴─────┴──────╯
154END
155
156.testcase 160
157.mode -reset box
158DROP TABLE t1;
159.import -csv -schema TEMP <<END t2
160"x"
161"abcdef"
162END
163SELECT * FROM t2;
164.tables
165.check <<END
166╭────────╮
167│ x │
168╞════════╡
169│ abcdef │
170╰────────╯
171temp.t2
172END
173
174.testcase 170
175.import -csv -skip 2 <<END t3
176a,b,c
177d,e,f
178g,h,i
179j,k,l
180m,n,o
181END
182SELECT * FROM t3;
183.check <<END
184╭───┬───┬───╮
185│ g │ h │ i │
186╞═══╪═══╪═══╡
187│ j │ k │ l │
188│ m │ n │ o │
189╰───┴───┴───╯
190END
191
192.testcase 180
193DELETE FROM t3;
194.import -csv -skip 7 <<END t3
195a,b,c
196d,e,f
197g,h,i
198j,k,l
199m,n,o
200END
201SELECT * FROM t3;
202.check <<END
203╭───┬───┬───╮
204│ g │ h │ i │
205╘═══╧═══╧═══╛
206END
207
208.testcase 200 --error-prefix ERROR:
209.import -csv
210.check 'ERROR: Missing FILE argument'
211.testcase 201
212.import -csv file1.csv
213.check 'ERROR: Missing TABLE argument'
214.testcase --error-prefix test-error: 202
215.import -csvxyzzy file1.csv
216.check <<END
217test-error: .import -csvxyzzy file1.csv
218test-error: ^--- unknown option
219END
220.testcase 203
221.import -csv file1.csv t4 -colsep
222.check <<END
223test-error: .import -csv file1.csv t4 -colsep
224test-error: missing argument ---^
225END