Example #1
0
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 findStringOrderbyAttributes(queryobj):
    orderbyAttr = ""
    if(queryobj is not None):
        orderbyIdent = queryobj.getOrderbyIdent()
        if (orderbyIdent is  not None):
            for oid in orderbyIdent:
#                print oid
                if (myhelper.isAggregate(oid)):
#                    print"agg"
                    orderbyAttr+= str(oid)
                elif (myhelper.isOrderbyOperator(oid)):
#                    print "ops"
                    orderbyAttr = orderbyAttr.strip(", ")
                    orderbyAttr+= " " + myhelper.remAggregate(str(oid)) + ", "
                elif(myhelper.isMathOperator(str(oid))):
#                    print "myops %s" %oid
                    orderbyAttr+=str(oid)
                else:
#                    print "else"
                    orderbyAttr+= str(oid) + ", "
    
        orderbyAttr = orderbyAttr.strip("_")
        orderbyAttr = orderbyAttr.strip(", ")
    
#    print "orderbyAttr: %s" %orderbyAttr
    return orderbyAttr
Example #3
0
def findIdentifierListWithKeywords(token,mytoklist):
#    print "I got into findidentifierListWIthKeywords: %s" %token
    foundAttr = False
    curr = token
    foundAggregate = False
#    print "TOken: %s" %token
    if (curr.ttype is None):
        if ("," in str(curr)):
            #After an aggregate is found, the clause is no longer an identifierList.
            commalist = str(curr).split(",")
#            commalist = str(curr).split()
            for  i in commalist:
                i = str(i).strip()
                itemtok = sql.Token(None,i)
                mytoklist.append(itemtok)
#            print commalist
        else:
#        print "Im on the None: %s"%curr
            mytoklist.append(curr)
    elif (curr.ttype is Token.Keyword):
        if (myhelper.isAggregate(curr)):
            mytoklist.append(curr)
            foundAggregate = True
        elif (myhelper.isLogicalOperator(curr)):
            mytoklist.append(curr)
        elif (myhelper.isOrderbyOperator(curr)):
            mytoklist.append(curr)
        else:
            foundAttr = True
    elif (curr.ttype is Token.Punctuation):
        mytoklist.append(curr)
    else:
#        print "Im on the else: %s"%curr
        mytoklist.append(curr)
    return (foundAttr, mytoklist, foundAggregate)
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