31 |
|
interface |
32 |
|
|
33 |
|
uses |
34 |
< |
Classes, SysUtils, IBSQL, IBDatabase, StdCtrls; |
34 |
> |
Classes, SysUtils, IBSQL, IBDatabase, StdCtrls, IB; |
35 |
|
|
36 |
|
type |
37 |
|
|
48 |
|
FGetProcedures: TIBSQL; |
49 |
|
FGetProcedureParams: TIBSQL; |
50 |
|
FGetProcedureInfo: TIBSQL; |
51 |
< |
function GetSQLType(SQLType: TIBSQLTypes): string; |
51 |
> |
function GetSQLType(SQLType: TIBSQLStatementTypes): string; |
52 |
|
procedure AddWhereClause(TableName: string; QuotedStrings: boolean; SQL: TStrings; |
53 |
|
UseOldValues: boolean = false); |
54 |
|
procedure GetProcParams(ProcName: string; ParamList: TStrings; InputParams: boolean); overload; |
75 |
|
procedure GenerateDeleteSQL(TableName: string; QuotedStrings: boolean; SQL: TStrings); |
76 |
|
procedure GenerateExecuteSQL(ProcName: string; QuotedStrings: boolean; ExecuteOnly: boolean; |
77 |
|
InputParams, OutputParams, ExecuteSQL: TStrings); |
78 |
< |
function GetStatementType(SQL: string; var IsStoredProcedure: boolean): TIBSQLTypes; |
78 |
> |
function GetStatementType(SQL: string; var IsStoredProcedure: boolean): TIBSQLStatementTypes; |
79 |
|
function GetFieldNames(FieldList: TListBox): TStrings; |
80 |
|
procedure TestSQL(SQL: string; GenerateParamNames: boolean = false); |
81 |
|
end; |
82 |
|
|
83 |
|
implementation |
84 |
|
|
85 |
< |
uses IB, Dialogs, IBUtils; |
85 |
> |
uses Dialogs, IBUtils, FBMessages; |
86 |
|
|
87 |
|
{ TIBSystemTables } |
88 |
|
|
136 |
|
|
137 |
|
sqlGETPROCEDUREINFO = 'Select RDB$PROCEDURE_TYPE From RDB$PROCEDURES Where Upper(Trim(RDB$PROCEDURE_NAME)) = Upper(:ProcName)'; |
138 |
|
|
139 |
< |
function TIBSystemTables.GetSQLType(SQLType: TIBSQLTypes): string; |
139 |
> |
function TIBSystemTables.GetSQLType(SQLType: TIBSQLStatementTypes): string; |
140 |
|
begin |
141 |
|
case SQLType of |
142 |
|
SQLUnknown: Result := 'Unknown'; |
421 |
|
FTableAndColumnSQL.SQL.Text := SelectSQL; |
422 |
|
try |
423 |
|
FTableAndColumnSQL.Prepare; |
424 |
< |
case FTableAndColumnSQL.SQLType of |
424 |
> |
case FTableAndColumnSQL.SQLStatementType of |
425 |
|
SQLSelect: |
426 |
|
begin |
427 |
< |
if FTableAndColumnSQL.Current.Count > 0 then |
428 |
< |
FirstTableName := strpas(FTableAndColumnSQL.Current.Vars[0].Data^.relname) |
427 |
> |
if FTableAndColumnSQL.MetaData.Count > 0 then |
428 |
> |
FirstTableName := FTableAndColumnSQL.MetaData[0].GetRelationName |
429 |
|
else |
430 |
|
FirstTableName := ''; |
431 |
|
if assigned(Columns) then |
432 |
|
begin |
433 |
|
Columns.Clear; |
434 |
< |
for I := 0 to FTableAndColumnSQL.Current.Count - 1 do |
435 |
< |
Columns.Add(FTableAndColumnSQL.Current.Vars[I].Name) |
434 |
> |
for I := 0 to FTableAndColumnSQL.MetaData.Count - 1 do |
435 |
> |
Columns.Add(FTableAndColumnSQL.MetaData[I].Name) |
436 |
|
end; |
437 |
|
end; |
438 |
|
{ If not a select statement then return table or procedure name |
666 |
|
ExecuteSQL.Text := SQL |
667 |
|
end; |
668 |
|
|
669 |
< |
function TIBSystemTables.GetStatementType(SQL: string; var IsStoredProcedure: boolean): TIBSQLTypes; |
669 |
> |
function TIBSystemTables.GetStatementType(SQL: string; |
670 |
> |
var IsStoredProcedure: boolean): TIBSQLStatementTypes; |
671 |
|
var TableName: string; |
672 |
|
begin |
673 |
|
Result := sqlUnknown; |
679 |
|
FTestSQL.GenerateParamNames := true; {permissive} |
680 |
|
try |
681 |
|
FTestSQL.Prepare; |
682 |
< |
Result := FTestSQL.SQLType |
682 |
> |
Result := FTestSQL.SQLStatementType |
683 |
|
except on E:EIBError do |
684 |
|
// ShowMessage(E.Message); |
685 |
|
end; |
686 |
< |
if (Result = SQLSelect) and (FTestSQL.Current.Count > 0) then |
686 |
> |
if (Result = SQLSelect) and (FTestSQL.MetaData.Count > 0) then |
687 |
|
begin |
688 |
< |
TableName := strpas(FTestSQL.Current.Vars[0].Data^.relname); |
688 |
> |
TableName := FTestSQL.MetaData[0].GetRelationName; |
689 |
|
FTestSQL.SQL.Text := sqlCheckProcedureNames; |
690 |
|
FTestSQL.Prepare; |
691 |
|
FTestSQL.ParamByName('ProcName').AsString := TableName; |
728 |
|
FTestSQL.SQL.Text := SQL; |
729 |
|
try |
730 |
|
FTestSQL.Prepare; |
731 |
< |
ShowMessage('SQL '+ GetSQLType(FTestSQL.SQLType) + ' Statement Looks OK'); |
731 |
> |
ShowMessage('SQL '+ GetSQLType(FTestSQL.SQLStatementType) + ' Statement Looks OK'); |
732 |
|
except on E:EIBError do |
733 |
|
ShowMessage(RemoveSQLText(E.Message)); |
734 |
|
end; |