diff idavoll/pgsql_storage.py @ 127:d3689da18ed2

Don't use encode('utf-8') on serialized XML. Return unicode strings for get_items() Rename get_items_by_ids() to get_items_by_id() as in the interface. Make purge() work. Don't return item ids when removing items.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 24 Apr 2005 17:21:43 +0000
parents c4ee16bc48e5
children 327de183f48d
line wrap: on
line diff
--- a/idavoll/pgsql_storage.py	Sun Apr 24 17:19:27 2005 +0000
+++ b/idavoll/pgsql_storage.py	Sun Apr 24 17:21:43 2005 +0000
@@ -298,7 +298,7 @@
                           WHERE nodes.id = items.node_id AND
                                 nodes.node = %s and items.item=%s""",
                        (publisher.full().encode('utf8'),
-                        data.encode('utf8'),
+                        data,
                         self.id.encode('utf8'),
                         item["id"].encode('utf8')))
         if cursor.rowcount == 1:
@@ -308,7 +308,7 @@
                           SELECT id, %s, %s, %s FROM nodes WHERE node=%s""",
                        (item["id"].encode('utf8'),
                         publisher.full().encode('utf8'),
-                        data.encode('utf8'),
+                        data,
                         self.id.encode('utf8')))
 
     def remove_items(self, item_ids):
@@ -326,10 +326,8 @@
                            (self.id.encode('utf-8'),
                             item_id.encode('utf-8')))
 
-            if cursor.rowcount:
-                deleted.append(item_id)
-
-        return deleted
+            if not cursor.rowcount:
+                raise storage.ItemNotFound
 
     def get_items(self, max_items=None):
         return self._dbpool.runInteraction(self._get_items, max_items)
@@ -347,12 +345,12 @@
             cursor.execute(query, (self.id.encode('utf8')))
 
         result = cursor.fetchall()
-        return [r[0] for r in result]
+        return [unicode(r[0], 'utf8') for r in result]
 
-    def get_items_by_ids(self, item_ids):
-        return self._dbpool.runInteraction(self._get_items_by_ids, item_ids)
+    def get_items_by_id(self, item_ids):
+        return self._dbpool.runInteraction(self._get_items_by_id, item_ids)
 
-    def _get_items_by_ids(self, cursor, item_ids):
+    def _get_items_by_id(self, cursor, item_ids):
         self._check_node_exists(cursor)
         items = []
         for item_id in item_ids:
@@ -363,13 +361,13 @@
                             item_id.encode('utf8')))
             result = cursor.fetchone()
             if result:
-                items.append(result[0])
+                items.append(unicode(result[0], 'utf8'))
         return items
 
     def purge(self):
         return self._dbpool.runInteraction(self._purge)
 
-    def _purge_node(self, cursor):
+    def _purge(self, cursor):
         self._check_node_exists(cursor)
 
         cursor.execute("""DELETE FROM items WHERE