本文整理匯總了Python中DatabaseManager.DatabaseManager.runCommit方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseManager.runCommit方法的具體用法?Python DatabaseManager.runCommit怎麽用?Python DatabaseManager.runCommit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DatabaseManager.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.runCommit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from DatabaseManager import DatabaseManager [as 別名]
# 或者: from DatabaseManager.DatabaseManager import runCommit [as 別名]
def main():
print "Reading minID"
fp = open('ids.txt', 'r')
for line in fp:
ids = line.strip().split(",")
minID = ids[0]
maxID = ids[1]
fp.close()
print "minID: ", minID
print "maxID: ", maxID
dbm = DatabaseManager()
print "running query..."
places = dbm.runQuery("SELECT id, bounding_box FROM Places \
WHERE lat_1 IS NULL AND id >= {0} AND id < {1}".format(minID, maxID))
print "query done!"
cont = 0.0;
for row in places:
try:
idPlace = row[0]
bounding_box = row[1]
tmp = re.sub(r'u\'','\'', bounding_box)
tmp = re.sub(r'\'','"', tmp)
obj = json.loads(tmp)
box_coords = obj['coordinates'][0]
lat_1 = box_coords[0][1]
long_1 = box_coords[0][0]
lat_2 = box_coords[1][1]
long_2 = box_coords[1][0]
lat_3 = box_coords[2][1]
long_3 = box_coords[2][0]
lat_4 = box_coords[3][1]
long_4 = box_coords[3][0]
query = u"""UPDATE Places SET lat_1={0}, long_1={1}, lat_2={2}, long_2={3},lat_3={4}, long_3={5}, lat_4={6}, long_4={7} WHERE id = {8}""".format(lat_1, long_1, lat_2, long_2, lat_3, long_3, lat_4, long_4, idPlace)
print cont
dbm.runCommit(query)
except Exception as e:
print "error with id=", row[0]
print e
cont += 1