@@ -56,24 +56,35 @@ INSERT INTO foo values ("a5", "bb", "cc");
5656 )
5757}
5858
59- func TestPKSelect (t * testing.T ) {
59+ func TestSelectIndexEqDesc (t * testing.T ) {
6060 Compare (
6161 t ,
6262 `
63- CREATE TABLE foo (a NOT NULL PRIMARY KEY, b, c);
64- INSERT INTO foo values ("aa", "bb1", "1");
65- INSERT INTO foo values ("a2", "bb2", "2");
66- INSERT INTO foo values ("a3", "bb3", "3");
67- INSERT INTO foo values ("a4", "bb4", "4");
68- INSERT INTO foo values ("a5", "bb5", "5");
63+ CREATE TABLE foo (a, b);
64+ INSERT INTO foo values ("a1", 1);
65+ INSERT INTO foo values ("a1", 2);
66+ INSERT INTO foo values ("a1", 3);
67+ INSERT INTO foo values ("a2", 1);
68+ INSERT INTO foo values ("a2", 2);
69+ INSERT INTO foo values ("a2", 3);
70+ INSERT INTO foo values ("a3", 1);
71+ INSERT INTO foo values ("a3", 2);
72+ INSERT INTO foo values ("a3", 3);
73+ INSERT INTO foo values ("a4", 1);
74+ INSERT INTO foo values ("a4", 2);
75+ INSERT INTO foo values ("a4", 3);
76+ INSERT INTO foo values ("a5", 1);
77+ INSERT INTO foo values ("a5", 2);
78+ INSERT INTO foo values ("a5", 3);
79+ CREATE INDEX foo_desc ON foo (a DESC, b DESC);
6980` ,
70- `SELECT b, c FROM foo WHERE a='a3'` ,
81+ `SELECT a, b FROM foo WHERE a='a3' ORDER BY a DESC, b DESC ` ,
7182 func (t * testing.T , db * sqlittle.DB ) [][]string {
7283 var rows [][]string
7384 cb := func (r sqlittle.Row ) {
7485 rows = append (rows , r .ScanStrings ())
7586 }
76- err := db .PKSelect ("foo" , sqlittle.Key {"a3" }, cb , "b " , "c " )
87+ err := db .IndexedSelectEq ("foo" , "foo_desc" , sqlittle.Key {"a3" }, cb , "a " , "b " )
7788 if err != nil {
7889 t .Fatal (err )
7990 }
@@ -82,11 +93,39 @@ INSERT INTO foo values ("a5", "bb5", "5");
8293 )
8394}
8495
85- func TestSelectIndexEqDesc (t * testing.T ) {
96+ func TestIndexedSelectDescNonrowid (t * testing.T ) {
8697 Compare (
8798 t ,
8899 `
89- CREATE TABLE foo (a, b);
100+ CREATE TABLE foo (a, b, primary key(a, b DESC)) WITHOUT ROWID;
101+ INSERT INTO foo values ("a1", 1);
102+ INSERT INTO foo values ("a1", 2);
103+ INSERT INTO foo values ("a1", 3);
104+ INSERT INTO foo values ("a2", 1);
105+ INSERT INTO foo values ("a2", 2);
106+ INSERT INTO foo values ("a2", 3);
107+ CREATE INDEX foo_desc ON foo (a, b DESC);
108+ ` ,
109+ `SELECT a, b FROM foo ORDER by a, b DESC` ,
110+ func (t * testing.T , db * sqlittle.DB ) [][]string {
111+ var rows [][]string
112+ cb := func (r sqlittle.Row ) {
113+ rows = append (rows , r .ScanStrings ())
114+ }
115+ err := db .IndexedSelect ("foo" , "foo_desc" , cb , "a" , "b" )
116+ if err != nil {
117+ t .Fatal (err )
118+ }
119+ return rows
120+ },
121+ )
122+ }
123+
124+ func TestIndexedSelectEqDescNonrowid (t * testing.T ) {
125+ Compare (
126+ t ,
127+ `
128+ CREATE TABLE foo (a, b, primary key(a, b DESC)) WITHOUT ROWID;
90129INSERT INTO foo values ("a1", 1);
91130INSERT INTO foo values ("a1", 2);
92131INSERT INTO foo values ("a1", 3);
@@ -102,15 +141,15 @@ INSERT INTO foo values ("a4", 3);
102141INSERT INTO foo values ("a5", 1);
103142INSERT INTO foo values ("a5", 2);
104143INSERT INTO foo values ("a5", 3);
105- CREATE INDEX foo_desc ON foo (a DESC , b DESC);
144+ CREATE INDEX foo_desc ON foo (a, b DESC);
106145` ,
107- `SELECT a, b FROM foo WHERE a='a3' ORDER BY a DESC, b DESC ` ,
146+ `SELECT a, b FROM foo WHERE a='a3' AND b=2 ` ,
108147 func (t * testing.T , db * sqlittle.DB ) [][]string {
109148 var rows [][]string
110149 cb := func (r sqlittle.Row ) {
111150 rows = append (rows , r .ScanStrings ())
112151 }
113- err := db .IndexedSelectEq ("foo" , "foo_desc" , sqlittle.Key {"a3" }, cb , "a" , "b" )
152+ err := db .IndexedSelectEq ("foo" , "foo_desc" , sqlittle.Key {"a3" , 2 }, cb , "a" , "b" )
114153 if err != nil {
115154 t .Fatal (err )
116155 }
0 commit comments