From 3ca26b10c6207602e6117c28f7dac078b72d277c Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 1 Apr 2011 07:06:08 +0000 Subject: [PATCH] - Forces relations to have correct attribute names git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@296 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational/relation.py | 8 ++++++++ relational_gui/guihandler.py | 16 ++++++++++++---- relational_readline/linegui.py | 13 +++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a6c1e34..9066b92 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/relational/relation.py b/relational/relation.py index 4ebb77e..11b075a 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -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 diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 17fc683..4debaa4 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -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''' diff --git a/relational_readline/linegui.py b/relational_readline/linegui.py index e9dee58..41a63aa 100644 --- a/relational_readline/linegui.py +++ b/relational_readline/linegui.py @@ -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() \ No newline at end of file