- Forces relations to have correct attribute names

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@296 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2011-04-01 07:06:08 +07:00
parent dfb3f19acf
commit 3ca26b10c6
4 changed files with 34 additions and 4 deletions

@ -1,5 +1,6 @@
1.1
- Incorrect relational operations now raise an exception instead of returning None
- Forces relations to have correct names for attributes
1.0
- Adds history in the GUI

@ -512,6 +512,10 @@ class header (object):
'''Accepts a list with attributes' names. Names MUST be unique'''
self.attributes=attributes
for i in attributes:
if not is_valid_relation_name(i):
raise Exception('"%s" is not a valid attribute name'% i)
def __repr__(self):
return "header(%s)" % (self.attributes.__repr__())
@ -519,6 +523,10 @@ class header (object):
def rename(self,old,new):
'''Renames a field. Doesn't check if it is a duplicate.
Returns True if the field was renamed, False otherwise'''
if not is_valid_relation_name(new):
raise Exception('%s is not a valid attribute name'% new)
try:
id_=self.attributes.index(old)
self.attributes[id_]=new

@ -190,11 +190,19 @@ class relForm(QtGui.QMainWindow):
#Patch provided by Angelo 'Havoc' Puglisi
name=str(res[0].toUtf8())
if rtypes.is_valid_relation_name(name):
self.relations[name]=relation.relation(filename)
self.updateRelations()
else:
if not rtypes.is_valid_relation_name(name):
QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Wrong name for destination relation: %s." % name))
return
try:
self.relations[name]=relation.relation(filename)
except Exception, e:
print e
QtGui.QMessageBox.information(None,QtGui.QApplication.translate("Form", "Error"),"%s\n%s" % (QtGui.QApplication.translate("Form", "Check your query!"),e.__str__()) )
return
self.updateRelations()
def insertTuple(self):
'''Shows an input dialog and inserts the inserted tuple into the selected relation'''

@ -24,6 +24,7 @@ import logging
import os.path
import os
import sys
import curses
from relational import relation, parser, rtypes
@ -261,6 +262,17 @@ def exec_query(command):
print e
def main(files=[]):
import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()
print curses.can_change_color()
curses.color_pair(curses.A_BOLD)
print "> ; Type HELP to get the HELP"
print "> ; Completion is activated using the tab (if supported by the terminal)"
@ -285,4 +297,5 @@ def main(files=[]):
if __name__ == "__main__":
main()