USERNAME = 'MKV'
PASSWORD = '1234'
TNSENTRY = 'tb12'
ARRAY_SIZE = 50
class VoraDriver:
def __init__(self):
self.connection = ''
self.cursor = ''
def setUp(self):
self.connection = cx_Oracle.connect(USERNAME, PASSWORD, TNSENTRY)
self.cursor = self.connection.cursor()
self.cursor.arraysize = ARRAY_SIZE
def __del__(self):
del self.cursor
del self.connection
#class VoraDriver:
class VcsvReader:
def __init__(self, fname='t.csv'):
self.fname = fname
self.fileObj = open(fname, 'rb')
self.csvReader = csv.reader(self.fileObj, \
delimiter=';', quotechar="'", quoting=csv.QUOTE_ALL, lineterminator='\n')
def __del__(self):
del self.csvReader
self.fileObj.close()
def readrow(self):
try:
return self.csvReader.next()
except:
return None
#class VcsvReader:
def insertRecord(row, ora):
ora.cursor.setinputsizes(coords = cx_Oracle.CLOB)
ora.cursor.execute("""
INSERT INTO MKV.BIGTAB (
DWG, TYPENAME, TYPENUM, LYR, EID, HAND, XDATA, COORDS, ROTANG, TXT, CLOSTY, RAD)
values (:dwg, :typename, :typenum, :layer, :id, :handle, :xdata,
:coords,
:angle, :text, :closed, :radius
)""", dwg = row[0], typename = row[1], typenum = row[2], layer = row[3].decode('utf-8'), \
id = row[4], handle = row[5],\
xdata = row[6].decode('utf-8'), coords = row[7], angle = row[8], text = row[9].decode('utf-8'),\
closed = row[10].decode('utf-8'), radius = row[11])
#~ ora.connection.commit()
#def insertRecord(row, ora):
def doWork(inp):
ora = VoraDriver()
ora.setUp()
rdr = VcsvReader(inp)
csvRowNum = 0
while True:
row = rdr.readrow()
csvRowNum += 1
if row == None: break
if csvRowNum < 3:
t = map(lambda a: (sys.stdout.write('[%s], ' % a)), row)
print
continue
insertRecord(row, ora)
... |
Комментариев нет:
Отправить комментарий