Optimized saving of relations

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@51 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2008-11-06 22:25:12 +07:00
parent 278036081f
commit 863289d29c
3 changed files with 17 additions and 17 deletions

@ -40,3 +40,4 @@
- Expressions between quotes aren't parsed anymore
- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename
- Changed internal rename method. Now uses a dictionary
- Optimized saving of relations

@ -31,39 +31,41 @@ class Ui_Form(object):
try:
#Converting string to utf8 and then from qstring to normal string
query=str(self.txtQuery.text().toUtf8())
expr=parser.parse(query)
print query,"-->" , expr
result=eval(expr,self.relations)
expr=parser.parse(query)#Converting expression to python code
print query,"-->" , expr #Printing debug
result=eval(expr,self.relations) #Evaluating the expression
res_rel=str(self.txtResult.text())#result relation's name
self.txtResult.setText("")
if len(res_rel)==0:
self.txtResult.setText("") #Sets the result relation name to none
if len(res_rel)==0: #If no name is set use the default last_
res_rel="last_"
self.relations[res_rel]=result
self.updateRelations()
self.relations[res_rel]=result #Add the relation to the dictionary
self.updateRelations() #update the list
self.showRelation(result)
self.showRelation(result) #Show the result in the table
except:
QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Check your query!") )
def showRelation(self,rel):
self.table.clear()
if rel==None:
if rel==None: #No relation to show
self.table.setColumnCount(1)
self.table.headerItem().setText(0,"Empty relation")
return
self.table.setColumnCount(len(rel.header.attributes))
#Set content
for i in rel.content:
item = QtGui.QTreeWidgetItem()
for j in range(len(i)):
item.setText(j, i[j])
self.table.addTopLevelItem(item)
#Sets columns
for i in range(len(rel.header.attributes)):
self.table.headerItem().setText(i,rel.header.attributes[i])
self.table.resizeColumnToContents(i)
self.table.resizeColumnToContents(i) #Must be done in order to avoid too small columns
def printRelation(self,*rel):

@ -45,14 +45,11 @@ class relation (object):
def save(self,filename):
'''Saves the relation in a file'''
res=""
for f in self.header.attributes:
res+="%s "%(f)
res+=" ".join(self.header.attributes)
for r in self.content:
res+="\n"
for i in r:
res+="%s "% (i)
res+=" ".join(r)
fp=file(filename,'w')
fp.write(res)
fp.close()