Skip to content

Commit 68e95ea

Browse files
committed
Add new tests for count() function
1 parent 1de73b3 commit 68e95ea

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

testing/agg-functions.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ do_execsql_test select-count-constant-false {
4747
SELECT count(*) FROM users WHERE false;
4848
} {0}
4949

50+
do_execsql_test select-count-star {
51+
SELECT count(*) FROM counter;
52+
} {10}
53+
54+
do_execsql_test select-count-field-t {
55+
SELECT count(t) FROM counter;
56+
} {9}
57+
58+
do_execsql_test select-count-field-i {
59+
SELECT count(i) FROM counter;
60+
} {9}
61+
62+
do_execsql_test select-count-field-r {
63+
SELECT count(r) FROM counter;
64+
} {9}
65+
66+
do_execsql_test select-count-field-b {
67+
SELECT count(b) FROM counter;
68+
} {9}
69+
70+
do_execsql_test select-count-field-t-distinct {
71+
SELECT count(distinct t) FROM counter;
72+
} {3}
73+
74+
do_execsql_test select-count-field-i-distinct {
75+
SELECT count(distinct i) FROM counter;
76+
} {3}
77+
78+
do_execsql_test select-count-field-r-distinct {
79+
SELECT count(distinct r) FROM counter;
80+
} {3}
81+
82+
do_execsql_test select-count-field-b-distinct {
83+
SELECT count(distinct b) FROM counter;
84+
} {3}
85+
5086
do_execsql_test select-max {
5187
SELECT max(age) FROM users;
5288
} {100}

testing/cmdlineshell.test

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ CREATE TABLE products (
2222
name TEXT,
2323
price REAL
2424
);
25-
CREATE INDEX age_idx on users (age);"}
25+
CREATE INDEX age_idx on users (age);
26+
CREATE TABLE counter (
27+
id INTEGER PRIMARY KEY,
28+
t TEXT,
29+
r REAL,
30+
i INTEGER,
31+
b BLOB
32+
);"}
2633

2734
# FIXME sqlite does something different with .schema than what we are doing
2835
#do_execsql_test_on_specific_db testing/testing_norowidalias.db schema {
@@ -100,3 +107,13 @@ do_execsql_test_on_specific_db testing/testing.db schema-2 {
100107
# do_execsql_test_on_specific_db testing/testing.db schema-1 {
101108
# .tables
102109
# } {"products users"}
110+
111+
do_execsql_test_on_specific_db testing/testing.db schema-3 {
112+
.schema counter
113+
} {"CREATE TABLE counter (
114+
id INTEGER PRIMARY KEY,
115+
t TEXT,
116+
r REAL,
117+
i INTEGER,
118+
b BLOB
119+
);"}

testing/gen-database.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,30 @@
5757
VALUES (?, ?)
5858
''', (product, price))
5959

60+
cursor.execute('''
61+
CREATE TABLE IF NOT EXISTS counter (
62+
id INTEGER PRIMARY KEY,
63+
t TEXT,
64+
r REAL,
65+
i INTEGER,
66+
b BLOB
67+
)
68+
''')
69+
70+
for _ in range(3):
71+
cursor.execute('''
72+
INSERT INTO counter (t, r, i, b) VALUES ('ONE', 1, 1, 'ONE')
73+
''')
74+
cursor.execute('''
75+
INSERT INTO counter (t, r, i, b) VALUES ('TWO', 2, 2, 'TWO');
76+
''')
77+
cursor.execute('''
78+
INSERT INTO counter (t, r, i, b) VALUES ('THREE', 3, 3, 'THREE');
79+
''')
6080

81+
cursor.execute('''
82+
INSERT INTO counter (t, r, i, b) VALUES (NULL, NULL, NULL, NULL);
83+
''')
6184

6285
conn.commit()
6386
conn.close()

testing/testing.db

4 KB
Binary file not shown.

testing/testing_norowidalias.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)