/* * TFiveSQL.prg — Main facade class for FiveSql2 engine * * Uses TSqlParser2 (Pratt parser) exclusively. * * FiveSql2 — SQL Engine for Harbour DBF/NTX * * Copyright (c) 2025-2026 Charles KWON (Charles KWON OhJun) * Email: charleskwonohjun@gmail.com * * All rights reserved. */ #include "hbclass.ch" #include "FiveSqlDef.ch" CLASS TFiveSQL DATA oLexer DATA oParser DATA oExec DATA aParams INIT {} METHOD New( aParams ) CONSTRUCTOR METHOD Execute( cSQL ) METHOD ExecuteWith( cSQL, aParams ) ENDCLASS METHOD New( aParams ) CLASS TFiveSQL IF aParams != NIL ::aParams := aParams ENDIF RETURN SELF METHOD Execute( cSQL ) CLASS TFiveSQL LOCAL aTokens, hQuery, aResult /* Parse — no caching (plan trees are mutated during execution) */ ::oLexer := TSqlLexer():New( cSQL ) ::oLexer:Tokenize() aTokens := ::oLexer:GetTokens() ::oParser := TSqlParser2():New( aTokens, ::aParams ) hQuery := ::oParser:Parse() IF hQuery == NIL RETURN { { "__error__" }, { { SQL_ERR_SYNTAX, "Failed to parse SQL", cSQL } } } ENDIF ::oExec := TSqlExecutor():New( hQuery, ::aParams ) aResult := ::oExec:Run() RETURN aResult METHOD ExecuteWith( cSQL, aParams ) CLASS TFiveSQL ::aParams := aParams RETURN ::Execute( cSQL )