Back to index

python3.2  3.2.2
Public Member Functions
sqlite3.test.hooks.CollationTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def CheckCreateCollationNotCallable
def CheckCreateCollationNotAscii
def CheckCollationIsUsed
def CheckCollationRegisterTwice
def CheckDeregisterCollation

Detailed Description

Definition at line 27 of file hooks.py.


Member Function Documentation

Definition at line 50 of file hooks.py.

00050 
00051     def CheckCollationIsUsed(self):
00052         if sqlite.version_info < (3, 2, 1):  # old SQLite versions crash on this test
00053             return
00054         def mycoll(x, y):
00055             # reverse order
00056             return -((x > y) - (x < y))
00057 
00058         con = sqlite.connect(":memory:")
00059         con.create_collation("mycoll", mycoll)
00060         sql = """
00061             select x from (
00062             select 'a' as x
00063             union
00064             select 'b' as x
00065             union
00066             select 'c' as x
00067             ) order by x collate mycoll
00068             """
00069         result = con.execute(sql).fetchall()
00070         if result[0][0] != "c" or result[1][0] != "b" or result[2][0] != "a":
00071             self.fail("the expected order was not returned")
00072 
00073         con.create_collation("mycoll", None)
00074         try:
00075             result = con.execute(sql).fetchall()
00076             self.fail("should have raised an OperationalError")
00077         except sqlite.OperationalError as e:
00078             self.assertEqual(e.args[0].lower(), "no such collation sequence: mycoll")

Here is the call graph for this function:

Register two different collation functions under the same name.
Verify that the last one is actually used.

Definition at line 79 of file hooks.py.

00079 
00080     def CheckCollationRegisterTwice(self):
00081         """
00082         Register two different collation functions under the same name.
00083         Verify that the last one is actually used.
00084         """
00085         con = sqlite.connect(":memory:")
00086         con.create_collation("mycoll", lambda x, y: (x > y) - (x < y))
00087         con.create_collation("mycoll", lambda x, y: -((x > y) - (x < y)))
00088         result = con.execute("""
00089             select x from (select 'a' as x union select 'b' as x) order by x collate mycoll
00090             """).fetchall()
00091         if result[0][0] != 'b' or result[1][0] != 'a':
00092             self.fail("wrong collation function is used")

Here is the call graph for this function:

Definition at line 42 of file hooks.py.

00042 
00043     def CheckCreateCollationNotAscii(self):
00044         con = sqlite.connect(":memory:")
00045         try:
00046             con.create_collation("collä", lambda x, y: (x > y) - (x < y))
00047             self.fail("should have raised a ProgrammingError")
00048         except sqlite.ProgrammingError as e:
00049             pass

Here is the call graph for this function:

Definition at line 34 of file hooks.py.

00034 
00035     def CheckCreateCollationNotCallable(self):
00036         con = sqlite.connect(":memory:")
00037         try:
00038             con.create_collation("X", 42)
00039             self.fail("should have raised a TypeError")
00040         except TypeError as e:
00041             self.assertEqual(e.args[0], "parameter must be callable")

Here is the call graph for this function:

Register a collation, then deregister it. Make sure an error is raised if we try
to use it.

Definition at line 93 of file hooks.py.

00093 
00094     def CheckDeregisterCollation(self):
00095         """
00096         Register a collation, then deregister it. Make sure an error is raised if we try
00097         to use it.
00098         """
00099         con = sqlite.connect(":memory:")
00100         con.create_collation("mycoll", lambda x, y: (x > y) - (x < y))
00101         con.create_collation("mycoll", None)
00102         try:
00103             con.execute("select 'a' as x union select 'b' as x order by x collate mycoll")
00104             self.fail("should have raised an OperationalError")
00105         except sqlite.OperationalError as e:
00106             if not e.args[0].startswith("no such collation sequence"):
00107                 self.fail("wrong OperationalError raised")

Here is the call graph for this function:

Definition at line 28 of file hooks.py.

00028 
00029     def setUp(self):
00030         pass

Here is the caller graph for this function:

Definition at line 31 of file hooks.py.

00031 
00032     def tearDown(self):
00033         pass

Here is the caller graph for this function:


The documentation for this class was generated from the following file: