Browse Source

AUTO_INCREMENT the ID for signatures.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
c99faeb1b3
2 changed files with 8 additions and 10 deletions
  1. +7
    -9
      earwigbot/tasks/drn_clerkbot.py
  2. +1
    -1
      earwigbot/tasks/schema/drn_clerkbot.sql

+ 7
- 9
earwigbot/tasks/drn_clerkbot.py View File

@@ -174,7 +174,7 @@ class DRNClerkBot(Task):


def read_page(self, conn, cases, text): def read_page(self, conn, cases, text):
"""Read the noticeboard content and update the list of _Cases.""" """Read the noticeboard content and update the list of _Cases."""
nextid = self.select_next_id(conn, "case_id", "cases")
nextid = self.select_next_id(conn)
tl_status_esc = re.escape(self.tl_status) tl_status_esc = re.escape(self.tl_status)
split = re.split("(^==\s*[^=]+?\s*==$)", text, flags=re.M|re.U) split = re.split("(^==\s*[^=]+?\s*==$)", text, flags=re.M|re.U)
for i in xrange(len(split)): for i in xrange(len(split)):
@@ -217,14 +217,14 @@ class DRNClerkBot(Task):
case.title = title case.title = title
case.body, case.old = body, old case.body, case.old = body, old


def select_next_id(self, conn, column, table):
def select_next_id(self, conn):
"""Return the next incremental ID for a case.""" """Return the next incremental ID for a case."""
query = "SELECT MAX(?) FROM {0}".format(table)
query = "SELECT MAX(case_id) FROM cases"
with conn.cursor() as cursor: with conn.cursor() as cursor:
cursor.execute(query, (column,))
cursor.execute(query)
current = cursor.fetchone()[0] current = cursor.fetchone()[0]
if current: if current:
return current + 1
return int(current) + 1
return 1 return 1


def read_status(self, body): def read_status(self, body):
@@ -418,18 +418,16 @@ class DRNClerkBot(Task):


with conn.cursor() as cursor: with conn.cursor() as cursor:
query1 = "DELETE FROM signatures WHERE signature_case = ? AND signature_username = ? AND signature_timestamp = ?" query1 = "DELETE FROM signatures WHERE signature_case = ? AND signature_username = ? AND signature_timestamp = ?"
query2 = "INSERT INTO signatures VALUES (?, ?, ?, ?)"
query2 = "INSERT INTO signatures (signature_case, signature_username, signature_timestamp) VALUES (?, ?, ?)"
removals = set(storedsigs) - set(sigs) removals = set(storedsigs) - set(sigs)
additions = set(sigs) - set(storedsigs) additions = set(sigs) - set(storedsigs)
if removals: if removals:
args = [(case.id, name, stamp) for (name, stamp) in removals] args = [(case.id, name, stamp) for (name, stamp) in removals]
cursor.executemany(query1, args) cursor.executemany(query1, args)
if additions: if additions:
nextid = self.select_next_id(conn, "signature_id", "signatures")
args = [] args = []
for name, stamp in additions: for name, stamp in additions:
args.append((nextid, case.id, name, stamp))
nextid += 1
args.append((case.id, name, stamp))
cursor.executemany(query2, args) cursor.executemany(query2, args)


def save_new_case(self, conn, case): def save_new_case(self, conn, case):


+ 1
- 1
earwigbot/tasks/schema/drn_clerkbot.sql View File

@@ -37,7 +37,7 @@ CREATE TABLE `cases` (


DROP TABLE IF EXISTS `signatures`; DROP TABLE IF EXISTS `signatures`;
CREATE TABLE `signatures` ( CREATE TABLE `signatures` (
`signature_id` int(10) unsigned NOT NULL,
`signature_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`signature_case` int(10) unsigned NOT NULL, `signature_case` int(10) unsigned NOT NULL,
`signature_username` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, `signature_username` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`signature_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `signature_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',


Loading…
Cancel
Save