📄 myldbsqlprocessor.pas
字号:
destructor Destroy; override;
// adds new node to the tree
procedure AddNode(NewType: TMYLDBQueryExprType; RightNode: TMYLDBQueryExprNode;
bAll, bCorresponding: Boolean; ColumnList: TStringList=nil);
function AllConditionsApplied: Boolean;
// check that there is no INTO clause
function HasInto: Boolean;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSQLUnion
// UNION SQL command
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBSQLUnion = class (TMYLDBSQLCursorCommand)
protected
FRootNode: TMYLDBQueryExprNode; // root node in unions,excepts tree
// parses [ALL]
function ParseAll: Boolean;
// parses [ <corresponding spec> ]
function ParseCorrespondingSpec(var ColumnsList: TStringList): Boolean;
// parses SELECT ...
function ParseQuerySpecification: TMYLDBQueryExprNode;
// parses <query specification> | <table value constructor> | <explicit table>
function ParseSimpleTable: TMYLDBQueryExprNode;
// parses <simple table> |
// <left paren> <non-join query expression> <right paren>
function ParseNonJoinQueryPrimary: TMYLDBQueryExprNode;
// parses <non-join query primary> |
// <query term> INTERSECT [ ALL ] [ <corresponding spec> ] <query primary>
function ParseNonJoinQueryTerm: TMYLDBQueryExprNode;
// parses <non-join query term> |
// <query expression> UNION [ ALL ] [ <corresponding spec> ] <query term> |
// <query expression> EXCEPT [ ALL ] [ <corresponding spec> ] <query term>
function ParseNonJoinQueryExpression: TMYLDBQueryExprNode;
// parses <non-join query expression> | <joined table>
function ParseQueryExpression: TMYLDBQueryExprNode;
// builds AO
function BuildAO(Node: TMYLDBQueryExprNode; RequestLive: Boolean; ParentQueryAO: TMYLDBAO;
ParentCursor: TMYLDBCursor; AllowNotAppliedConditions: Boolean): TMYLDBAO;
public
// creates object
constructor Create(Lexer: TMYLDBLexer; Query: TDataSet);
// destroys object
destructor Destroy; override;
// parses query
procedure Parse; override;
// check if correlated subquery apllied
function AllConditionsApplied: Boolean; override;
// builds AO tree
function BuildAOTree(query: TDataset; RequestLive: Boolean; ParentQueryAO: TMYLDBAO;
ParentCursor: TMYLDBCursor; AllowNotAppliedConditions: Boolean): TMYLDBAO; override;
end;//TMYLDBSQLUnion
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSQLInsert
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBSQLInsert = class (TMYLDBSQLCommand)
protected
TableName: string; // Table Name
DatabaseFileName: string;
Password: string; // table password
FieldNames: TStringList;
FieldValues: array of TList;
InternalSelecter: TMYLDBSQLSelect;
protected
procedure ParseValuesList;
public
// creates object
constructor Create(Lexer: TMYLDBLexer; Query: TDataSet);
// destroys object
destructor Destroy; override;
// parses query
procedure Parse; override;
// executes query
procedure ExecSQL(
query: TDataset;
IsRoot,
RequestLive: boolean;
var ReadOnly: boolean;
ParentQueryAO: TMYLDBAO = nil;
ParentCursor: TMYLDBCursor = nil
); override;
end;//TMYLDBSQLInsert
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSQLUpdate
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBSQLUpdate = class (TMYLDBSQLCommand)
protected
DatabaseFileName: String; // DB Name
TableName: string; // Table Name
Password: string; // table password
FieldNames: TStringList;
FieldValues: TList;
IsFieldValuesSubquery: Boolean;
FieldValuesSubqueryExpr: TMYLDBExpression;
InternalSelecter: TMYLDBSQLSelect;
FSelectLexer: TMYLDBLexer;
FTablePseudonym: String;
public
// creates object
constructor Create(Lexer: TMYLDBLexer; Query: TDataSet);
// destroys object
destructor Destroy; override;
// parses query
procedure Parse; override;
// executes query
procedure ExecSQL(
query: TDataset;
IsRoot,
RequestLive: boolean;
var ReadOnly: boolean;
ParentQueryAO: TMYLDBAO = nil;
ParentCursor: TMYLDBCursor = nil
); override;
end;//TMYLDBSQLUpdate
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBSQLDelete
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBSQLDelete = class (TMYLDBSQLCommand)
protected
InternalSelecter: TMYLDBSQLSelect;
TableName: string; // Table Name
FullDelete: boolean;
public
// creates object
constructor Create(Lexer: TMYLDBLexer; Query: TDataSet);
// destroys object
destructor Destroy; override;
// parses query
procedure Parse; override;
// executes query
procedure ExecSQL(
query: TDataset;
IsRoot,
RequestLive: boolean;
var ReadOnly: boolean;
ParentQueryAO: TMYLDBAO = nil;
ParentCursor: TMYLDBCursor = nil
); override;
end;//TMYLDBSQLDelete
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBDDLTableManipulation
//
////////////////////////////////////////////////////////////////////////////////
// FieldDef element
TSQLFieldDef = class (TObject)
public
FieldName: String; // field name or pseudonym
CreateIfNotExists: Boolean;
// FieldType
newFieldType: Boolean;
FieldType: TMYLDBAdvancedFieldType;
// field length ex: String(255)
newLength: Boolean;
Length: Integer;
// is Requared field (NOT NULL)
newRequired: Boolean;
Required: Boolean;
// Autoinc settings
newAutoincIncrement: Boolean;
AutoincIncrement: Int64;
newAutoincLastValue: Boolean;
AutoincLastValue: Int64;
newAutoincMinValue: Boolean;
AutoincMinValue: Int64;
newAutoincMaxValue: Boolean;
AutoincMaxValue: Int64;
newAutoincCycled: Boolean;
AutoincCycled: Boolean;
// Blob settings
newBlobBlockSize: Boolean;
BlobBlockSize: Integer; // 1..
newBlobCompressionAlgorithm: Boolean;
BlobCompressionAlgorithm: TMYLDBCompressionAlgorithm;// {NONE | ZLIB | BZIP | PPM}
newBlobCompressionMode: Boolean;
BlobCompressionMode: Byte; // {0 .. 9}
//Default Value
newDefaultValue: Boolean;
DefaultValue: TMYLDBVariant;
newMinValue: Boolean;
MinValue: TMYLDBVariant;
newMaxValue: Boolean;
MaxValue: TMYLDBVariant;
newPrimaryKey: Boolean;
PrimaryKey: Boolean;
newUnique: Boolean;
Unique: Boolean;
public
constructor Create;
destructor Destroy; override;
end;
TSQLFieldDefs = class (TObject)
protected
List: TList;
function GetDef(Index: Integer): TSQLFieldDef;
public
constructor Create;
destructor Destroy; override;
function AddCreated: TSQLFieldDef;
function GetCount: Integer;
public
property Items[Index: Integer]: TSQLFieldDef read GetDef; default;
property Count: Integer read GetCount;
end;
TMYLDBIndexField = record
FieldName: string; // field name or pseudonym
desc: boolean; // desc/asc
nocase: boolean; // ncase/case sensitive
end;
TMYLDBIndex = record
IndexName: String;
Unique: Boolean;
Primary: Boolean;
IndexFields: array of TMYLDBIndexField; // Index Fields
end;
TMYLDBDDLTableManipulation = class (TMYLDBSQLCommand)
protected
Password: String; // table password
DatabaseName: String; // DB Name
TableName: String; // Table Name
TableAlias: String; // Table Pseudonym
SQLFieldDefs: TSQLFieldDefs; // SQLFieldDefs
//PrimaryIndexName: String;
//PrimaryKey: TStringList;
//PrimaryKeyFields: array of TMYLDBIndexField;
//UniqueFields: TStringList;
Indexes: array of TMYLDBIndex;
// table element list
procedure ParseTableElementList;
// parse TableName token
procedure ParseTableNameToken;
// Fill table column type into Structure
procedure FillColumnType(var FieldDef:TSQLFieldDef);
// Fill column requared value into Structure
procedure ParseColumnRequared(var FieldDef:TSQLFieldDef);
// parse PASSWORD 'aaa'
procedure ParsePassword;
// parse DEFAULT {const | NULL}
function ParseDefaultValue(var FieldDef:TSQLFieldDef): Boolean;
// parse MINVALUE value
function ParseMinValue(var FieldDef:TSQLFieldDef): Boolean;
// parse MAXVALUE value
function ParseMaxValue(var FieldDef:TSQLFieldDef): Boolean;
// parse fiald ... PRIMARY KEY
function ParseFieldPrimaryKey(var FieldDef:TSQLFieldDef): Boolean;
// parse fiald ... UNIQUE
function ParseFieldUnique(var FieldDef:TSQLFieldDef): Boolean;
// parse Primary Key
function ParsePrimaryKey: boolean;
// parse Index
function ParseIndex: boolean;
// parse Index Field
procedure ParseIndexField(IndexNo: Integer);
// parse Index Fields
procedure ParseIndexFields(IndexNo: Integer);
// go to the Next token and Parse Integer (Int64)
function ParseInteger: Int64;
// Create MYLDBTable object and fill MYLDBTable params
procedure CreateInternalMYLDBTable(query: TDataSet; var table: TDataSet;
var db: TObject; FillAdvFieldDefs: Boolean);
// Fill AdvFieldDef
procedure FillAdvFieldDef(AdvFieldDef: TFieldDef; SQLFieldDef: TSQLFieldDef);
// Add Indexes to MYLDBTable
procedure AddIndexes(T: TDataSet);
// Add Primary Key into MYLDBTable
//procedure AddPrimaryKey(T: TDataSet);
// Add UNIQUE constraint and index into MYLDBTable
//procedure AddUnique(T: TDataSet);
// Delete PrimaryKey
procedure DeletePrimaryKey(T: TDataSet);
public
// creates object
constructor Create(Lexer: TMYLDBLexer; Query: TDataSet);
// destroy
destructor Destroy; override;
// parses query
procedure Parse; override;
// executes query
procedure ExecSQL(
query: TDataset;
IsRoot,
RequestLive: boolean;
var ReadOnly: boolean;
ParentQueryAO: TMYLDBAO = nil;
ParentCursor: TMYLDBCursor = nil
); override; abstract;
end;//TMYLDBDDLTableManipulation
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBDDLCreateTable
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBDDLCreateTable = class (TMYLDBDDLTableManipulation)
private
FCreateIfNotExists: Boolean;
protected
// Create Table
procedure CreateTable(query: TDataSet);
public
// parses query
procedure Parse; override;
// executes query
procedure ExecSQL(
query: TDataset;
IsRoot,
RequestLive: boolean;
var ReadOnly: boolean;
ParentQueryAO: TMYLDBAO = nil;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -