version 1.29, 2009/02/10 17:54:00
|
version 1.32, 2011/05/20 16:03:18
|
Line 22 except:
|
Line 22 except:
|
|
|
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
|
|
version_string = "V0.6.3 ROC 10.2.2009" |
version_string = "V0.6.6 ROC 20.5.2011" |
|
|
def unicodify(text, withNone=False): |
def unicodify(text, withNone=False): |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
Line 205 class xml_handler:
|
Line 205 class xml_handler:
|
#First round through the generator corresponds to the |
#First round through the generator corresponds to the |
#start element event |
#start element event |
self.logger.info("reading metadata...") |
self.logger.info("reading metadata...") |
|
if self.debug_data: |
self.logger.debug("START METADATA") |
self.logger.debug("START METADATA") |
yield None |
yield None |
|
|
Line 217 class xml_handler:
|
Line 218 class xml_handler:
|
yield None |
yield None |
|
|
#Element closed. Wrap up |
#Element closed. Wrap up |
|
if self.debug_data: |
self.logger.debug("END METADATA") |
self.logger.debug("END METADATA") |
|
|
# rename table for backup |
# rename table for backup |
Line 367 class xml_handler:
|
Line 369 class xml_handler:
|
#First round through the generator corresponds to the |
#First round through the generator corresponds to the |
#start element event |
#start element event |
self.logger.info("reading data...") |
self.logger.info("reading data...") |
|
if self.debug_data: |
self.logger.debug("START RESULTSET") |
self.logger.debug("START RESULTSET") |
self.rowcnt = 0 |
self.rowcnt = 0 |
yield None |
yield None |
Line 380 class xml_handler:
|
Line 383 class xml_handler:
|
yield None |
yield None |
|
|
#Element closed. Wrap up |
#Element closed. Wrap up |
|
if self.debug_data: |
self.logger.debug("END RESULTSET") |
self.logger.debug("END RESULTSET") |
self.dbCon.commit() |
self.dbCon.commit() |
|
|
if self.sync_mode: |
if self.sync_mode: |
# delete unmatched entries in db |
# delete unmatched entries in db |
|
if self.rowcnt > 0: |
self.logger.info("deleting unmatched rows from db") |
self.logger.info("deleting unmatched rows from db") |
delQuery = "DELETE FROM %s WHERE \"%s\" = %%s"%(self.table,self.id_field) |
delQuery = "DELETE FROM %s WHERE \"%s\" = %%s"%(self.table,self.id_field) |
for id in self.dbIDs.keys(): |
for id in self.dbIDs.keys(): |
Line 398 class xml_handler:
|
Line 403 class xml_handler:
|
|
|
self.dbCon.commit() |
self.dbCon.commit() |
|
|
|
else: |
|
# safety in case we had an empty file |
|
self.logger.warning("no rows read! not deleting unmatched rows!") |
|
|
# reinstate backup tables |
# reinstate backup tables |
if self.backup_table and not self.id_field: |
if self.backup_table and not self.id_field: |
backup_name = "%s_%s"%(self.orig_table,time.strftime('%Y_%m_%d_%H_%M_%S')) |
backup_name = "%s_%s"%(self.orig_table,time.strftime('%Y_%m_%d_%H_%M_%S')) |
Line 409 class xml_handler:
|
Line 418 class xml_handler:
|
self.db.execute(qstr) |
self.db.execute(qstr) |
self.dbCon.commit() |
self.dbCon.commit() |
|
|
|
self.logger.info("Done (%s rows)"%self.rowcnt) |
return |
return |
|
|
def handle_row(self, end_condition): |
def handle_row(self, end_condition): |
Line 416 class xml_handler:
|
Line 426 class xml_handler:
|
(saxtools.START_ELEMENT, fm_ns, u'COL'): |
(saxtools.START_ELEMENT, fm_ns, u'COL'): |
self.handle_col, |
self.handle_col, |
} |
} |
|
if self.debug_data: |
self.logger.debug("START ROW") |
self.logger.debug("START ROW") |
self.xml_data = {} |
self.xml_data = {} |
self.colIdx = 0 |
self.colIdx = 0 |
Line 430 class xml_handler:
|
Line 441 class xml_handler:
|
yield None |
yield None |
|
|
#Element closed. Wrap up |
#Element closed. Wrap up |
|
if self.debug_data: |
self.logger.debug("END ROW") |
self.logger.debug("END ROW") |
self.rowcnt += 1 |
self.rowcnt += 1 |
# process collected row data |
# process collected row data |
Line 464 class xml_handler:
|
Line 476 class xml_handler:
|
f = self.xml_field_map[fn] |
f = self.xml_field_map[fn] |
val = self.xml_data[fn] |
val = self.xml_data[fn] |
type = self.sql_fields[f.getName()].getType() |
type = self.sql_fields[f.getName()].getType() |
if type == "date" and len(val) == 0: |
if type == "date" and len(val.strip()) == 0: |
# empty date field |
# empty date field |
val = None |
val = None |
|
|