blob: 3504a350a04ecb82c093751007514d22b619e565 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001import sqlite3
2
3def collate_reverse(string1, string2):
Mark Dickinsonc48d8342009-02-01 14:18:10 +00004 if string1 == string2:
5 return 0
6 elif string1 < string2:
7 return 1
8 else:
9 return -1
Georg Brandl116aa622007-08-15 14:28:22 +000010
11con = sqlite3.connect(":memory:")
12con.create_collation("reverse", collate_reverse)
13
14cur = con.cursor()
15cur.execute("create table test(x)")
16cur.executemany("insert into test(x) values (?)", [("a",), ("b",)])
17cur.execute("select x from test order by x collate reverse")
18for row in cur:
19 print(row)
20con.close()