version 1.23, 2008/02/13 19:48:50
|
version 1.24, 2008/03/06 12:10:55
|
Line 22 except:
|
Line 22 except:
|
|
|
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
fm_ns = 'http://www.filemaker.com/fmpxmlresult' |
|
|
version_string = "V0.6 ROC 13.2.2008" |
version_string = "V0.6.1 ROC .2008" |
|
|
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 261 class xml_handler:
|
Line 261 class xml_handler:
|
qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0 and relname = '%s'" |
qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0 and relname = '%s'" |
self.sql_fields={} |
self.sql_fields={} |
for f in SimpleSearch(self.db, qstr%self.table): |
for f in SimpleSearch(self.db, qstr%self.table): |
n = f[0] |
fn = f[0] |
t = f[1] |
ft = f[1] |
#print "SQL fields: %s (%s)"%(n,t) |
#print "SQL fields: %s (%s)"%(n,t) |
self.sql_fields[n] = TableColumn(n,t) |
self.sql_fields[fn] = TableColumn(fn,ft) |
|
|
# translate id_field (SQL-name) to XML-name |
# translate id_field (SQL-name) to XML-name |
self.xml_id = self.sql_field_map.get(self.id_field, None) |
self.xml_id = self.sql_field_map.get(self.id_field, None) |
Line 313 class xml_handler:
|
Line 313 class xml_handler:
|
self.logger.debug("field %s has different type (%s vs %s)"%(f,f.getType(),sf.getType())) |
self.logger.debug("field %s has different type (%s vs %s)"%(f,f.getType(),sf.getType())) |
elif uf is not None: |
elif uf is not None: |
# add field to table |
# add field to table |
qstr="alter table %s add %s %s"%(self.table,uf.getName(),uf.getType()) |
fn = uf.getName() |
|
ft = uf.getType() |
|
qstr="alter table %s add \"%s\" %s"%(self.table,fn,ft) |
self.logger.info("db add field:"+qstr) |
self.logger.info("db add field:"+qstr) |
|
|
if self.ascii_db and type(qstr)==types.UnicodeType: |
if self.ascii_db and type(qstr)==types.UnicodeType: |
Line 321 class xml_handler:
|
Line 323 class xml_handler:
|
|
|
self.db.execute(qstr) |
self.db.execute(qstr) |
self.dbCon.commit() |
self.dbCon.commit() |
|
# add field to field list |
|
self.sql_fields[fn] = TableColumn(fn, ft) |
|
|
# prepare sql statements for update (do not update id_field) |
# prepare sql statements for update (do not update id_field) |
setStr=string.join(["%s = %%s"%self.xml_field_map[f] for f in self.xml_update_list if f != self.xml_id], ', ') |
setStr=string.join(["\"%s\" = %%s"%self.xml_field_map[f] for f in self.xml_update_list if f != self.xml_id], ', ') |
self.updQuery="UPDATE %s SET %s WHERE %s = %%s"%(self.table,setStr,self.id_field) |
self.updQuery="UPDATE %s SET %s WHERE \"%s\" = %%s"%(self.table,setStr,self.id_field) |
# and select (for update check) |
# and select (for update check) |
selStr=string.join([self.xml_field_map[f].getName() for f in self.xml_update_list if f != self.xml_id], ', ') |
selStr=string.join([self.xml_field_map[f].getName() for f in self.xml_update_list if f != self.xml_id], ', ') |
self.selQuery="SELECT %s FROM %s WHERE %s = %%s"%(selStr,self.table,self.id_field) |
self.selQuery="SELECT %s FROM %s WHERE \"%s\" = %%s"%(selStr,self.table,self.id_field) |
# and insert |
# and insert |
fields=string.join([self.xml_field_map[x].getName() for x in self.xml_update_list], ',') |
fields=string.join(["\"%s\""%self.xml_field_map[x].getName() for x in self.xml_update_list], ',') |
values=string.join(['%s' for f in self.xml_update_list], ',') |
values=string.join(['%s' for f in self.xml_update_list], ',') |
self.addQuery="INSERT INTO %s (%s) VALUES (%s)"%(self.table,fields,values) |
self.addQuery="INSERT INTO %s (%s) VALUES (%s)"%(self.table,fields,values) |
self.logger.debug("update-query: "+self.updQuery) |
self.logger.debug("update-query: "+self.updQuery) |
Line 380 class xml_handler:
|
Line 384 class xml_handler:
|
if self.sync_mode: |
if self.sync_mode: |
# delete unmatched entries in db |
# delete unmatched entries in db |
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(): |
# find all not-updated fields |
# find all not-updated fields |
if self.dbIDs[id] == 0: |
if self.dbIDs[id] == 0: |