diff sat_pubsub/pgsql_storage.py @ 276:b757c29b20d7

import changes from idavoll changeset 233 (24be3a11ddbc), by Ralph Meijer and based on a patch by Nuno Santos
author souliane <souliane@mailoo.org>
date Mon, 13 Oct 2014 15:59:25 +0200
parents 232002e132db
children 8a71486c3e95
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Thu Aug 01 16:22:14 2013 -0700
+++ b/sat_pubsub/pgsql_storage.py	Mon Oct 13 15:59:25 2014 +0200
@@ -174,7 +174,7 @@
         cursor.execute("""SELECT node_id FROM nodes WHERE node=%s""", (nodeIdentifier,));
         node_id = cursor.fetchone()[0]
 
-        cursor.execute("""SELECT 1 from entities where jid=%s""",
+        cursor.execute("""SELECT 1 as bool from entities where jid=%s""",
                        (owner,))
 
         if not cursor.fetchone():
@@ -383,6 +383,7 @@
                        (self.nodeIdentifier,
                         userhost,
                         resource))
+
         row = cursor.fetchone()
         if not row:
             return None
@@ -402,14 +403,14 @@
                    FROM subscriptions
                    NATURAL JOIN nodes
                    NATURAL JOIN entities
-                   WHERE node=%s""";
+                   WHERE node=%s"""
         values = [self.nodeIdentifier]
 
         if state:
             query += " AND state=%s"
             values.append(state)
 
-        cursor.execute(query, values);
+        cursor.execute(query, values)
         rows = cursor.fetchall()
 
         subscriptions = []
@@ -501,7 +502,7 @@
     def _isSubscribed(self, cursor, entity):
         self._checkNodeExists(cursor)
 
-        cursor.execute("""SELECT 1 FROM entities
+        cursor.execute("""SELECT 1 as bool FROM entities
                           NATURAL JOIN subscriptions
                           NATURAL JOIN nodes
                           WHERE entities.jid=%s
@@ -761,28 +762,28 @@
         """
         cursor.execute("""SELECT count(*) FROM callbacks
                           WHERE service=%s and node=%s""",
-                       service.full(),
-                       nodeIdentifier)
+                       (service.full(),
+                        nodeIdentifier))
         results = cursor.fetchall()
         return results[0][0]
 
 
     def addCallback(self, service, nodeIdentifier, callback):
         def interaction(cursor):
-            cursor.execute("""SELECT 1 FROM callbacks
+            cursor.execute("""SELECT 1 as bool FROM callbacks
                               WHERE service=%s and node=%s and uri=%s""",
-                           service.full(),
+                           (service.full(),
                            nodeIdentifier,
-                           callback)
+                           callback))
             if cursor.fetchall():
                 return
 
             cursor.execute("""INSERT INTO callbacks
                               (service, node, uri) VALUES
                               (%s, %s, %s)""",
-                           service.full(),
+                           (service.full(),
                            nodeIdentifier,
-                           callback)
+                           callback))
 
         return self.dbpool.runInteraction(interaction)
 
@@ -791,9 +792,9 @@
         def interaction(cursor):
             cursor.execute("""DELETE FROM callbacks
                               WHERE service=%s and node=%s and uri=%s""",
-                           service.full(),
-                           nodeIdentifier,
-                           callback)
+                           (service.full(),
+                            nodeIdentifier,
+                            callback))
 
             if cursor.rowcount != 1:
                 raise error.NotSubscribed()
@@ -807,8 +808,8 @@
         def interaction(cursor):
             cursor.execute("""SELECT uri FROM callbacks
                               WHERE service=%s and node=%s""",
-                           service.full(),
-                           nodeIdentifier)
+                           (service.full(),
+                            nodeIdentifier))
             results = cursor.fetchall()
 
             if not results: