@@ -47,7 +47,7 @@ def __get_temp_lobs(self, sid):
4747 def __perform_test (self , lob_type , input_type ):
4848 long_string = ""
4949 db_type = getattr (oracledb , "DB_TYPE_" + lob_type )
50- self .cursor .execute ("truncate table Test%ss" % lob_type )
50+ self .cursor .execute (f "truncate table Test{ lob_type } s" )
5151 for i in range (0 , 11 ):
5252 if i > 0 :
5353 char = chr (ord ('A' ) + i - 1 )
@@ -59,45 +59,76 @@ def __perform_test(self, lob_type, input_type):
5959 bind_value = long_string .encode ()
6060 else :
6161 bind_value = long_string
62- self .cursor .execute ("""
63- insert into Test%ss (
62+ self .cursor .execute (f """
63+ insert into Test{ lob_type } s (
6464 IntCol,
65- %sCol
65+ { lob_type } Col
6666 ) values (
6767 :integer_value,
6868 :long_string
69- )""" % ( lob_type , lob_type ) ,
69+ )""" ,
7070 integer_value = i ,
7171 long_string = bind_value )
7272 self .connection .commit ()
73- self .cursor .execute ("""
74- select *
75- from Test%ss
76- order by IntCol""" % lob_type )
73+ self .cursor .execute (f"""
74+ select
75+ IntCol,
76+ { lob_type } Col
77+ from Test{ lob_type } s
78+ order by IntCol""" )
7779 self .__validate_query (self .cursor , lob_type )
7880
81+ def __test_fetch_lobs_direct (self , lob_type ):
82+ self .cursor .execute (f"truncate table Test{ lob_type } s" )
83+ data = []
84+ long_string = ""
85+ for i in range (1 , 11 ):
86+ if i > 0 :
87+ char = chr (ord ('A' ) + i - 1 )
88+ long_string += char * 25000
89+ if lob_type == "BLOB" :
90+ data .append ((i , long_string .encode ()))
91+ else :
92+ data .append ((i , long_string ))
93+ self .cursor .executemany (f"""
94+ insert into Test{ lob_type } s (
95+ IntCol,
96+ { lob_type } Col
97+ ) values (
98+ :1,
99+ :2
100+ )""" , data )
101+ with test_env .FetchLobsContextManager (False ):
102+ self .cursor .execute (f"""
103+ select
104+ IntCol,
105+ { lob_type } Col
106+ from Test{ lob_type } s
107+ order by IntCol""" )
108+ self .assertEqual (data , self .cursor .fetchall ())
109+
79110 def __test_lob_operations (self , lob_type ):
80- self .cursor .execute ("truncate table Test%ss" % lob_type )
111+ self .cursor .execute (f "truncate table Test{ lob_type } s" )
81112 self .cursor .setinputsizes (long_string = getattr (oracledb , lob_type ))
82113 long_string = "X" * 75000
83114 write_value = "TEST"
84115 if lob_type == "BLOB" :
85116 long_string = long_string .encode ("ascii" )
86117 write_value = write_value .encode ("ascii" )
87- self .cursor .execute ("""
88- insert into Test%ss (
118+ self .cursor .execute (f """
119+ insert into Test{ lob_type } s (
89120 IntCol,
90- %sCol
121+ { lob_type } Col
91122 ) values (
92123 :integer_value,
93124 :long_string
94- )""" % ( lob_type , lob_type ) ,
125+ )""" ,
95126 integer_value = 1 ,
96127 long_string = long_string )
97- self .cursor .execute ("""
98- select %sCol
99- from Test%ss
100- where IntCol = 1""" % ( lob_type , lob_type ) )
128+ self .cursor .execute (f """
129+ select { lob_type } Col
130+ from Test{ lob_type } s
131+ where IntCol = 1""" )
101132 lob , = self .cursor .fetchone ()
102133 self .assertEqual (lob .isopen (), False )
103134 lob .open ()
@@ -132,7 +163,7 @@ def __test_pickle(self, lob_type):
132163 self .assertEqual (unpickled_value , value )
133164
134165 def __test_temporary_lob (self , lob_type ):
135- self .cursor .execute ("truncate table Test%ss" % lob_type )
166+ self .cursor .execute (f "truncate table Test{ lob_type } s" )
136167 value = "A test string value"
137168 if lob_type == "BLOB" :
138169 value = value .encode ("ascii" )
@@ -183,15 +214,21 @@ def __validate_query(self, rows, lob_type):
183214 def test_1900_bind_lob_value (self ):
184215 "1900 - test binding a LOB value directly"
185216 self .cursor .execute ("truncate table TestCLOBs" )
186- self .cursor .execute ("insert into TestCLOBs values (1, 'Short value')" )
217+ self .cursor .execute ("""
218+ insert into TestCLOBs
219+ (IntCol, ClobCol)
220+ values (1, 'Short value')""" )
187221 self .cursor .execute ("select ClobCol from TestCLOBs" )
188222 lob , = self .cursor .fetchone ()
189- self .cursor .execute ("insert into TestCLOBs values (2, :value)" ,
190- value = lob )
223+ self .cursor .execute ("""
224+ insert into TestCLOBs
225+ (IntCol, ClobCol)
226+ values (2, :value)""" ,
227+ value = lob )
191228
192229 def test_1901_blob_cursor_description (self ):
193230 "1901 - test cursor description is accurate for BLOBs"
194- self .cursor .execute ("select * from TestBLOBs" )
231+ self .cursor .execute ("select IntCol, BlobCol from TestBLOBs" )
195232 expected_value = [
196233 ('INTCOL' , oracledb .DB_TYPE_NUMBER , 10 , None , 9 , 0 , 0 ),
197234 ('BLOBCOL' , oracledb .DB_TYPE_BLOB , None , None , None , None , 0 )
@@ -212,7 +249,7 @@ def test_1904_blob_operations(self):
212249
213250 def test_1905_clob_cursor_description (self ):
214251 "1905 - test cursor description is accurate for CLOBs"
215- self .cursor .execute ("select * from TestCLOBs" )
252+ self .cursor .execute ("select IntCol, ClobCol from TestCLOBs" )
216253 expected_value = [
217254 ('INTCOL' , oracledb .DB_TYPE_NUMBER , 10 , None , 9 , 0 , False ),
218255 ('CLOBCOL' , oracledb .DB_TYPE_CLOB , None , None , None , None , False )
@@ -252,7 +289,7 @@ def test_1912_multiple_fetch(self):
252289
253290 def test_1913_nclob_cursor_description (self ):
254291 "1913 - test cursor description is accurate for NCLOBs"
255- self .cursor .execute ("select * from TestNCLOBs" )
292+ self .cursor .execute ("select IntCol, NClobCol from TestNCLOBs" )
256293 expected_value = [
257294 ('INTCOL' , oracledb .DB_TYPE_NUMBER , 10 , None , 9 , 0 , 0 ),
258295 ('NCLOBCOL' , oracledb .DB_TYPE_NCLOB , None , None , None , None , 0 )
@@ -268,8 +305,10 @@ def test_1915_nclob_non_ascii_chars(self):
268305 value = "\u03b4 \u4e2a "
269306 self .cursor .execute ("truncate table TestNCLOBs" )
270307 self .cursor .setinputsizes (val = oracledb .DB_TYPE_NVARCHAR )
271- self .cursor .execute ("insert into TestNCLOBs values (1, :val)" ,
272- val = value )
308+ self .cursor .execute ("""
309+ insert into TestNCLOBs (IntCol, NClobCol)
310+ values (1, :val)""" ,
311+ val = value )
273312 self .cursor .execute ("select NCLOBCol from TestNCLOBs" )
274313 nclob , = self .cursor .fetchone ()
275314 self .cursor .setinputsizes (val = oracledb .DB_TYPE_NVARCHAR )
@@ -327,7 +366,11 @@ def test_1920_supplemental_characters(self):
327366 self .cursor .execute ("truncate table TestCLOBs" )
328367 lob = self .connection .createlob (oracledb .DB_TYPE_CLOB )
329368 lob .write (supplemental_chars )
330- self .cursor .execute ("insert into TestCLOBs values (1, :val)" , [lob ])
369+ self .cursor .execute ("""
370+ insert into TestCLOBs
371+ (IntCol, ClobCol)
372+ values (1, :val)""" ,
373+ [lob ])
331374 self .connection .commit ()
332375 self .cursor .execute ("select ClobCol from TestCLOBs" )
333376 lob , = self .cursor .fetchone ()
@@ -395,5 +438,17 @@ def test_1926_pickle_nclob(self):
395438 "1925 - test pickling of NCLOB"
396439 self .__test_pickle ("NCLOB" )
397440
441+ def test_1927_fetch_blob_as_bytes (self ):
442+ "1927 - test fetching BLOB as bytes"
443+ self .__test_fetch_lobs_direct ("BLOB" )
444+
445+ def test_1928_fetch_clob_as_str (self ):
446+ "1928 - test fetching CLOB as str"
447+ self .__test_fetch_lobs_direct ("CLOB" )
448+
449+ def test_1929_fetch_nclob_as_str (self ):
450+ "1929 - test fetching NCLOB as str"
451+ self .__test_fetch_lobs_direct ("NCLOB" )
452+
398453if __name__ == "__main__" :
399454 test_env .run_test_cases ()
0 commit comments