def test_simple(self):
     refList = ("dual", "emp")
     for tables, line in ((["dual", ], "select * from dual"),
                          (["dual", ], "select * from dual;"),
                          (["dual", ], "select * from dual d"),
                          (["dual", ], "select * from (select * from dual)"),
                          (["dual", "emp"], "select * from dual, emp"),
                          (["dual", "emp"], "select * from dual d, emp"),
                          (["dual", ], "select * from dual where dummy='X'"),
                          (["dual", ], "select * from dual order by 1"),
                          (["dual", ], "select dummy, count(1) from dual group by dummy"),):
         result = pysqlhelpers.getKnownTablesViews(line, refList)
         result.sort()
         self.failUnlessEqual(tables, result)
Exemple #2
0
def completeColumns(db, line, text, refList):
    """Find columns list to complete on
    @param line: line of sql text
    @param text: word we are currently completing
    @param refList: list of known tables/views/synonym of the current schema
    @return: list of columns (unicode)"""
    # Try to find tables/views name
    tables = pysqlhelpers.getKnownTablesViews(line.upper(), refList)
    columns = []
    for table in tables:
        oraObject = OraObject(objectName=table)
        oraObject.guessInfos(db)
        if oraObject is None:
            continue
        if oraObject.getType() == "SYNONYM":
            oraObject = oraObject.getTarget(db)
        columns.extend([i[0] for i in oraObject.getTableColumns(db)])

    # TODO: filter on proper table
    return [c for c in columns if c.startswith(text.upper())]