added insert method, can be used to add one touple per time into a relation and does integrity check (just prevents inserting duplicated entries)
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@80 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
907d95268b
commit
8d0830fd6b
36
relation.py
36
relation.py
@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Relational
|
# Relational
|
||||||
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
|
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
|
||||||
#
|
#
|
||||||
@ -449,30 +450,25 @@ class relation (object):
|
|||||||
i[f_ids[k]]=str(dic[keys[k]])
|
i[f_ids[k]]=str(dic[keys[k]])
|
||||||
return affected
|
return affected
|
||||||
def insert(self,values):
|
def insert(self,values):
|
||||||
'''Inserts the values in the relation. If values[0] is not a list | tuple,
|
'''Inserts a touple in the relation.
|
||||||
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.
|
This function will not insert duplicate tuples.
|
||||||
All the values will be converted in string.
|
All the values will be converted in string.
|
||||||
Will return the number of inserted rows.'''
|
Will return the number of inserted rows.'''
|
||||||
affected=0
|
|
||||||
l=len(self.header.attributes)
|
#Returns if touple doesn't fit the number of attributes
|
||||||
if str(values[0].__class__) == "<type 'tuple'>" or str(values[0].__class__) == "<type 'list'>":
|
if len(self.header.attributes) != len(values):
|
||||||
for i in values:
|
return 0
|
||||||
if l==len(i) and i not in self.content:
|
|
||||||
affected+=1
|
#Creating list containing only strings
|
||||||
t=[]
|
t=[]
|
||||||
for q in i:
|
for i in values:
|
||||||
t.append(str(i))
|
t.append(str(i))
|
||||||
self.content.append(t)
|
|
||||||
|
if t not in self.content:
|
||||||
|
self.content.append(t)
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
if len(values)== l and values not in self.content:
|
return 0
|
||||||
t=[]
|
|
||||||
for q in values:
|
|
||||||
t.append(str(q))
|
|
||||||
self.content.append(t)
|
|
||||||
return 1
|
|
||||||
return affected
|
|
||||||
|
|
||||||
def delete(self,expr):
|
def delete(self,expr):
|
||||||
'''Delete, expr must be a valid boolean expression, can contain field names,
|
'''Delete, expr must be a valid boolean expression, can contain field names,
|
||||||
|
Loading…
Reference in New Issue
Block a user