Skip to content

Instantly share code, notes, and snippets.

@jinjie
Created October 29, 2013 05:44
Show Gist options
  • Save jinjie/7209632 to your computer and use it in GitHub Desktop.
Save jinjie/7209632 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sqlite3 as lite
import sys
con = None
try :
con = lite.connect(<Sqlite file>)
con.row_factory = lite.Row
cur = con.cursor()
cur.execute('SELECT * FROM ZABCDNOTE WHERE ZTEXT LIKE \'%HTCData%\';')
rows = cur.fetchall()
for row in rows :
start = row["ZTEXT"].index("<HTCData>")
end = row["ZTEXT"].index("</HTCData>")
if end > start :
cur.execute("UPDATE ZABCDNOTE SET ZTEXT = ? WHERE Z_PK = ?", (
row["ZTEXT"].replace(row["ZTEXT"][start:end+10], ''),
row["Z_PK"]
))
con.commit()
print "Updated %d" % cur.rowcount
except lite.Error, e :
print "Error %s:" % e.args[0]
sys.exit(1)
finally :
if con :
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment