def findNewSelectIdent(selectid, groupbyid): if (selectid and groupbyid): newIdent = " SELECT "#sqlparse.sql.IdentifierList if(myhelper.checkIfList(selectid)): for sid in selectid: if(myhelper.isAggregate(sid)): newIdent+=str(sid) + " " elif ("(" in str(sid)): newIdent+=str(sid) + ", " elif ("AS" in str(sid)): newIdent+=str(sid) + ", " else: newIdent+=str(sid) + ", " else: newIdent+=str(selectid) + " " if (myhelper.checkIfList(groupbyid)): for gid in groupbyid: if (str(gid) not in newIdent): newIdent+=str(gid) + ", " else: if (str(groupbyid) not in newIdent): newIdent+=str(groupbyid) + ", " newIdent = newIdent.rstrip(", ") (mytok, mytoklen) = tokenizeUserInput (newIdent) myobj = myParser(mytok,mytoklen) return myobj.getSelectIdent() return None
def findStringGroupbyAttributes(queryobj): groupbyAttr = "" if (queryobj is not None): groupbyIdent = queryobj.getGroupbyIdent() if (groupbyIdent is not None): if (myhelper.checkIfList(groupbyIdent)): for gid in groupbyIdent: groupbyAttr+= str(gid) + ", " else: groupbyAttr+= str(groupbyIdent) groupbyAttr = groupbyAttr.strip(", ") return groupbyAttr
def findStringFromAttributes(queryobj): fromAttr = "" fromIdent = queryobj.getFromIdent() if (fromIdent is not None): if (myhelper.checkIfList(fromIdent)): for fid in fromIdent: fromAttr+= str(fid) + ", " else: fromAttr+= str(fromIdent) fromAttr = fromAttr.strip(", ") return fromAttr
def findStringSelectAttributes(queryobj): selectAttr = "" selectIdent = queryobj.getSelectIdent() if (selectIdent is not None): if (myhelper.checkIfList(selectIdent)): for sid in selectIdent: if (myhelper.isAggregate(sid)): selectAttr+=str(sid) selectAttr= selectAttr.strip() elif(myhelper.isMathOperator(sid)): selectAttr = selectAttr.rstrip(", ") selectAttr+=str(sid) selectAttr= selectAttr.strip() else: selectAttr+= str(sid) + ", " selectAttr= selectAttr.strip() else: selectAttr+= str(selectIdent) selectAttr= selectAttr.strip() selectAttr = selectAttr.strip(", ") return selectAttr