From 6adcd221bd2343fb2a4ee2d11ea4b00eb50b46b3 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Wed, 24 Feb 2010 00:46:58 +0000 Subject: [PATCH] Edited license Desktop file in make SQL conversion (probably will be deleted again) git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@219 014f5005-505e-4b48-8d0a-63407b615a7c --- Makefile | 2 +- relational/optimizations.py | 2 +- relational/optimizer.py | 2 +- relational/parallel.py | 2 +- relational/parser.py | 2 +- relational/relation.py | 2 +- relational/sql.py | 149 ++++++++++++++++++++++++++++++----- relational_gui.py | 11 ++- relational_gui/about.py | 2 +- relational_gui/maingui.py | 2 +- relational_gui/surveyForm.py | 2 +- 11 files changed, 148 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 63b4ef8..1534d37 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ debian: chmod a+x data/usr/bin/relational #desktop file mkdir -p data/usr/share/applications/ - cp relational.desktop data/usr/share/applications/ + cp debscript/relational.desktop data/usr/share/applications/ mkdir -p data/DEBIAN #package description debscript/gencontrol.sh > data/DEBIAN/control diff --git a/relational/optimizations.py b/relational/optimizations.py index 2aea0dc..1553b34 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2009 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational/optimizer.py b/relational/optimizer.py index c43420d..825f84d 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -3,7 +3,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational/parallel.py b/relational/parallel.py index 0cf8b16..05d6763 100644 --- a/relational/parallel.py +++ b/relational/parallel.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2009 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational/parser.py b/relational/parser.py index 7fce527..ec4512a 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -3,7 +3,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational/relation.py b/relational/relation.py index 352639e..8a6d3f0 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational/sql.py b/relational/sql.py index 8e9c1b8..63d9822 100644 --- a/relational/sql.py +++ b/relational/sql.py @@ -22,24 +22,6 @@ def stub(): "NATURAL JOIN" "CROSS JOIN" , - -def sql2relational(query): - query=query.replace('\n',' ').replace(',',' , ') - - t=query.split(' ') - escape=False - for i in range(len(t)): - tok=t[i].lower().strip() - if tok=='from' and not escape: - break - - if tok in ('select','as',','): - escape=True - else: - escape=False - - return extract_select(t[1:i]) - def extract_select(query,internal=''): @@ -76,5 +58,134 @@ def extract_select(query,internal=''): return result def extract_from(query): return query + +def sql2relational(query): + query=query.replace('\n',' ').replace(',',' , ') + + tokens=[] + + t=query.split(' ') + escape=False + for i in range(len(t)): + tok=t[i].lower().strip() + if tok=='from' and not escape: + break + + if tok in ('select','as',','): + escape=True + else: + escape=False + + return extract_select(t[1:i]) + + + + + + + + + + + + + + + + +class table(object): + def __init__(self): + self.attr=[] + self.realname=None + pass + + + + + +sqlops=('SELECT','FROM','WHERE',',',';') + +import optimizations + + if __name__=="__main__": - print sql2relational('SELECT a,c AS q FROM from;') \ No newline at end of file + + query="SELECT * FROM a AS b,a WHERE a.id!= b.id and a.age<12 or b.sucation==4 or d=3;" + + query=query.replace(',',' , ').replace(';',' ; ') + print query + parts=query.split(' ') + tokens=[] + + temp='' + lastop=None + for i in parts: + if i in sqlops: + # TODO must tokenize (blabla(bla)) as a single token + if lastop == 'WHERE': #Where is a special case, must tokenize all the stuff + for j in optimizations.tokenize_select(temp): + tokens.append(j.strip()) + else: + tokens.append(temp.strip()) + tokens.append(i.strip()) + temp='' + lastop=i + else: + temp+=i+' ' + + tokens=tokens[1:] #Removes futile 1st empty element + print tokens + + + + rels={} + + from_=[] + where_=[] + select_=[] + + + for i in tokens: + if i in ('SELECT','FROM','WHERE'): + last=i + continue + + + if last=='FROM': + if ' AS ' in i: + parts=i.split(' AS ') + rels[parts[1].strip()]=table() + rels[parts[1].strip()].realname=parts[0].strip() + from_.append(parts[1].strip()) + pass + else: + if i!=',': + rels[i.strip()]=table() + from_.append(i.strip()) + pass + + elif last=='WHERE': + where_.append(i) + if i in optimizations.sel_op: + continue + if '.' in i: + parts=i.split('.',1) + if parts[1] not in rels[parts[0]].attr: + rels[parts[0]].attr.append(parts[1]) + elif last=='SELECT': + # TODO should do like the same of WHERE but supporting AS too + pass + + + + for i in rels.keys(): + print "========" + i + "========" + print rels[i].attr + print rels[i].realname + + print from_ + for i in from_: + if i in rels.keys(): + print i + + #print sql2relational('SELECT a,c AS q FROM from;') \ No newline at end of file diff --git a/relational_gui.py b/relational_gui.py index c71f10c..9c7ba01 100755 --- a/relational_gui.py +++ b/relational_gui.py @@ -4,7 +4,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. @@ -31,7 +31,14 @@ about.version=version if __name__ == "__main__": if len (sys.argv) > 1 and sys.argv[1] == "-v": - print version + + print "Relational" + print "This program comes with ABSOLUTELY NO WARRANTY." + print "This is free software, and you are welcome to redistribute it" + print "under certain conditions." + print "For details see the GPLv3 Licese." + print + print "Version: %s"%version sys.exit(0) try: diff --git a/relational_gui/about.py b/relational_gui/about.py index d1ed387..1bfe875 100644 --- a/relational_gui/about.py +++ b/relational_gui/about.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational_gui/maingui.py b/relational_gui/maingui.py index 60c5121..da23837 100644 --- a/relational_gui/maingui.py +++ b/relational_gui/maingui.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. diff --git a/relational_gui/surveyForm.py b/relational_gui/surveyForm.py index e56a360..1893a25 100644 --- a/relational_gui/surveyForm.py +++ b/relational_gui/surveyForm.py @@ -2,7 +2,7 @@ # Relational # Copyright (C) 2008 Salvo "LtWorf" Tomaselli # -# Relation is free software: you can redistribute it and/or modify +# Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version.