#include "FiveSqlDef.ch" #include "hbclass.ch" FUNCTION Main() LOCAL oSql, oLexer, oParser, aTokens, hQuery, oExec dbCreate("dbg_test", { {"ID","N",4,0}, {"NAME","C",20,0} }) USE "dbg_test" NEW EXCLUSIVE APPEND BLANK REPLACE ID WITH 1, NAME WITH "Alice" APPEND BLANK REPLACE ID WITH 2, NAME WITH "Bob" CLOSE ALL oLexer := TSqlLexer():New("SELECT * FROM dbg_test") oLexer:Tokenize() aTokens := oLexer:GetTokens() oParser := TSqlParser2():New(aTokens, {}) hQuery := oParser:Parse() oExec := TSqlExecutor():New(hQuery, {}) // Manually trace RunSelect steps ? "hQuery type:", hQuery["type"] ? "tables:", Len(hQuery["tables"]) ? "tables[1]:", ValType(hQuery["tables"][1]) IF ValType(hQuery["tables"][1]) == "A" ? " table name:", hQuery["tables"][1][1] ? " table alias:", hQuery["tables"][1][2] ENDIF // Trace the executor's OpenTable ? "aTables:", ValType(oExec:aTables) ? "oExec:hQuery:", ValType(oExec:hQuery) // Set aTables like RunSelect does oExec:aTables := hQuery["tables"] ? "aTables set, len:", Len(oExec:aTables) // Try opening table LOCAL cTable, cAlias, nWA cTable := oExec:aTables[1][1] ? "cTable:", cTable BEGIN SEQUENCE nWA := oExec:OpenTable(cTable, "") ? "OpenTable returned:", nWA RECOVER ? "OpenTable exception" END SEQUENCE // Try manual scan IF nWA != NIL .AND. nWA > 0 dbSelectArea(nWA) ? "FCount:", FCount() dbGoTop() ? "EOF:", Eof() DO WHILE !Eof() ? " Row:", FieldGet(1), FieldGet(2) dbSkip() ENDDO ENDIF oExec:CloseOpened() FErase("dbg_test.dbf") ? "DONE" RETURN NIL