Mar-09-2022, 11:26 PM
(This post was last modified: Mar-09-2022, 11:34 PM by Yoriz.
Edit Reason: Added code tags
)
Hi all,
I have this code below where from table all have values so all files generated should not be empty.
Seems cursor is writing X-1 (Skeeping the latest one it tries to generate. It create file but did not write to it.)
Can anyone help on this?
I have this code below where from table all have values so all files generated should not be empty.
import cx_Oracle as oracledb def output_type_handler(cursor, name, default_type, size, precision, scale): if default_type == oracledb.CLOB: return cursor.var(oracledb.LONG_STRING, arraysize=cursor.arraysize) if default_type == oracledb.BLOB: return cursor.var(oracledb.LONG_BINARY, arraysize=cursor.arraysize) conn = oracledb.connect("/", mode=oracledb.SYSASM) conn.outputtypehandler = output_type_handler prev_name = None cursor.execute("select cellname, confval from v$cell_config where conftype='CELL' order by cellname desc") for name, val in cursor: if name != prev_name: filename = "my_file_%s.xml" %name print("File name is: ", filename) print("XML Content for this line is: ", val) f = open(filename,"w") prev_name = name f.write(val)It generate 3 files where 1 is empty:
Output:-rw-r--r-- 1 grid oinstall 2008 Mar 9 23:23 my_file_172.16.4.129;172.16.4.130.xml
-rw-r--r-- 1 grid oinstall 2008 Mar 9 23:23 my_file_172.16.4.127;172.16.4.128.xml
-rw-r--r-- 1 grid oinstall 0 Mar 9 23:23 my_file_172.16.4.125;172.16.4.126.xml
If I debug using print I can see data for all 3 lines . Seems cursor is writing X-1 (Skeeping the latest one it tries to generate. It create file but did not write to it.)
Can anyone help on this?