44
55class TestLobVar (BaseTestCase ):
66
7- def __PerformTest (self , type , inputType ):
7+ def __GetTempLobs (self , sid ):
8+ cursor = self .connection .cursor ()
9+ cursor .execute ("""
10+ select abstract_lobs
11+ from v$temporary_lobs
12+ where sid = :sid""" , sid = sid )
13+ row = cursor .fetchone ()
14+ if row is None :
15+ return 0
16+ return int (row [0 ])
17+
18+ def __PerformTest (self , lobType , inputType ):
819 longString = ""
9- directType = getattr (cx_Oracle , type )
10- self .cursor .execute ("truncate table Test%ss" % type )
20+ directType = getattr (cx_Oracle , lobType )
21+ self .cursor .execute ("truncate table Test%ss" % lobType )
1122 for i in range (0 , 11 ):
1223 if i > 0 :
1324 char = chr (ord ('A' ) + i - 1 )
1425 longString += char * 25000
1526 elif inputType != directType :
1627 continue
1728 self .cursor .setinputsizes (longString = inputType )
18- if type == "BLOB" and sys .version_info [0 ] >= 3 :
29+ if lobType == "BLOB" and sys .version_info [0 ] >= 3 :
1930 bindValue = longString .encode ("ascii" )
2031 else :
2132 bindValue = longString
@@ -26,70 +37,73 @@ def __PerformTest(self, type, inputType):
2637 ) values (
2738 :integerValue,
2839 :longString
29- )""" % (type , type ),
40+ )""" % (lobType , lobType ),
3041 integerValue = i ,
3142 longString = bindValue )
3243 self .connection .commit ()
3344 self .cursor .execute ("""
3445 select *
3546 from Test%ss
36- order by IntCol""" % type )
47+ order by IntCol""" % lobType )
48+ self .__ValidateQuery (self .cursor , lobType )
49+
50+ def __TestTrim (self , lobType ):
51+ self .cursor .execute ("truncate table Test%ss" % lobType )
52+ self .cursor .setinputsizes (longString = getattr (cx_Oracle , lobType ))
53+ longString = "X" * 75000
54+ if lobType == "BLOB" and sys .version_info [0 ] >= 3 :
55+ longString = longString .encode ("ascii" )
56+ self .cursor .execute ("""
57+ insert into Test%ss (
58+ IntCol,
59+ %sCol
60+ ) values (
61+ :integerValue,
62+ :longString
63+ )""" % (lobType , lobType ),
64+ integerValue = 1 ,
65+ longString = longString )
66+ self .cursor .execute ("""
67+ select %sCol
68+ from Test%ss
69+ where IntCol = 1""" % (lobType , lobType ))
70+ lob , = self .cursor .fetchone ()
71+ self .assertEqual (lob .size (), 75000 )
72+ lob .trim (25000 )
73+ self .assertEqual (lob .size (), 25000 )
74+ lob .trim ()
75+ self .assertEqual (lob .size (), 0 )
76+
77+ def __ValidateQuery (self , rows , lobType ):
3778 longString = ""
3879 for row in self .cursor :
3980 integerValue , lob = row
4081 if integerValue == 0 :
4182 self .assertEqual (lob .size (), 0 )
4283 expectedValue = ""
43- if type == "BLOB" and sys .version_info [0 ] >= 3 :
84+ if lobType == "BLOB" and sys .version_info [0 ] >= 3 :
4485 expectedValue = expectedValue .encode ("ascii" )
4586 self .assertEqual (lob .read (), expectedValue )
4687 else :
4788 char = chr (ord ('A' ) + integerValue - 1 )
4889 prevChar = chr (ord ('A' ) + integerValue - 2 )
4990 longString += char * 25000
50- if type == "BLOB" and sys .version_info [0 ] >= 3 :
91+ if lobType == "BLOB" and sys .version_info [0 ] >= 3 :
5192 actualValue = longString .encode ("ascii" )
5293 char = char .encode ("ascii" )
5394 prevChar = prevChar .encode ("ascii" )
5495 else :
5596 actualValue = longString
5697 self .assertEqual (lob .size (), len (actualValue ))
5798 self .assertEqual (lob .read (), actualValue )
58- if type == "CLOB" :
99+ if lobType == "CLOB" :
59100 self .assertEqual (str (lob ), actualValue )
60101 self .assertEqual (lob .read (len (actualValue )), char )
61102 if integerValue > 1 :
62103 offset = (integerValue - 1 ) * 25000 - 4
63104 string = prevChar * 5 + char * 5
64105 self .assertEqual (lob .read (offset , 10 ), string )
65106
66- def __TestTrim (self , type ):
67- self .cursor .execute ("truncate table Test%ss" % type )
68- self .cursor .setinputsizes (longString = getattr (cx_Oracle , type ))
69- longString = "X" * 75000
70- if type == "BLOB" and sys .version_info [0 ] >= 3 :
71- longString = longString .encode ("ascii" )
72- self .cursor .execute ("""
73- insert into Test%ss (
74- IntCol,
75- %sCol
76- ) values (
77- :integerValue,
78- :longString
79- )""" % (type , type ),
80- integerValue = 1 ,
81- longString = longString )
82- self .cursor .execute ("""
83- select %sCol
84- from Test%ss
85- where IntCol = 1""" % (type , type ))
86- lob , = self .cursor .fetchone ()
87- self .assertEqual (lob .size (), 75000 )
88- lob .trim (25000 )
89- self .assertEqual (lob .size (), 25000 )
90- lob .trim ()
91- self .assertEqual (lob .size (), 0 )
92-
93107 def testBLOBCursorDescription (self ):
94108 "test cursor description is accurate for BLOBs"
95109 self .cursor .execute ("select * from TestBLOBs" )
@@ -131,9 +145,9 @@ def testCLOBTrim(self):
131145 def testMultipleFetch (self ):
132146 "test retrieving data from a CLOB after multiple fetches"
133147 self .cursor .arraysize = 1
134- self .cursor .execute ("select CLOBCol from TestCLOBS" )
148+ self .cursor .execute ("select * from TestCLOBS" )
135149 rows = self .cursor .fetchall ()
136- self .assertRaises ( cx_Oracle . ProgrammingError , rows [ 1 ][ 0 ]. read )
150+ self .__ValidateQuery ( rows , "CLOB" )
137151
138152 def testNCLOBCursorDescription (self ):
139153 "test cursor description is accurate for NCLOBs"
@@ -154,3 +168,23 @@ def testNCLOBTrim(self):
154168 "test trimming a CLOB"
155169 self .__TestTrim ("CLOB" )
156170
171+ def testTemporaryLobs (self ):
172+ cursor = self .connection .cursor ()
173+ cursor .arraysize = self .cursor .arraysize
174+ cursor .execute ("""
175+ select sid
176+ from v$session
177+ where audsid = userenv('sessionid')""" )
178+ sid , = cursor .fetchone ()
179+ tempLobs = self .__GetTempLobs (sid )
180+ self .assertEqual (tempLobs , 0 )
181+ cursor .execute ("""
182+ select extract(xmlcol, '/').getclobval()
183+ from TestXML""" )
184+ for lob , in cursor :
185+ value = lob .read ()
186+ del lob
187+ cursor .close ()
188+ tempLobs = self .__GetTempLobs (sid )
189+ self .assertEqual (tempLobs , 0 )
190+
0 commit comments