Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | import sqlite3 |
| 2 | |
| 3 | def collate_reverse(string1, string2): |
Mark Dickinson | c48d834 | 2009-02-01 14:18:10 +0000 | [diff] [blame] | 4 | if string1 == string2: |
| 5 | return 0 |
| 6 | elif string1 < string2: |
| 7 | return 1 |
| 8 | else: |
| 9 | return -1 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | |
| 11 | con = sqlite3.connect(":memory:") |
| 12 | con.create_collation("reverse", collate_reverse) |
| 13 | |
| 14 | cur = con.cursor() |
| 15 | cur.execute("create table test(x)") |
| 16 | cur.executemany("insert into test(x) values (?)", [("a",), ("b",)]) |
| 17 | cur.execute("select x from test order by x collate reverse") |
| 18 | for row in cur: |
| 19 | print(row) |
| 20 | con.close() |