From: Tony Mack <tmack@cs.princeton.edu>
Date: Fri, 1 Dec 2006 16:37:15 +0000 (+0000)
Subject: - modified insert_new_item to support multiple value insert in single sql statement
X-Git-Tag: pycurl-7_13_1~215
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=82e65a34b0c16a2079c5d0e846665d5a35dca51c;p=plcapi.git

- modified insert_new_item to support multiple value insert in single sql statement
---

diff --git a/PLC/Cache.py b/PLC/Cache.py
index 535aab46..e9495991 100644
--- a/PLC/Cache.py
+++ b/PLC/Cache.py
@@ -92,12 +92,12 @@ class Cache:
 		self.api.db.do (sql)
 
 	def insert_new_items (self, id1, id2_set):
-        ### xxx needs to be optimized
-        ### tried to figure a way to use a single sql statement
-        ### like: insert into table (x,y) values (1,2),(3,4);
-        ### but apparently this is not supported under postgresql
-	    for id2 in id2_set:
-		sql = "INSERT INTO %s VALUES (%d,%d)"%(self.tablename,id1,id2)
+	    if id2_set:
+		sql = "INSERT INTO %s select %d, %d " % \
+   			self.tablename, id1, id2[0] 
+	    	for id2 in id2_set[1:]:
+			sql += " UNION ALL SELECT %d, %d " % \
+			(id1,id2)
 		self.api.db.do (sql)
 
 	def update_item (self, id1, old_id2s, new_id2s):