Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
sqlite3.test.dbapi.CursorTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def CheckExecuteNoArgs
def CheckExecuteIllegalSql
def CheckExecuteTooMuchSql
def CheckExecuteTooMuchSql2
def CheckExecuteTooMuchSql3
def CheckExecuteWrongSqlArg
def CheckExecuteArgInt
def CheckExecuteArgFloat
def CheckExecuteArgString
def CheckExecuteWrongNoOfArgs1
def CheckExecuteWrongNoOfArgs2
def CheckExecuteWrongNoOfArgs3
def CheckExecuteParamList
def CheckExecuteParamSequence
def CheckExecuteDictMapping
def CheckExecuteDictMapping_Mapping
def CheckExecuteDictMappingTooLittleArgs
def CheckExecuteDictMappingNoArgs
def CheckExecuteDictMappingUnnamed
def CheckClose
def CheckRowcountExecute
def CheckRowcountSelect
def CheckRowcountExecutemany
def CheckTotalChanges
def CheckExecuteManySequence
def CheckExecuteManyIterator
def CheckExecuteManyGenerator
def CheckExecuteManyWrongSqlArg
def CheckExecuteManySelect
def CheckExecuteManyNotIterable
def CheckFetchIter
def CheckFetchone
def CheckFetchoneNoStatement
def CheckArraySize
def CheckFetchmany
def CheckFetchmanyKwArg
def CheckFetchall
def CheckSetinputsizes
def CheckSetoutputsize
def CheckSetoutputsizeNoColumn
def CheckCursorConnection
def CheckWrongCursorCallable
def CheckCursorWrongClass

Public Attributes

 cx
 cu
 value

Detailed Description

Definition at line 166 of file dbapi.py.


Member Function Documentation

Definition at line 421 of file dbapi.py.

00421 
00422     def CheckArraySize(self):
00423         # must default ot 1
00424         self.assertEqual(self.cu.arraysize, 1)
00425 
00426         # now set to 2
00427         self.cu.arraysize = 2
00428 
00429         # now make the query return 3 rows
00430         self.cu.execute("delete from test")
00431         self.cu.execute("insert into test(name) values ('A')")
00432         self.cu.execute("insert into test(name) values ('B')")
00433         self.cu.execute("insert into test(name) values ('C')")
00434         self.cu.execute("select name from test")
00435         res = self.cu.fetchmany()
00436 
00437         self.assertEqual(len(res), 2)

Here is the call graph for this function:

Definition at line 311 of file dbapi.py.

00311 
00312     def CheckClose(self):
00313         self.cu.close()

Definition at line 467 of file dbapi.py.

00467 
00468     def CheckCursorConnection(self):
00469         # Optional DB-API extension.
00470         self.assertEqual(self.cu.connection, self.cx)

Here is the call graph for this function:

Definition at line 480 of file dbapi.py.

00480 
00481     def CheckCursorWrongClass(self):
00482         class Foo: pass
00483         foo = Foo()
00484         try:
00485             cur = sqlite.Cursor(foo)
00486             self.fail("should have raised a ValueError")
00487         except TypeError:
00488             pass
00489 
@unittest.skipUnless(threading, 'This test requires threading.')

Here is the call graph for this function:

Definition at line 222 of file dbapi.py.

00222 
00223     def CheckExecuteArgFloat(self):
00224         self.cu.execute("insert into test(income) values (?)", (2500.32,))

Definition at line 219 of file dbapi.py.

00219 
00220     def CheckExecuteArgInt(self):
00221         self.cu.execute("insert into test(id) values (?)", (42,))

Definition at line 225 of file dbapi.py.

00225 
00226     def CheckExecuteArgString(self):
00227         self.cu.execute("insert into test(name) values (?)", ("Hugo",))

Definition at line 271 of file dbapi.py.

00271 
00272     def CheckExecuteDictMapping(self):
00273         self.cu.execute("insert into test(name) values ('foo')")
00274         self.cu.execute("select name from test where name=:name", {"name": "foo"})
00275         row = self.cu.fetchone()
00276         self.assertEqual(row[0], "foo")

Here is the call graph for this function:

Definition at line 277 of file dbapi.py.

00277 
00278     def CheckExecuteDictMapping_Mapping(self):
00279         class D(dict):
00280             def __missing__(self, key):
00281                 return "foo"
00282 
00283         self.cu.execute("insert into test(name) values ('foo')")
00284         self.cu.execute("select name from test where name=:name", D())
00285         row = self.cu.fetchone()
00286         self.assertEqual(row[0], "foo")

Here is the call graph for this function:

Definition at line 295 of file dbapi.py.

00295 
00296     def CheckExecuteDictMappingNoArgs(self):
00297         self.cu.execute("insert into test(name) values ('foo')")
00298         try:
00299             self.cu.execute("select name from test where name=:name")
00300             self.fail("should have raised ProgrammingError")
00301         except sqlite.ProgrammingError:
00302             pass

Here is the call graph for this function:

Definition at line 287 of file dbapi.py.

00287 
00288     def CheckExecuteDictMappingTooLittleArgs(self):
00289         self.cu.execute("insert into test(name) values ('foo')")
00290         try:
00291             self.cu.execute("select name from test where name=:name and id=:id", {"name": "foo"})
00292             self.fail("should have raised ProgrammingError")
00293         except sqlite.ProgrammingError:
00294             pass

Here is the call graph for this function:

Definition at line 303 of file dbapi.py.

00303 
00304     def CheckExecuteDictMappingUnnamed(self):
00305         self.cu.execute("insert into test(name) values ('foo')")
00306         try:
00307             self.cu.execute("select name from test where name=?", {"name": "foo"})
00308             self.fail("should have raised ProgrammingError")
00309         except sqlite.ProgrammingError:
00310             pass

Here is the call graph for this function:

Definition at line 180 of file dbapi.py.

00180 
00181     def CheckExecuteIllegalSql(self):
00182         try:
00183             self.cu.execute("select asdf")
00184             self.fail("should have raised an OperationalError")
00185         except sqlite.OperationalError:
00186             return
00187         except:
00188             self.fail("raised wrong exception")

Here is the call graph for this function:

Definition at line 362 of file dbapi.py.

00362 
00363     def CheckExecuteManyGenerator(self):
00364         def mygen():
00365             for i in range(5):
00366                 yield (i,)
00367 
00368         self.cu.executemany("insert into test(income) values (?)", mygen())

Definition at line 348 of file dbapi.py.

00348 
00349     def CheckExecuteManyIterator(self):
00350         class MyIter:
00351             def __init__(self):
00352                 self.value = 5
00353 
00354             def __next__(self):
00355                 if self.value == 10:
00356                     raise StopIteration
00357                 else:
00358                     self.value += 1
00359                     return (self.value,)
00360 
00361         self.cu.executemany("insert into test(income) values (?)", MyIter())

Here is the call graph for this function:

Definition at line 387 of file dbapi.py.

00387 
00388     def CheckExecuteManyNotIterable(self):
00389         try:
00390             self.cu.executemany("insert into test(income) values (?)", 42)
00391             self.fail("should have raised a TypeError")
00392         except TypeError:
00393             return
00394         except Exception as e:
00395             print("raised", e.__class__)
00396             self.fail("raised wrong exception.")

Here is the call graph for this function:

Definition at line 378 of file dbapi.py.

00378 
00379     def CheckExecuteManySelect(self):
00380         try:
00381             self.cu.executemany("select ?", [(3,)])
00382             self.fail("should have raised a ProgrammingError")
00383         except sqlite.ProgrammingError:
00384             return
00385         except:
00386             self.fail("raised wrong exception.")

Here is the call graph for this function:

Definition at line 345 of file dbapi.py.

00345 
00346     def CheckExecuteManySequence(self):
00347         self.cu.executemany("insert into test(income) values (?)", [(x,) for x in range(100, 110)])

Definition at line 369 of file dbapi.py.

00369 
00370     def CheckExecuteManyWrongSqlArg(self):
00371         try:
00372             self.cu.executemany(42, [(3,)])
00373             self.fail("should have raised a ValueError")
00374         except ValueError:
00375             return
00376         except:
00377             self.fail("raised wrong exception.")

Here is the call graph for this function:

Definition at line 177 of file dbapi.py.

00177 
00178     def CheckExecuteNoArgs(self):
00179         self.cu.execute("delete from test")

Definition at line 252 of file dbapi.py.

00252 
00253     def CheckExecuteParamList(self):
00254         self.cu.execute("insert into test(name) values ('foo')")
00255         self.cu.execute("select name from test where name=?", ["foo"])
00256         row = self.cu.fetchone()
00257         self.assertEqual(row[0], "foo")

Here is the call graph for this function:

Definition at line 258 of file dbapi.py.

00258 
00259     def CheckExecuteParamSequence(self):
00260         class L(object):
00261             def __len__(self):
00262                 return 1
00263             def __getitem__(self, x):
00264                 assert x == 0
00265                 return "foo"
00266 
00267         self.cu.execute("insert into test(name) values ('foo')")
00268         self.cu.execute("select name from test where name=?", L())
00269         row = self.cu.fetchone()
00270         self.assertEqual(row[0], "foo")

Here is the call graph for this function:

Definition at line 189 of file dbapi.py.

00189 
00190     def CheckExecuteTooMuchSql(self):
00191         try:
00192             self.cu.execute("select 5+4; select 4+5")
00193             self.fail("should have raised a Warning")
00194         except sqlite.Warning:
00195             return
00196         except:
00197             self.fail("raised wrong exception")

Here is the call graph for this function:

Definition at line 198 of file dbapi.py.

00198 
00199     def CheckExecuteTooMuchSql2(self):
00200         self.cu.execute("select 5+4; -- foo bar")

Definition at line 201 of file dbapi.py.

00201 
00202     def CheckExecuteTooMuchSql3(self):
00203         self.cu.execute("""
00204             select 5+4;
00205 
00206             /*
00207             foo
00208             */
00209             """)

Definition at line 228 of file dbapi.py.

00228 
00229     def CheckExecuteWrongNoOfArgs1(self):
00230         # too many parameters
00231         try:
00232             self.cu.execute("insert into test(id) values (?)", (17, "Egon"))
00233             self.fail("should have raised ProgrammingError")
00234         except sqlite.ProgrammingError:
00235             pass

Here is the call graph for this function:

Definition at line 236 of file dbapi.py.

00236 
00237     def CheckExecuteWrongNoOfArgs2(self):
00238         # too little parameters
00239         try:
00240             self.cu.execute("insert into test(id) values (?)")
00241             self.fail("should have raised ProgrammingError")
00242         except sqlite.ProgrammingError:
00243             pass

Here is the call graph for this function:

Definition at line 244 of file dbapi.py.

00244 
00245     def CheckExecuteWrongNoOfArgs3(self):
00246         # no parameters, parameters are needed
00247         try:
00248             self.cu.execute("insert into test(id) values (?)")
00249             self.fail("should have raised ProgrammingError")
00250         except sqlite.ProgrammingError:
00251             pass

Here is the call graph for this function:

Definition at line 210 of file dbapi.py.

00210 
00211     def CheckExecuteWrongSqlArg(self):
00212         try:
00213             self.cu.execute(42)
00214             self.fail("should have raised a ValueError")
00215         except ValueError:
00216             return
00217         except:
00218             self.fail("raised wrong exception.")

Here is the call graph for this function:

Definition at line 451 of file dbapi.py.

00451 
00452     def CheckFetchall(self):
00453         self.cu.execute("select name from test")
00454         res = self.cu.fetchall()
00455         self.assertEqual(len(res), 1)
00456         res = self.cu.fetchall()
00457         self.assertEqual(res, [])

Here is the call graph for this function:

Definition at line 397 of file dbapi.py.

00397 
00398     def CheckFetchIter(self):
00399         # Optional DB-API extension.
00400         self.cu.execute("delete from test")
00401         self.cu.execute("insert into test(id) values (?)", (5,))
00402         self.cu.execute("insert into test(id) values (?)", (6,))
00403         self.cu.execute("select id from test order by id")
00404         lst = []
00405         for row in self.cu:
00406             lst.append(row[0])
00407         self.assertEqual(lst[0], 5)
00408         self.assertEqual(lst[1], 6)

Here is the call graph for this function:

Definition at line 438 of file dbapi.py.

00438 
00439     def CheckFetchmany(self):
00440         self.cu.execute("select name from test")
00441         res = self.cu.fetchmany(100)
00442         self.assertEqual(len(res), 1)
00443         res = self.cu.fetchmany(100)
00444         self.assertEqual(res, [])

Here is the call graph for this function:

Checks if fetchmany works with keyword arguments

Definition at line 445 of file dbapi.py.

00445 
00446     def CheckFetchmanyKwArg(self):
00447         """Checks if fetchmany works with keyword arguments"""
00448         self.cu.execute("select name from test")
00449         res = self.cu.fetchmany(size=100)
00450         self.assertEqual(len(res), 1)

Here is the call graph for this function:

Definition at line 409 of file dbapi.py.

00409 
00410     def CheckFetchone(self):
00411         self.cu.execute("select name from test")
00412         row = self.cu.fetchone()
00413         self.assertEqual(row[0], "foo")
00414         row = self.cu.fetchone()
00415         self.assertEqual(row, None)

Here is the call graph for this function:

Definition at line 416 of file dbapi.py.

00416 
00417     def CheckFetchoneNoStatement(self):
00418         cur = self.cx.cursor()
00419         row = cur.fetchone()
00420         self.assertEqual(row, None)

Here is the call graph for this function:

Definition at line 314 of file dbapi.py.

00314 
00315     def CheckRowcountExecute(self):
00316         self.cu.execute("delete from test")
00317         self.cu.execute("insert into test(name) values ('foo')")
00318         self.cu.execute("insert into test(name) values ('foo')")
00319         self.cu.execute("update test set name='bar'")
00320         self.assertEqual(self.cu.rowcount, 2)

Here is the call graph for this function:

Definition at line 330 of file dbapi.py.

00330 
00331     def CheckRowcountExecutemany(self):
00332         self.cu.execute("delete from test")
00333         self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
00334         self.assertEqual(self.cu.rowcount, 3)

Here is the call graph for this function:

pysqlite does not know the rowcount of SELECT statements, because we
don't fetch all rows after executing the select statement. The rowcount
has thus to be -1.

Definition at line 321 of file dbapi.py.

00321 
00322     def CheckRowcountSelect(self):
00323         """
00324         pysqlite does not know the rowcount of SELECT statements, because we
00325         don't fetch all rows after executing the select statement. The rowcount
00326         has thus to be -1.
00327         """
00328         self.cu.execute("select 5 union select 6")
00329         self.assertEqual(self.cu.rowcount, -1)

Here is the call graph for this function:

Definition at line 458 of file dbapi.py.

00458 
00459     def CheckSetinputsizes(self):
00460         self.cu.setinputsizes([3, 4, 5])

Definition at line 461 of file dbapi.py.

00461 
00462     def CheckSetoutputsize(self):
00463         self.cu.setoutputsize(5, 0)

Definition at line 464 of file dbapi.py.

00464 
00465     def CheckSetoutputsizeNoColumn(self):
00466         self.cu.setoutputsize(42)

Definition at line 335 of file dbapi.py.

00335 
00336     def CheckTotalChanges(self):
00337         self.cu.execute("insert into test(name) values ('foo')")
00338         self.cu.execute("insert into test(name) values ('foo')")
00339         if self.cx.total_changes < 2:
00340             self.fail("total changes reported wrong value")

Here is the call graph for this function:

Definition at line 471 of file dbapi.py.

00471 
00472     def CheckWrongCursorCallable(self):
00473         try:
00474             def f(): pass
00475             cur = self.cx.cursor(f)
00476             self.fail("should have raised a TypeError")
00477         except TypeError:
00478             return
00479         self.fail("should have raised a ValueError")

Here is the call graph for this function:

Definition at line 167 of file dbapi.py.

00167 
00168     def setUp(self):
00169         self.cx = sqlite.connect(":memory:")
00170         self.cu = self.cx.cursor()
00171         self.cu.execute("create table test(id integer primary key, name text, income number)")
00172         self.cu.execute("insert into test(name) values (?)", ("foo",))

Here is the caller graph for this function:

Definition at line 173 of file dbapi.py.

00173 
00174     def tearDown(self):
00175         self.cu.close()
00176         self.cx.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 169 of file dbapi.py.

Definition at line 168 of file dbapi.py.

Definition at line 351 of file dbapi.py.


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