]> git.etc.gen.nz Git - whoisi.git/commitdiff
Many changes to make SQL work with PostgreSQL.
authorAndrew Ruthven <andrew@etc.gen.nz>
Mon, 22 Jun 2009 09:32:05 +0000 (21:32 +1200)
committerAndrew Ruthven <andrew@etc.gen.nz>
Mon, 22 Jun 2009 09:34:04 +0000 (21:34 +1200)
services/command/feedparse.py
services/command/newsite.py
services/command/previewsite.py
whoisi/model.py
whoisi/utils/fast_history.py

index 465a238b02c1cc32b7e2ace8f68342d6a770d7c1..db3198654a6c0459239c59d3594da70c8f00026d 100644 (file)
@@ -217,7 +217,7 @@ class FeedUpdateDatabaseCommand(BaseCommand):
                 SELECT id, site_id, title, link, entry_id, added, published, updated, summary, content, display_cache FROM site_history where site_id = %s
                 """
             print("  getting current entries for %d" % self.site_id)
-            d = self.dcm.runQuery(q, self.site_id)
+            d = self.dcm.runQuery(q, [ self.site_id ])
             d.addCallback(self.gotEntries)
             d.addErrback(self.error)
 
@@ -415,9 +415,9 @@ class FeedUpdateDatabaseCommand(BaseCommand):
         # If new_site is in the state, we're adding a new site so set
         # the flag so that we know these sites were added when the
         # site was first added.
-        on_new = 0
+        on_new = False
         if self.state.has_key("new_site"):
-            on_new = 1
+            on_new = True
 
         t = datetime.utcnow()
 
@@ -428,7 +428,8 @@ class FeedUpdateDatabaseCommand(BaseCommand):
 
     def insertInteraction(self, trans, *args):
         trans.execute(*args)
-        return trans.lastrowid
+        trans.execute("SELECT CURRVAL('site_history_id_seq')")
+        return trans.fetchone()[0]
 
     def maybeUpdateEntry(self, entry, old_entry):
         published = None
@@ -503,11 +504,14 @@ class FeedUpdateDatabaseCommand(BaseCommand):
         q = "UPDATE site set " + update + "feed_type = %s, title = %s, last_poll = %s WHERE id = %s"
         args.extend([self.feed["version"], self.feed["title"], datetime.utcnow(), self.site_id])
 
-        d = self.dcm.runQuery(q, args);
+        d = self.dcm.runInteraction(self.newInteraction, q, args);
 
         d.addCallback(self.done)
         d.addErrback(self.error)
 
+    def newInteraction(self, trans, *args):
+        trans.execute(*args)
+
     def done(self, *args):
         print("  done.")
         self.state["site_history_new_ids"] = self.insert_ids
index 87a85922044da6025a7a9ce7e7a05f60101eb8ff..57e87e1d7e6dd23f9eda3ae3266438939f3f977b 100644 (file)
@@ -97,7 +97,7 @@ class NewSiteSetup(BaseCommand):
             SELECT person_id, url, status, data, track_info FROM new_site WHERE id = %s
             """
         
-        d = self.dcm.runQuery(q, self.id)
+        d = self.dcm.runQuery(q, [ self.id ])
         d.addCallback(self.gotNewSite)
         d.addErrback(self.error)
 
@@ -469,7 +469,8 @@ class NewSiteCreate(BaseCommand):
 
     def newSiteInteraction(self, trans, *args):
         trans.execute(*args)
-        return trans.lastrowid
+        trans.execute("SELECT CURRVAL('site_id_seq')")
+        return trans.fetchone()[0]
 
     def siteSetupDone(self, results):
         self.state["site_id"] = results
@@ -515,12 +516,17 @@ class NewSiteAudit(BaseCommand):
         referer=ti.get("referer", None)
         follower=ti.get("follower", None)
 
-        d = self.dcm.runQuery(q, (t, "add", "site", state["site_id"], follower, referer, remoteip, useragent))
+        d = self.dcm.runInteraction(self.newInteraction, q, (t, "add", "site", state["site_id"], follower, referer, remoteip, useragent))
         d.addCallback(self.done)
         d.addErrback(self.error)
 
         return self.d
 
+    def newInteraction(self, trans, *args):
+        trans.execute(*args)
+        trans.execute("SELECT CURRVAL('change_audit_id_seq')")
+        return trans.fetchone()[0]
+
     def done(self, *args, **kw):
         self.d.callback(None)
 
@@ -544,13 +550,18 @@ class NewSiteDone(BaseCommand):
         q = """
             UPDATE new_site SET status = 'done', site_id = %s where id = %s
             """
-        d = self.dcm.runQuery(q, (state["site_id"], state["id"]))
+        d = self.dcm.runInteraction(self.newSiteInteraction, q, (state["site_id"], state["id"]))
+        
         d.addCallback(self.done)
         d.addErrback(self.error)
 
         return self.d
 
-    def done(self, *args, **kw):
+    def newSiteInteraction(self, trans, *args):
+        trans.execute(*args)
+        return trans.lastrowid
+
+    def done(self, result, *args, **kw):
         site_history_new_ids = self.state.get("site_history_new_ids", [])
         self.d.callback(dict(site_id=self.state["site_id"],
                              site_history_new_ids=site_history_new_ids,
@@ -575,7 +586,7 @@ class NewSiteError:
                 UPDATE new_site SET status = 'pick_url', data = %s WHERE id = %s
                 """
 
-            d = self.dcm.runQuery(q, (data, id))
+            d = self.dcm.runInteraction(self.newInteraction, q, (data, id))
             d.addCallback(self.updateDone)
 
         else:
@@ -601,13 +612,17 @@ class NewSiteError:
             else:
                 error = "internal"
 
-            d = self.dcm.runQuery(q, (error, id))
+            d = self.dcm.runInteraction(self.newInteraction, q, (error, id))
             d.addCallback(self.updateDoneError)
 
         return self.d
 
+    def newInteraction(self, trans, *args):
+        trans.execute(*args)
+        return trans.lastrowid
+
     def updateDoneError(self, *args, **kw):
         self.d.errback(self.orig_failure)
 
-    def updateDone(self, *args, **kw):
+    def updateDone(self, result, *args, **kw):
         self.d.callback(dict(site_id=None, type=None))
index 7b4db591814401c27b11a07177b778c3f994c541..df3838feb629fad7692bde9e1c2aa03078c190c4 100644 (file)
@@ -70,12 +70,16 @@ class PreviewSiteDone(BaseCommand):
             UPDATE new_site SET status = 'preview_done', data = %s where id = %s
             """
 
-        d = self.dcm.runQuery(q, (data, state["id"]))
+        d = self.dcm.runInteraction(self.newInteraction, q, (data, state["id"]))
         d.addCallback(self.done)
         d.addErrback(self.error)
 
         return self.d
 
+    def newInteraction(self, trans, *args):
+        trans.execute(*args)
+        return trans.lastrowid
+
     def done(self, *args, **kw):
         self.d.callback(None)
 
index 86b40fd8f126b74097365fec27efec6c07cb2f23..1bee3108028b64f76bc4792a12c2f69a195abdd6 100644 (file)
@@ -153,7 +153,7 @@ class Person(SQLObject):
         This uses raw mysql syntax to generate a random person ID.
         """
         c = Person._connection
-        result = c.queryAll("select id from person order by rand() limit 1")
+        result = c.queryAll("select id from person order by random() limit 1")
         return result[0][0]
 
 class Name(SQLObject):
@@ -232,7 +232,7 @@ class SiteHistory(SQLObject):
     summary = UnicodeCol(default=None)
     content = UnicodeCol(default=None)
     display_cache = UnicodeCol(default=None)
-    on_new = BoolCol(default=0) # set to one when this is an item that
+    on_new = BoolCol(default=False) # set to one when this is an item that
                                 # was added when the site was created.
 
     def getText(self):
index 412f18bcd6998dacac8cdaeeb13d3c6543ddca81..feb6da65ec6f207780af5326f380300aff3094ed 100644 (file)
@@ -78,7 +78,7 @@ site_history, site, person, follow_person
 WHERE
 site_history.site_id = site.id
 AND
-site_history.on_new = 0
+site_history.on_new = False
 AND
 site.is_removed is NULL
 AND
@@ -151,7 +151,7 @@ site_history.id > %s
 AND
 site_history.site_id = site.id
 AND
-site_history.on_new = 0
+site_history.on_new = False
 AND
 site.is_removed is NULL
 AND
@@ -176,7 +176,7 @@ site_history, site, follow_person
 WHERE
 site_history.site_id = site.id
 AND
-site_history.on_new = 0
+site_history.on_new = False
 AND
 site.is_removed is NULL
 AND
@@ -216,7 +216,7 @@ site_history, site, person, name
 WHERE
 site_history.site_id = site.id
 AND
-site_history.on_new = 0
+site_history.on_new = False
 AND
 site.is_removed is NULL
 AND
@@ -291,7 +291,7 @@ site.is_removed is NULL
 AND
 site_history.site_id = site.id
 AND
-site_history.on_new = 0
+site_history.on_new = False
 %s
 ORDER BY
 site_history.id