// Borland C++ Builder
// Copyright (c) 1995, 2005 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'Sqltxtrtns.pas' rev: 10.00

#ifndef SqltxtrtnsHPP
#define SqltxtrtnsHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member functions
#pragma pack(push,8)
#include <System.hpp>	// Pascal unit
#include <Sysinit.hpp>	// Pascal unit
#include <Sysutils.hpp>	// Pascal unit
#include <Classes.hpp>	// Pascal unit
#include <Strutil.hpp>	// Pascal unit
#include <Windows.hpp>	// Pascal unit
#include <Variants.hpp>	// Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Sqltxtrtns
{
//-- type declarations -------------------------------------------------------
#pragma option push -b-
enum TSQLKind { skUnknown, skSelect, skUpdate, skInsert, skDelete, skExecuteProc, skDDL, skExecuteBlock };
#pragma option pop

#pragma option push -b-
enum TParserState { sNormal, sQuote, sComment, sFBComment, sQuoteSingle };
#pragma option pop

typedef void __fastcall (__closure *TOnScanSQLText)(int Position, bool &StopScan);

typedef Set<char, 0, 255>  TChars;

#pragma option push -b-
enum TSQLSection { stUnknown, stSelect, stFields, stUpdate, stInsert, stDelete, stExecute, stSet, stComment, stFrom, stWhere, stGroupBy, stHaving, stUnion, stPlan, stOrderBy, stForUpdate };
#pragma option pop

typedef DynamicArray<TSQLSection >  TSQLSections;

class DELPHICLASS TSQLParser;
class PASCALIMPLEMENTATION TSQLParser : public System::TObject 
{
	typedef System::TObject inherited;
	
private:
	TParserState FState;
	int FCurPos;
	int FResultPos;
	int FBracketOpened;
	AnsiString FSQLText;
	int FLen;
	int FReserved;
	int FReserved1;
	bool FScanInBrackets;
	int FFirstPos;
	TSQLKind FSQLKind;
	bool FCanParamsCheck;
	Classes::TStrings* FTables;
	int FBracketOpenedBeforeScan;
	void __fastcall SetSQLText(const AnsiString Value);
	bool __fastcall IsClause(int Position, const AnsiString Clause);
	TSQLKind __fastcall GetSQLKind(void);
	
protected:
	void __fastcall IsOrderBegin(int Position, bool &Yes);
	void __fastcall IsGroupBegin(int Position, bool &Yes);
	void __fastcall IsByBegin(int Position, bool &Yes);
	void __fastcall IsHaving(int Position, bool &Yes);
	void __fastcall IsMainOrderBegin(int Position, bool &Yes);
	void __fastcall IsMainGroupBegin(int Position, bool &Yes);
	void __fastcall IsFromBegin(int Position, bool &Yes);
	void __fastcall IsWhereBegin(int Position, bool &Yes);
	void __fastcall IsWhereEnd(int Position, bool &Yes);
	void __fastcall IsMainWhereBegin(int Position, bool &Yes);
	void __fastcall IsMainFromBegin(int Position, bool &Yes);
	void __fastcall IsFromEnd(int Position, bool &Yes);
	void __fastcall IsPlanBegin(int Position, bool &Yes);
	void __fastcall IsPlanEnd(int Position, bool &Yes);
	void __fastcall IsSetBegin(int Position, bool &Yes);
	void __fastcall IsIntoBegin(int Position, bool &Yes);
	void __fastcall IsUpdateBegin(int Position, bool &Yes);
	bool __fastcall IsSelect(int Position);
	bool __fastcall IsUpdate(int Position);
	bool __fastcall IsDelete(int Position);
	bool __fastcall IsInsert(int Position);
	bool __fastcall IsExecute(int Position);
	bool __fastcall IsExecuteProc(int Position);
	bool __fastcall IsExecuteBlock(int Position);
	bool __fastcall IsDDL(void);
	void __fastcall FillMainTables(bool WithSP = false);
	
public:
	__fastcall TSQLParser(void)/* overload */;
	__fastcall TSQLParser(const AnsiString aSQLText)/* overload */;
	__fastcall virtual ~TSQLParser(void);
	void __fastcall ScanText(int FromPosition, TOnScanSQLText Proc);
	TSQLSections __fastcall PosInSections(int Position)/* overload */;
	TSQLSections __fastcall PosInSections(int ScanFrom, int Position, int &EndScan)/* overload */;
	Types::TPoint __fastcall DispositionMainFrom();
	AnsiString __fastcall MainFrom();
	AnsiString __fastcall ModifiedTables();
	AnsiString __fastcall OrderText(int &StartPos, int &EndPos);
	AnsiString __fastcall OrderClause();
	AnsiString __fastcall SetOrderClause(const AnsiString Value);
	Variant __fastcall GetOrderInfo();
	AnsiString __fastcall GroupByText(int &StartPos, int &EndPos);
	AnsiString __fastcall GroupByClause();
	AnsiString __fastcall SetGroupClause(const AnsiString Value);
	AnsiString __fastcall GetFieldsClause();
	AnsiString __fastcall SetFieldsClause(const AnsiString NewFields);
	AnsiString __fastcall WhereClause(int N, int &StartPos, int &EndPos);
	AnsiString __fastcall SetWhereClause(int N, const AnsiString Value);
	AnsiString __fastcall SetMainWhereClause(const AnsiString Value);
	AnsiString __fastcall MainWhereClause(int &StartPos, int &EndPos);
	int __fastcall WhereCount(void);
	int __fastcall MainWhereIndex(void);
	AnsiString __fastcall AddToMainWhere(const AnsiString NewClause, bool ForceCLRF = true);
	int __fastcall PlanCount(void);
	AnsiString __fastcall PlanText(int N, int &StartPos, int &EndPos);
	int __fastcall MainPlanIndex(void);
	AnsiString __fastcall MainPlanText(int &StartPos, int &EndPos);
	AnsiString __fastcall SetMainPlan(const AnsiString Text);
	AnsiString __fastcall GetMainPlan();
	AnsiString __fastcall RecCountSQLText();
	Classes::TStrings* __fastcall GetAllTables(bool WithSP = false);
	__property AnsiString SQLText = {read=FSQLText, write=SetSQLText};
	__property int Len = {read=FLen, write=FLen, nodefault};
	__property int FirstPos = {read=FFirstPos, nodefault};
	__property AnsiString MainPlanClause = {read=GetMainPlan};
	__property TSQLKind SQLKind = {read=FSQLKind, nodefault};
	__property bool CanParamsCheck = {read=FCanParamsCheck, nodefault};
};


typedef AnsiString SqlTxtRtns__2[61];

//-- var, const, procedure ---------------------------------------------------
#define SpaceStr "    "
#define ForceNewStr "\r\n    "
static const char QuotMarks = '\x27';
#define CharsAfterClause (Set<char, 0, 255> () << '\x0' << '\x9' << '\xa' << '\xd' << '\x20' << '\x29' << '\x2a' << '\x2d' )
#define CharsBeforeClause (Set<char, 0, 255> () << '\x9' << '\xa' << '\xd' << '\x20' << '\x29' << '\x2a' << '\x2d' )
#define endLexem (Set<char, 0, 255> () << '\x21' << '\x28' << '\x29' << '\x2a' << '\x2b' << '\x2c' << '\x2d' << '\x2f' << '\x3b' << '\x3c' << '\x3d' << '\x3e' << '\x41' << '\x48' << '\x49' << '\x4a' << '\x4b' << '\x4c' << '\x4d' << '\x4f' << '\x5b' << '\x5c' << '\x5d' << '\x5e' << '\x61' << '\x68' << '\x69' << '\x6a' << '\x6b' << '\x6c' << '\x6d' << '\x6f' << '\x7b' << '\x7c' << '\x7d' << '\x7e' )
static const Shortint IBStdCharSetsCount = 0x3d;
static const Byte IBStdCollationsCount = 0x88;
#define UnknownStr "UNKNOWN"
extern PACKAGE AnsiString IBStdCharacterSets[61];
#define BeginWhere " WHERE "
extern PACKAGE AnsiString __fastcall ParseMacroString(const AnsiString MacroString, char aMacroChar, AnsiString &DefValue);
extern PACKAGE int __fastcall PosClause(const AnsiString Clause, const AnsiString SQLText);
extern PACKAGE bool __fastcall IsEquelSQLNames(const AnsiString Name1, const AnsiString Name2);
extern PACKAGE Types::TPoint __fastcall DispositionFrom(const AnsiString SQLText);
extern PACKAGE AnsiString __fastcall CountSelect(const AnsiString SrcSQL);
extern PACKAGE AnsiString __fastcall FieldsClause(const AnsiString SrcSQL);
extern PACKAGE AnsiString __fastcall GetModifyTable(const AnsiString SQLText, bool WithAlias = false);
extern PACKAGE int __fastcall PosAlias(const AnsiString SQLString);
extern PACKAGE AnsiString __fastcall FieldNameForSQL(const AnsiString TableAlias, const AnsiString FieldName);
extern PACKAGE AnsiString __fastcall CutTableName(const AnsiString SQLString, int AliasPosition = 0x0);
extern PACKAGE AnsiString __fastcall CutAlias(const AnsiString SQLString, int AliasPosition = 0x0);
extern PACKAGE void __fastcall AllTables(const AnsiString SQLText, Classes::TStrings* aTables, bool WithSP = false, bool WithAliases = false);
extern PACKAGE void __fastcall AllSQLTables(AnsiString SQLText, Classes::TStrings* aTables, bool WithSP = false, bool WithAliases = false);
extern PACKAGE AnsiString __fastcall AliasForTable(const AnsiString SQLText, const AnsiString TableName);
extern PACKAGE AnsiString __fastcall TableByAlias(const AnsiString SQLText, const AnsiString Alias);
extern PACKAGE AnsiString __fastcall FullFieldName(const AnsiString SQLText, const AnsiString aFieldName);
extern PACKAGE AnsiString __fastcall FieldNameFromSelect(const AnsiString SQLText, const AnsiString FieldName);
extern PACKAGE int __fastcall MainWhereIndex(const AnsiString SQLText);
extern PACKAGE AnsiString __fastcall MainFrom(const AnsiString SQLText);
extern PACKAGE AnsiString __fastcall MainWhereClause(const AnsiString SQLText);
extern PACKAGE int __fastcall WhereCount(AnsiString SQLText);
extern PACKAGE AnsiString __fastcall OrderStringTxt(const AnsiString SQLText, int &StartPos, int &EndPos);
extern PACKAGE TSQLKind __fastcall GetSQLKind(const AnsiString SQLText);
extern PACKAGE Variant __fastcall GetOrderInfo(const AnsiString SQLText);
extern PACKAGE void __fastcall SetOrderString(Classes::TStrings* SQLText, const AnsiString OrderTxt);
extern PACKAGE AnsiString __fastcall SetOrderClause(const AnsiString SQLText, const AnsiString NewClause);
extern PACKAGE AnsiString __fastcall GetWhereClause(const AnsiString SQLText, int N, int &StartPos, int &EndPos);
extern PACKAGE AnsiString __fastcall AddToWhereClause(const AnsiString SQLText, const AnsiString NewClause, bool ForceCLRF = true);
extern PACKAGE AnsiString __fastcall PrepareConstraint(Classes::TStrings* Src);
extern PACKAGE AnsiString __fastcall GetFieldByAlias(const AnsiString SQLText, const AnsiString FieldName);
extern PACKAGE AnsiString __fastcall GetLinkFieldName(const AnsiString SQLText, const AnsiString ParamName);
extern PACKAGE bool __fastcall IsWhereBeginPos(const AnsiString SQLText, int Position);
extern PACKAGE bool __fastcall IsWhereEndPos(const AnsiString SQLText, int Position);
extern PACKAGE TSQLSections __fastcall PosInSections(const AnsiString SQLText, int Position);
extern PACKAGE AnsiString __fastcall InvertOrderClause(const AnsiString OrderText);

}	/* namespace Sqltxtrtns */
using namespace Sqltxtrtns;
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// Sqltxtrtns
