1 | n/a | import sqlite3 |
---|
2 | n/a | |
---|
3 | n/a | def collate_reverse(string1, string2): |
---|
4 | n/a | if string1 == string2: |
---|
5 | n/a | return 0 |
---|
6 | n/a | elif string1 < string2: |
---|
7 | n/a | return 1 |
---|
8 | n/a | else: |
---|
9 | n/a | return -1 |
---|
10 | n/a | |
---|
11 | n/a | con = sqlite3.connect(":memory:") |
---|
12 | n/a | con.create_collation("reverse", collate_reverse) |
---|
13 | n/a | |
---|
14 | n/a | cur = con.cursor() |
---|
15 | n/a | cur.execute("create table test(x)") |
---|
16 | n/a | cur.executemany("insert into test(x) values (?)", [("a",), ("b",)]) |
---|
17 | n/a | cur.execute("select x from test order by x collate reverse") |
---|
18 | n/a | for row in cur: |
---|
19 | n/a | print(row) |
---|
20 | n/a | con.close() |
---|