version 1.1, 2006/12/20 18:45:58
|
version 1.2, 2006/12/20 20:29:27
|
Line 3
|
Line 3
|
|
|
import string |
import string |
from xml.dom.pulldom import parse |
from xml.dom.pulldom import parse |
import psycopg2 as psycopg |
|
import logging |
import logging |
import sys |
import sys |
|
|
|
try: |
|
import psycopg2 as psycopg |
|
psyco = 2 |
|
except: |
|
import psycopg |
|
psyco = 1 |
|
|
|
|
def getTextFromNode(nodename): |
def getTextFromNode(nodename): |
"""get the cdata content of a node""" |
"""get the cdata content of a node""" |
Line 30 def sql_quote(v):
|
Line 36 def sql_quote(v):
|
def SimpleSearch(curs,query, args=None): |
def SimpleSearch(curs,query, args=None): |
"""execute sql query and return data""" |
"""execute sql query and return data""" |
logging.debug("executing: "+query) |
logging.debug("executing: "+query) |
|
if psyco == 1: |
|
query = query.encode("UTF-8") |
curs.execute(query, args) |
curs.execute(query, args) |
logging.debug("sql done") |
logging.debug("sql done") |
return curs.fetchall() |
return curs.fetchall() |
Line 146 def importXMLFileFMP(dsn,table,filename,
|
Line 154 def importXMLFileFMP(dsn,table,filename,
|
setStr=string.join(setvals, ',') |
setStr=string.join(setvals, ',') |
id_val=dataSet[id_field] |
id_val=dataSet[id_field] |
qstr="UPDATE %s SET %s WHERE %s = '%s' "%(table,setStr,id_field,id_val) |
qstr="UPDATE %s SET %s WHERE %s = '%s' "%(table,setStr,id_field,id_val) |
|
if psyco == 1: |
|
query = query.encode("UTF-8") |
db.execute(qstr) |
db.execute(qstr) |
ret += "up: %s"%id_val |
ret += "up: %s"%id_val |
else: |
else: |
Line 153 def importXMLFileFMP(dsn,table,filename,
|
Line 163 def importXMLFileFMP(dsn,table,filename,
|
fields=string.join(update_fields, ',') |
fields=string.join(update_fields, ',') |
values=string.join([" %s "%sql_quote(dataSet[x]) for x in update_fields], ',') |
values=string.join([" %s "%sql_quote(dataSet[x]) for x in update_fields], ',') |
qstr="INSERT INTO %s (%s) VALUES (%s)"%(table,fields,values) |
qstr="INSERT INTO %s (%s) VALUES (%s)"%(table,fields,values) |
|
if psyco == 1: |
|
query = query.encode("UTF-8") |
db.execute(qstr) |
db.execute(qstr) |
ret += "ad: %s"%dataSet.get(id_field, rowcnt) |
ret += "ad: %s"%dataSet.get(id_field, rowcnt) |
|
|
Line 169 def importXMLFileFMP(dsn,table,filename,
|
Line 181 def importXMLFileFMP(dsn,table,filename,
|
if dbIDs[id] == 0: |
if dbIDs[id] == 0: |
logging.info(" delete:"+id) |
logging.info(" delete:"+id) |
qstr = "DELETE FROM %s WHERE %%s = '%%s'"%table |
qstr = "DELETE FROM %s WHERE %%s = '%%s'"%table |
|
if psyco == 1: |
|
query = query.encode("UTF-8") |
db.execute(qstr, (id_field,id)) |
db.execute(qstr, (id_field,id)) |
|
|
elif dbIDs[id] > 1: |
elif dbIDs[id] > 1: |