Back to index

python3.2  3.2.2
Classes | Public Member Functions | Public Attributes
sqlite3.test.types.DeclTypesTests Class Reference

List of all members.

Classes

class  Foo

Public Member Functions

def setUp
def tearDown
def CheckString
def CheckSmallInt
def CheckLargeInt
def CheckFloat
def CheckBool
def CheckUnicode
def CheckFoo
def CheckUnsupportedSeq
def CheckUnsupportedDict
def CheckBlob
def CheckNumber1
def CheckNumber2

Public Attributes

 con
 cur

Detailed Description

Definition at line 82 of file types.py.


Member Function Documentation

Definition at line 216 of file types.py.

00216 
00217     def CheckBlob(self):
00218         # default
00219         sample = b"Guglhupf"
00220         val = memoryview(sample)
00221         self.cur.execute("insert into test(bin) values (?)", (val,))
00222         self.cur.execute("select bin from test")
00223         row = self.cur.fetchone()
00224         self.assertEqual(row[0], sample)

Here is the call graph for this function:

Definition at line 166 of file types.py.

00166 
00167     def CheckBool(self):
00168         # custom
00169         self.cur.execute("insert into test(b) values (?)", (False,))
00170         self.cur.execute("select b from test")
00171         row = self.cur.fetchone()
00172         self.assertEqual(row[0], False)
00173 
00174         self.cur.execute("delete from test")
00175         self.cur.execute("insert into test(b) values (?)", (True,))
00176         self.cur.execute("select b from test")
00177         row = self.cur.fetchone()
00178         self.assertEqual(row[0], True)

Here is the call graph for this function:

Definition at line 158 of file types.py.

00158 
00159     def CheckFloat(self):
00160         # custom
00161         val = 3.14
00162         self.cur.execute("insert into test(f) values (?)", (val,))
00163         self.cur.execute("select f from test")
00164         row = self.cur.fetchone()
00165         self.assertEqual(row[0], 47.2)

Here is the call graph for this function:

Definition at line 187 of file types.py.

00187 
00188     def CheckFoo(self):
00189         val = DeclTypesTests.Foo("bla")
00190         self.cur.execute("insert into test(foo) values (?)", (val,))
00191         self.cur.execute("select foo from test")
00192         row = self.cur.fetchone()
00193         self.assertEqual(row[0], val)

Here is the call graph for this function:

Definition at line 150 of file types.py.

00150 
00151     def CheckLargeInt(self):
00152         # default
00153         num = 2**40
00154         self.cur.execute("insert into test(i) values (?)", (num,))
00155         self.cur.execute("select i from test")
00156         row = self.cur.fetchone()
00157         self.assertEqual(row[0], num)

Here is the call graph for this function:

Definition at line 225 of file types.py.

00225 
00226     def CheckNumber1(self):
00227         self.cur.execute("insert into test(n1) values (5)")
00228         value = self.cur.execute("select n1 from test").fetchone()[0]
00229         # if the converter is not used, it's an int instead of a float
00230         self.assertEqual(type(value), float)

Here is the call graph for this function:

Checks wether converter names are cut off at '(' characters

Definition at line 231 of file types.py.

00231 
00232     def CheckNumber2(self):
00233         """Checks wether converter names are cut off at '(' characters"""
00234         self.cur.execute("insert into test(n2) values (5)")
00235         value = self.cur.execute("select n2 from test").fetchone()[0]
00236         # if the converter is not used, it's an int instead of a float
00237         self.assertEqual(type(value), float)

Here is the call graph for this function:

Definition at line 143 of file types.py.

00143 
00144     def CheckSmallInt(self):
00145         # default
00146         self.cur.execute("insert into test(i) values (?)", (42,))
00147         self.cur.execute("select i from test")
00148         row = self.cur.fetchone()
00149         self.assertEqual(row[0], 42)

Here is the call graph for this function:

Definition at line 136 of file types.py.

00136 
00137     def CheckString(self):
00138         # default
00139         self.cur.execute("insert into test(s) values (?)", ("foo",))
00140         self.cur.execute('select s as "s [WRONG]" from test')
00141         row = self.cur.fetchone()
00142         self.assertEqual(row[0], "foo")

Here is the call graph for this function:

Definition at line 179 of file types.py.

00179 
00180     def CheckUnicode(self):
00181         # default
00182         val = "\xd6sterreich"
00183         self.cur.execute("insert into test(u) values (?)", (val,))
00184         self.cur.execute("select u from test")
00185         row = self.cur.fetchone()
00186         self.assertEqual(row[0], val)

Here is the call graph for this function:

Definition at line 205 of file types.py.

00205 
00206     def CheckUnsupportedDict(self):
00207         class Bar: pass
00208         val = Bar()
00209         try:
00210             self.cur.execute("insert into test(f) values (:val)", {"val": val})
00211             self.fail("should have raised an InterfaceError")
00212         except sqlite.InterfaceError:
00213             pass
00214         except:
00215             self.fail("should have raised an InterfaceError")

Here is the call graph for this function:

Definition at line 194 of file types.py.

00194 
00195     def CheckUnsupportedSeq(self):
00196         class Bar: pass
00197         val = Bar()
00198         try:
00199             self.cur.execute("insert into test(f) values (?)", (val,))
00200             self.fail("should have raised an InterfaceError")
00201         except sqlite.InterfaceError:
00202             pass
00203         except:
00204             self.fail("should have raised an InterfaceError")

Here is the call graph for this function:

Definition at line 114 of file types.py.

00114 
00115     def setUp(self):
00116         self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
00117         self.cur = self.con.cursor()
00118         self.cur.execute("create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))")
00119 
00120         # override float, make them always return the same number
00121         sqlite.converters["FLOAT"] = lambda x: 47.2
00122 
00123         # and implement two custom ones
00124         sqlite.converters["BOOL"] = lambda x: bool(int(x))
00125         sqlite.converters["FOO"] = DeclTypesTests.Foo
00126         sqlite.converters["WRONG"] = lambda x: "WRONG"
00127         sqlite.converters["NUMBER"] = float

Here is the caller graph for this function:

Definition at line 128 of file types.py.

00128 
00129     def tearDown(self):
00130         del sqlite.converters["FLOAT"]
00131         del sqlite.converters["BOOL"]
00132         del sqlite.converters["FOO"]
00133         del sqlite.converters["NUMBER"]
00134         self.cur.close()
00135         self.con.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 115 of file types.py.

Definition at line 116 of file types.py.


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