Skip to content

Commit 9ccd2a6

Browse files
committed
✅ field types are always uppercase
At first I thought this issue introduced in #132 but it's most likely something todo with sqlite3 core changes.
1 parent 41c4440 commit 9ccd2a6

File tree

4 files changed

+37
-48
lines changed

4 files changed

+37
-48
lines changed

lua/sqlite/stmt.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ local sqlite_datatypes = {
126126
---@TODO should accept 1-index
127127
function sqlstmt:convert_type(idx)
128128
local convert_dt = {
129-
["integer"] = "number",
130-
["float"] = "number",
131-
["double"] = "number",
132-
["text"] = "string",
133-
["blob"] = "binary",
134-
["null"] = nil,
129+
["INTEGER"] = "number",
130+
["FLOAT"] = "number",
131+
["DOUBLE"] = "number",
132+
["TEXT"] = "string",
133+
["BLOB"] = "binary",
134+
["NULL"] = nil,
135135
}
136136
return convert_dt[clib.to_str(clib.column_decltype(self.pstmt, idx))]
137137
end

test/auto/db_spec.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -687,26 +687,26 @@ describe("sqlite.db", function()
687687
cid = 0,
688688
primary = false,
689689
required = false,
690-
type = "text",
690+
type = "TEXT",
691691
},
692692
b = {
693693
cid = 1,
694694
primary = false,
695695
required = false,
696-
type = "int",
696+
type = "INT",
697697
},
698698
c = {
699699
cid = 2,
700700
primary = false,
701701
required = true,
702-
type = "int",
702+
type = "INT",
703703
},
704704
d = {
705705
cid = 3,
706706
default = "def",
707707
primary = false,
708708
required = false,
709-
type = "text",
709+
type = "TEXT",
710710
},
711711
}, sch)
712712
end)
@@ -718,25 +718,25 @@ describe("sqlite.db", function()
718718
cid = 0,
719719
primary = false,
720720
required = false,
721-
type = "text",
721+
type = "TEXT",
722722
},
723723
b = {
724724
cid = 1,
725725
primary = false,
726726
required = false,
727-
type = "int",
727+
type = "INT",
728728
},
729729
c = {
730730
cid = 2,
731731
primary = false,
732732
required = true,
733-
type = "int",
733+
type = "INT",
734734
},
735735
d = {
736736
cid = 3,
737737
primary = false,
738738
required = false,
739-
type = "text",
739+
type = "TEXT",
740740
default = "def",
741741
},
742742
}, sch)
@@ -763,7 +763,7 @@ describe("sqlite.db", function()
763763
it("skip overriding the table schema if it exists", function()
764764
db:create("test", { id = "not_a_type", ensure = true })
765765
local sch = db:schema "test"
766-
eq("text", sch.title.type, "should exists and should be still text not be nil")
766+
eq("TEXT", sch.title.type, "should exists and should be still text not be nil")
767767
end)
768768
it("auto enable foreign_keys on usage", function()
769769
db:create("test_keys", {

test/auto/stmt_spec.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ describe("stmt", function()
5151

5252
local db, expectedlist, expectedkv, s
5353
db = conn() -- start of first suit test.
54-
for _, v in pairs {
55-
[[create table todos(id integer primary key, title text, desc text, deadline integer);]],
56-
[[insert into todos (title,desc,deadline) values("Create something", "Don't you dare to tell conni", 2021);]],
57-
[[insert into todos (title,desc,deadline) values("Don't work on something else", 'keep conni close by :P', 2021);]],
58-
} do
54+
for _, v in
55+
pairs {
56+
[[create table todos(id integer primary key, title text, desc text, deadline integer);]],
57+
[[insert into todos (title,desc,deadline) values("Create something", "Don't you dare to tell conni", 2021);]],
58+
[[insert into todos (title,desc,deadline) values("Don't work on something else", 'keep conni close by :P', 2021);]],
59+
}
60+
do
5961
eval(db, v)
6062
end
6163

test/auto/tbl_spec.lua

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ describe("sqlite.tbl", function()
6161
cid = 0,
6262
primary = false,
6363
required = false,
64-
type = "int",
64+
type = "INT",
6565
},
6666
name = {
6767
cid = 1,
6868
primary = false,
6969
required = false,
70-
type = "text",
70+
type = "TEXT",
7171
},
7272
}
7373
local new = db:tbl("newtbl", opts)
@@ -92,19 +92,19 @@ describe("sqlite.tbl", function()
9292
cid = 0,
9393
primary = false,
9494
required = false,
95-
type = "integer",
95+
type = "INTEGER",
9696
},
9797
b = {
9898
cid = 1,
9999
primary = false,
100100
required = false,
101-
type = "text",
101+
type = "TEXT",
102102
},
103103
c = {
104104
cid = 2,
105105
primary = false,
106106
required = false,
107-
type = "text",
107+
type = "TEXT",
108108
},
109109
}, t1:schema())
110110
end)
@@ -117,19 +117,19 @@ describe("sqlite.tbl", function()
117117
cid = 0,
118118
primary = false,
119119
required = false,
120-
type = "text",
120+
type = "TEXT",
121121
},
122122
d = {
123123
cid = 1,
124124
primary = false,
125125
required = false,
126-
type = "text",
126+
type = "TEXT",
127127
},
128128
id = {
129129
cid = 2,
130130
primary = false,
131131
required = false,
132-
type = "int",
132+
type = "INT",
133133
},
134134
}
135135
eq(true, t2:schema(schema), "Should return true")
@@ -142,19 +142,19 @@ describe("sqlite.tbl", function()
142142
cid = 0,
143143
primary = false,
144144
required = false,
145-
type = "text",
145+
type = "TEXT",
146146
},
147147
f = {
148148
cid = 1,
149149
primary = false,
150150
required = false,
151-
type = "text",
151+
type = "TEXT",
152152
},
153153
id = {
154154
cid = 2,
155155
primary = false,
156156
required = false,
157-
type = "int",
157+
type = "INT",
158158
},
159159
}
160160
eq(true, t2:schema(new), "Should return true")
@@ -302,26 +302,17 @@ describe("sqlite.tbl", function()
302302
{ a = 12, b = "srd", c = "fn" },
303303
{ a = 32, b = "sbs", c = "en" },
304304
{ a = 35, b = "cba", c = "qa" },
305-
}, t1:sort(
306-
{ where = { a = { 32, 12, 35 } } },
307-
"a"
308-
))
305+
}, t1:sort({ where = { a = { 32, 12, 35 } } }, "a"))
309306
eq({
310307
{ a = 32, b = "sbs", c = "en" },
311308
{ a = 12, b = "srd", c = "fn" },
312309
{ a = 35, b = "cba", c = "qa" },
313-
}, t1:sort(
314-
{ where = { a = { 32, 12, 35 } } },
315-
"c"
316-
))
310+
}, t1:sort({ where = { a = { 32, 12, 35 } } }, "c"))
317311
eq({
318312
{ a = 35, b = "cba", c = "qa" },
319313
{ a = 32, b = "sbs", c = "en" },
320314
{ a = 12, b = "srd", c = "fn" },
321-
}, t1:sort(
322-
{ where = { a = { 32, 12, 35 } } },
323-
"b"
324-
))
315+
}, t1:sort({ where = { a = { 32, 12, 35 } } }, "b"))
325316
end)
326317

327318
it("can use a custom comparison function", function()
@@ -332,11 +323,7 @@ describe("sqlite.tbl", function()
332323
{ a = 12, b = "srd", c = "fn" },
333324
{ a = 32, b = "sbs", c = "en" },
334325
{ a = 35, b = "cba", c = "qa" },
335-
}, t1:sort(
336-
{ where = { a = { 32, 12, 35 } } },
337-
"b",
338-
comp
339-
))
326+
}, t1:sort({ where = { a = { 32, 12, 35 } } }, "b", comp))
340327
end)
341328
end)
342329

0 commit comments

Comments
 (0)