📄 ibstoredproc.pas
字号:
end;
DataType := ftUnknown;
for i := 0 to QSelect.Params.Count - 1 do begin
case QSelect.Params[i].SQLtype of
SQL_TYPE_DATE: DataType := ftDate;
SQL_TYPE_TIME: DataType := ftTime;
SQL_TIMESTAMP: DataType := ftDateTime;
SQL_SHORT:
if ((QSelect.Params[i].AsXSQLVar)^.sqlscale = 0) then
DataType := ftSmallInt
else
DataType := ftBCD;
SQL_LONG:
if ((QSelect.Params[i].AsXSQLVar)^.sqlscale = 0) then
DataType := ftInteger
else if ((QSelect.Params[i].AsXSQLVar)^.sqlscale >= (-4)) then
DataType := ftBCD
else DataType := ftFloat;
SQL_INT64:
if ((QSelect.Params[i].AsXSQLVar)^.sqlscale = 0) then
DataType := ftLargeInt
else if ((QSelect.Params[i].AsXSQLVar)^.sqlscale >= (-4)) then
DataType := ftBCD
else DataType := ftFloat;
SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: DataType := ftFloat;
SQL_TEXT: DataType := ftString;
SQL_VARYING:
if ((QSelect.Params[i].AsXSQLVar)^.sqllen < 1024) then
DataType := ftString
else DataType := ftBlob;
SQL_BLOB, SQL_ARRAY, SQL_QUAD: DataType := ftBlob;
end;
FParams.CreateParam(DataType, Trim(QSelect.Params[i].Name), ptInput);
end;
end;
procedure TIBStoredProc.SetPrepared(Value: Boolean);
begin
if Prepared <> Value then
begin
if Value then
try
if SelectSQL.Text = '' then GenerateSQL;
InternalPrepare;
if FParams.Count = 0 then CreateParamDesc;
FPrepared := True;
except
FreeStatement;
raise;
end
else
FreeStatement;
end;
end;
procedure TIBStoredProc.Prepare;
begin
SetPrepared(True);
end;
procedure TIBStoredProc.UnPrepare;
begin
SetPrepared(False);
end;
procedure TIBStoredProc.FreeStatement;
begin
InternalUnPrepare;
QSelect.FreeHandle;
FPrepared := False;
end;
procedure TIBStoredProc.SetPrepare(Value: Boolean);
begin
if Value then
Prepare
else
UnPrepare;
end;
procedure TIBStoredProc.CopyParams(Value: TParams);
begin
if not Prepared and (FParams.Count = 0) then
try
Prepare;
Value.Assign(FParams);
finally
UnPrepare;
end
else
Value.Assign(FParams);
end;
procedure TIBStoredProc.SetParamsList(Value: TParams);
begin
CheckInactive;
if Prepared then
begin
SetPrepared(False);
FParams.Assign(Value);
SetPrepared(True);
end else
FParams.Assign(Value);
end;
function TIBStoredProc.ParamByName(const Value: string): TParam;
begin
if not Prepared and (FParams.Count = 0) then
Prepare;
Result := FParams.ParamByName(Value);
end;
function TIBStoredProc.GetStoredProcedureNames: TStrings;
begin
FNameList.clear;
GetStoredProcedureNamesFromServer;
Result := FNameList;
end;
procedure TIBStoredProc.GetStoredProcedureNamesFromServer;
var
Query : TIBSQL;
begin
if not (csReading in ComponentState) then
begin
ActivateConnection;
Database.InternalTransaction.StartTransaction;
Query := TIBSQL.Create(self);
try
Query.GoToFirstRecordOnExecute := False;
Query.Database := DataBase;
Query.Transaction := Database.InternalTransaction;
Query.SQL.Text := 'Select RDB$PROCEDURE_NAME from RDB$PROCEDURES'; {do not localize}
Query.Prepare;
Query.ExecQuery;
while (not Query.EOF) and (Query.Next <> nil) do
FNameList.Add(TrimRight(Query.Current.ByName('RDB$PROCEDURE_NAME').AsString)); {do not localize}
finally
Query.Free;
Database.InternalTransaction.Commit;
end;
end;
end;
procedure TIBStoredProc.SetParams;
var
i : integer;
j: integer;
begin
i := 0;
for j := 0 to FParams.Count - 1 do
begin
if (Params[j].ParamType <> ptInput) then
continue;
if not Params[j].Bound then
IBError(ibxeRequiredParamNotSet, [nil]);
if Params[j].IsNull then
SQLParams[i].IsNull := True
else begin
SQLParams[i].IsNull := False;
case Params[j].DataType of
ftString:
SQLParams[i].AsString := Params[j].AsString;
ftBoolean, ftSmallint, ftWord:
SQLParams[i].AsShort := Params[j].AsSmallInt;
ftInteger:
SQLParams[i].AsLong := Params[j].AsInteger;
ftLargeInt:
SQLParams[i].AsInt64 := Params[j].Value;
ftFloat, ftCurrency:
SQLParams[i].AsDouble := Params[j].AsFloat;
ftBCD:
SQLParams[i].AsCurrency := Params[j].AsCurrency;
ftDate:
SQLParams[i].AsDate := Params[j].AsDateTime;
ftTime:
SQLParams[i].AsTime := Params[j].AsDateTime;
ftDateTime:
SQLParams[i].AsDateTime := Params[j].AsDateTime;
ftBlob, ftMemo:
SQLParams[i].AsString := Params[j].AsString;
else
IBError(ibxeNotSupported, [nil]);
end;
end;
Inc(i);
end;
end;
procedure TIBStoredProc.SetParamsFromCursor;
var
I: Integer;
DataSet: TDataSet;
begin
if DataSource <> nil then
begin
DataSet := DataSource.DataSet;
if DataSet <> nil then
begin
DataSet.FieldDefs.Update;
for I := 0 to FParams.Count - 1 do
with FParams[I] do
if (not Bound) and
((ParamType = ptInput) or (ParamType = ptInputOutput)) then
AssignField(DataSet.FieldByName(Name));
end;
end;
end;
procedure TIBStoredProc.FetchDataIntoOutputParams;
var
i,j : Integer;
begin
j := 0;
for i := 0 to FParams.Count - 1 do
with Params[I] do
if ParamType = ptOutput then begin
Value := QSelect.Fields[j].Value;
Inc(j);
end;
end;
procedure TIBStoredProc.InternalOpen;
begin
IBError(ibxeIsAExecuteProcedure,[nil]);
end;
procedure TIBStoredProc.DefineProperties(Filer: TFiler);
function WriteData: Boolean;
begin
if Filer.Ancestor <> nil then
Result := not FParams.IsEqual(TIBStoredProc(Filer.Ancestor).FParams) else
Result := FParams.Count > 0;
end;
begin
inherited DefineProperties(Filer);
Filer.DefineProperty('ParamData', ReadParamData, WriteParamData, WriteData); {do not localize}
end;
procedure TIBStoredProc.WriteParamData(Writer: TWriter);
begin
Writer.WriteCollection(Params);
end;
procedure TIBStoredProc.ReadParamData(Reader: TReader);
begin
Reader.ReadValue;
Reader.ReadCollection(Params);
end;
{ TIBStoredProc IProviderSupport }
function TIBStoredProc.PSGetParams: TParams;
begin
Result := Params;
end;
procedure TIBStoredProc.PSSetParams(AParams: TParams);
begin
if AParams.Count > 0 then
Params.Assign(AParams);
Close;
end;
function TIBStoredProc.PSGetTableName: string;
begin
{ ! }
end;
procedure TIBStoredProc.PSExecute;
begin
ExecProc;
end;
procedure TIBStoredProc.PSSetCommandText(const CommandText: string);
begin
if CommandText <> '' then
StoredProcName := CommandText;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -