def __del__(self): """Some cleanup code so the database doesn't get too icky""" db = Db.getDBH() cur = db.cursor() cur.execute('SELECT wsid FROM wn_workspaces where wsname=%s', [urllib.unquote(_WORKSPACE)]) wsid = cur.fetchone()[0] cur.execute('DELETE FROM wn_notes WHERE wsid=%s AND time > %s', [wsid, '20050530222438'])
def __init__(self): self.name = '' self.notes = [] self.nextNoteNum = 0 self.lasttime = '' # string self.newNoteText = '' # create a db connection self.dbh = Db.getDBH() self.db = self.dbh.cursor()
your sysadmin to install it for you.</p>""" raise def create(): print "<p>Trying to create tables . . ." try: from lib import Db from etc import common assert common.TABLE_SHARDS > 0 assert len(common.TABLE_PREFIX) != 0 except Exception, e: print "failed to read db values from config:", e raise try: db = Db.getDBH() cur = db.cursor() shards = common.TABLE_SHARDS max_digits = len(str(shards)) # create 'workspaces' and 'notes' table for each shard for num in xrange(shards): num = Db.getShardNum(num) table_name = "%s%s%s" % (common.TABLE_PREFIX, "workspaces", num) create_sql = CREATE_WORKSPACE % {'table_name': table_name} cur.execute(create_sql) table_name = "%s%s%s" % (common.TABLE_PREFIX, "notes", num) create_sql = CREATE_NOTES % {'table_name': table_name} cur.execute(create_sql) except Exception, e:
#!/usr/bin/python import MySQLdb import csv import sys sys.path.insert(0, '..') from lib import Db cur = Db.getDBH().cursor() print 'db' cur.execute('select wsid, count(nid), time from wn_notes' ' where wsid != 15' ' group by wsid, time order by wsid') writer = csv.writer(open('usage.csv', 'w')) print 'write' writer.writerows(cur.fetchall())