Ejemplo n.º 1
0
 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'])
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
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:
Ejemplo n.º 4
0
#!/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())