version 1.15, 2007/08/09 15:09:27
|
version 1.16, 2007/12/11 16:21:24
|
Line 19 except:
|
Line 19 except:
|
|
|
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
|
|
version_string = "V0.4.1 ROC 9.8.2007" |
version_string = "V0.5 ROC 11.12.2007" |
|
|
def getTextFromNode(nodename): |
def getTextFromNode(nodename): |
"""get the cdata content of a node""" |
"""get the cdata content of a node""" |
Line 191 class xml_handler:
|
Line 191 class xml_handler:
|
# rename table for backup |
# rename table for backup |
if self.backup_table: |
if self.backup_table: |
self.orig_table = self.table |
self.orig_table = self.table |
self.table = self.table + "_tmp" |
self.tmp_table = self.table + "_tmp" |
|
backup_name = "%s_%s"%(self.table,time.strftime('%Y_%m_%d_%H_%M_%S')) |
|
|
# remove old temp table |
# remove old temp table |
qstr = "DROP TABLE %s"%(self.table) |
qstr = "DROP TABLE %s"%(self.tmp_table) |
try: |
try: |
self.db.execute(qstr) |
self.db.execute(qstr) |
except: |
except: |
Line 202 class xml_handler:
|
Line 204 class xml_handler:
|
self.dbCon.commit() |
self.dbCon.commit() |
|
|
if self.id_field: |
if self.id_field: |
# sync mode -- copy table |
# sync mode -- copy backup table, update current table |
self.logger.info("copy table %s to %s"%(self.orig_table,self.table)) |
self.logger.info("copy table %s to %s"%(self.table,backup_name)) |
qstr = "CREATE TABLE %s AS (SELECT * FROM %s)"%(self.table,self.orig_table) |
qstr = "CREATE TABLE %s AS (SELECT * FROM %s)"%(backup_name,self.table) |
|
|
else: |
else: |
# rename table and create empty new one |
# replace mode -- create empty tmp table, insert into tmp table |
|
self.table = self.tmp_table |
self.logger.info("create empty table %s"%(self.table)) |
self.logger.info("create empty table %s"%(self.table)) |
qstr = "CREATE TABLE %s AS (SELECT * FROM %s WHERE 1=0)"%(self.table,self.orig_table) |
qstr = "CREATE TABLE %s AS (SELECT * FROM %s WHERE 1=0)"%(self.table,self.orig_table) |
|
|
Line 353 class xml_handler:
|
Line 356 class xml_handler:
|
self.dbCon.commit() |
self.dbCon.commit() |
|
|
# reinstate backup tables |
# reinstate backup tables |
if self.backup_table: |
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')) |
self.logger.info("rename backup table %s to %s"%(self.orig_table,backup_name)) |
self.logger.info("rename backup table %s to %s"%(self.orig_table,backup_name)) |
qstr = "ALTER TABLE %s RENAME TO %s"%(self.orig_table,backup_name) |
qstr = "ALTER TABLE %s RENAME TO %s"%(self.orig_table,backup_name) |
Line 478 def importFMPXML(options):
|
Line 481 def importFMPXML(options):
|
@param options.keep_fields: (optional) don't add fields to SQL database |
@param options.keep_fields: (optional) don't add fields to SQL database |
@param options.ascii_db: (optional) assume ascii encoding in db |
@param options.ascii_db: (optional) assume ascii encoding in db |
@param options.replace_table: (optional) delete and re-insert data |
@param options.replace_table: (optional) delete and re-insert data |
@param options.backup_table: (optional) create backup of old table (breaks indices) |
@param options.backup_table: (optional) create backup of old table |
""" |
""" |
|
|
if getattr(options,'update_fields',None): |
if getattr(options,'update_fields',None): |
Line 544 if __name__ == "__main__":
|
Line 547 if __name__ == "__main__":
|
help="replace table i.e. delete and re-insert data") |
help="replace table i.e. delete and re-insert data") |
opars.add_option("--backup", default=False, action="store_true", |
opars.add_option("--backup", default=False, action="store_true", |
dest="backup_table", |
dest="backup_table", |
help="create backup of old table (breaks indices)") |
help="create backup of old table") |
opars.add_option("-d", "--debug", default=False, action="store_true", |
opars.add_option("-d", "--debug", default=False, action="store_true", |
dest="debug", |
dest="debug", |
help="debug mode (more output)") |
help="debug mode (more output)") |