diff --git a/CHANGELOG b/CHANGELOG index 715bb93..d8bae9a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ - Parsing of strings representing dates is now cached, eliminating the need for double parse - Restyle of the GUI - Adds history in the GUI +- Checks if given name to relations are valid 0.11 - Font is set only on windows (Rev 206) diff --git a/relational/rtypes.py b/relational/rtypes.py index f1cd07e..d3207fe 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -109,3 +109,11 @@ class rdate (object): def __sub__ (self,other): return (self.intdate-other.intdate).days + +def is_valid_relation_name(name): + '''Checks if a name is valid for a relation. + Returns boolean''' + if re.match(r'^[_a-zA-Z]+[_a-zA-Z0-9]*$',name)==None: + return False + else: + return True \ No newline at end of file diff --git a/relational_gui.py b/relational_gui.py index 98ca7b3..b771efa 100755 --- a/relational_gui.py +++ b/relational_gui.py @@ -83,7 +83,13 @@ if __name__ == "__main__": if x11: import sip from PyQt4 import QtCore, QtGui - from relational_gui import maingui,guihandler, about, surveyForm + + try: + from relational_gui import maingui,guihandler, about, surveyForm + except: + print >> sys.stderr, "Module relational_gui is missing.\nPlease install relational package." + sys.exit(3) + about.version=version surveyForm.version=version @@ -113,6 +119,10 @@ if __name__ == "__main__": sys.exit(app.exec_()) else: printver(False) - import relational_readline.linegui + try: + import relational_readline.linegui + except: + print >> sys.stderr, "Module relational_readline is missing.\nPlease install relational-cli package." + sys.exit(3) relational_readline.linegui.main(files) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 817ee98..36492c7 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -17,7 +17,7 @@ # # author Salvo "LtWorf" Tomaselli from PyQt4 import QtCore, QtGui -from relational import relation, parser, optimizer +from relational import relation, parser, optimizer,rtypes import sys import about @@ -53,7 +53,6 @@ class relForm(QtGui.QMainWindow): result=optimizer.optimize_all(str(self.ui.txtQuery.text().toUtf8()),self.relations) self.ui.txtQuery.setText(QtCore.QString.fromUtf8(result)) - #self.txtQuery.setText(result) def resumeHistory(self,item): itm=str(item.text().toUtf8()).split(' = ',1) self.ui.txtResult.setText(QtCore.QString.fromUtf8(itm[0])) @@ -65,10 +64,11 @@ class relForm(QtGui.QMainWindow): query=str(self.ui.txtQuery.text().toUtf8()) res_rel=str(self.ui.txtResult.text())#result relation's name - if len(res_rel)==0: #If no name is set use the default last_ - QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Missing destination relation.")) + + if not rtypes.is_valid_relation_name(res_rel): + QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Wrong name for destination relation.")) return - + try: #Converting string to utf8 and then from qstring to normal string expr=parser.parse(query)#Converting expression to python code @@ -172,11 +172,10 @@ class relForm(QtGui.QMainWindow): #Default relation's name f=str(filename.toUtf8()).split('/') #Split the full path - defname=f[len(f)-1].lower() #Takes only the lowercase filename - else: f=filename.split('/') #Split the full path - defname=f[len(f)-1].lower() #Takes only the lowercase filename + + defname=f[len(f)-1].lower() #Takes only the lowercase filename if len(defname)==0: return @@ -191,11 +190,14 @@ class relForm(QtGui.QMainWindow): return #Patch provided by Angelo 'Havoc' Puglisi - self.relations[str(res[0].toUtf8())]=relation.relation(str(filename.toUtf8())) - else: #name was decided by caller + name=str(res[0].toUtf8()) + filename=str(filename.toUtf8()) + + if rtypes.is_valid_relation_name(name): self.relations[name]=relation.relation(filename) - - self.updateRelations() + self.updateRelations() + else: + QtGui.QMessageBox.information(self,QtGui.QApplication.translate("Form", "Error"),QtGui.QApplication.translate("Form", "Wrong name for destination relation: %s." % name)) def insertTuple(self): '''Shows an input dialog and inserts the inserted tuple into the selected relation''' res=QtGui.QInputDialog.getText(self, QtGui.QApplication.translate("Form", "New relation"),QtGui.QApplication.translate("Form", "Insert the values, comma separated"), @@ -253,16 +255,4 @@ class relForm(QtGui.QMainWindow): def addSymbolInQuery(self,symbol): self.ui.txtQuery.insert(symbol) self.ui.txtQuery.setFocus() - -def q_main(): - import sys - app = QtGui.QApplication(sys.argv) - Form = RelForm() - ui = maingui.Ui_MainWindow() - ui.setupUi(Form) - Form.setupUi(ui) - Form.show() - sys.exit(app.exec_()) - -if __name__ == "__main__": - q_main() \ No newline at end of file + \ No newline at end of file diff --git a/relational_readline/linegui.py b/relational_readline/linegui.py index 097e826..e9dee58 100644 --- a/relational_readline/linegui.py +++ b/relational_readline/linegui.py @@ -25,7 +25,7 @@ import os.path import os import sys -from relational import relation, parser, optimizer +from relational import relation, parser, rtypes class SimpleCompleter(object): '''Handles completion''' @@ -103,7 +103,10 @@ def load_relation(filename,defname=None): defname=f[len(f)-1].lower() if defname.endswith(".csv"): #removes the extension defname=defname[:-4] - + + if not rtypes.is_valid_relation_name(defname): + print >> sys.stderr, "%s is not a valid relation name" % defname + return try: relations[defname]=relation.relation(filename) @@ -234,18 +237,9 @@ def exec_query(command): #Finds the name in where to save the query parts=command.split('=',1) - if len(parts)>1: - assignment=True - for i in parser.op_functions: - if i in parts[0]: - #If we are here, there is no explicit assignment - assignment=False - if assignment: - relname=parts[0] - query=parts[1] - else: - relname='last_' - query=command + if len(parts)>1 and rtypes.is_valid_relation_name(parts[0]): + relname=parts[0] + query=parts[1] else: relname='last_' query=command