From 4c510df460a41a1e4c5d1f321c5402b4f143da34 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 27 Jan 2009 12:12:44 +0000 Subject: [PATCH] stub insert git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@78 014f5005-505e-4b48-8d0a-63407b615a7c --- relation.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/relation.py b/relation.py index 6c556e6..9239dc1 100644 --- a/relation.py +++ b/relation.py @@ -448,6 +448,32 @@ class relation (object): for k in range(len(keys)): i[f_ids[k]]=str(dic[keys[k]]) return affected + def insert(self,values): + '''Inserts the values in the relation. If values[0] is not a list | tuple, + values will be inserted as a tuple. Otherwise values will be considered as a + table containing many tuples that will be inserted. + This function will not insert duplicate tuples. + All the values will be converted in string. + Will return the number of inserted rows.''' + affected=0 + l=len(self.header.attributes) + if str(values[0].__class__) == "" or str(values[0].__class__) == "": + for i in values: + if l==len(i) and i not in self.content: + affected+=1 + t=[] + for q in i: + t.append(str(i)) + self.content.append(t) + else: + if len(values)== l and values not in self.content: + t=[] + for q in values: + t.append(str(q)) + self.content.append(t) + return 1 + return affected + def delete(self,expr): '''Delete, expr must be a valid boolean expression, can contain field names, constant, math operations and boolean ones.