Einzelnen Beitrag anzeigen

Walter Landwehr

Registriert seit: 28. Mär 2006
Ort: 32816 Schieder-Schwalenberg
397 Beiträge
 
Delphi 10.4 Sydney
 
#9

AW: Insert in eine Firebirddatenbank (Tabelle)

  Alt 4. Sep 2014, 17:11
Sorry hier die functionen:

Delphi-Quellcode:
function ExecuteSQL(const s: string; const Par: array of variant): Boolean;
  var Q: TIBOQuery;
      i: integer;
begin
     Q := TIBOQuery.Create(nil);
     try
        try
           Q.Databasename := dmMain.ibconMain.DatabaseName;
           Q.SQL.Text := s;
           for i := Low(Par) to High(Par) do
               case VarType(Par[i]) of
                    varSmallint ,
                    varInteger : Q.Params.Items[i].AsInteger := Par[i];
                    varSingle ,
                    varDouble : Q.Params.Items[i].AsFloat := Par[i];
                    varCurrency : Q.Params.Items[i].AsCurrency := Par[i];
                    varDate : begin
                                       if TDateTime(Par[i]) = 0 then begin
                                          Q.Params.Items[i].DataType := ftDate;
                                          Q.Params.Items[i].Clear;
                                       end
                                       else
                                           Q.Params.Items[i].AsDateTime := Par[i];
                                  end;
                    varBoolean : begin
                                    if Par[i] = True then
                                       Q.Params.Items[i].AsString := '1'
                                    else
                                        Q.Params.Items[i].AsString := '0';
                                  end;
                    varByte : Q.Params.Items[i].AsWord := Par[i];
                    varString : Q.Params.Items[i].AsString := Par[i];
                    varLongWord : Q.Params.Items[i].AsInteger := Par[i];
               end;
           Q.ExecSQL;
           Result := True;
        except
              Result := False;
              raise;
        end;
     finally
            Q.Close;
            FreeAndNil(Q);
     end;
end;

function ExecuteSQLEx(const s: string; const Par, prBlobParamsNumbers: array of const): Boolean;
  var bProcessed: boolean;
      Stream1: TStream;
      Q: TIBOQuery;
      i, j: integer;
begin
     Q := TIBOQuery.Create(nil);
     try
        try
           Q.Databasename := dmMain.ibconMain.DatabaseName;
           Q.SQL.Text := s;
           for i := Low(Par) to High(Par) do
               with Par[i] do begin
                    bProcessed := False;
                    for j := 0 to High(prBlobParamsNumbers) do begin
                        if i = prBlobParamsNumbers[j].VInteger - 1 then begin
                           if VType = vtString then begin
                              Stream1 := TStringStream.Create(VString^);
                              try
                                 Q.Params.Items[i].LoadFromStream(Stream1, ftMemo);
                              finally
                                     Stream1.Free;
                              end;
                           end
                           else
                           if VType = vtAnsiString then begin
                              Stream1 := TStringStream.Create(string(VAnsiString));
                              try
                                 Q.Params.Items[i].LoadFromStream(Stream1, ftMemo);
                              finally
                                     Stream1.Free;
                              end;
                           end
                           else
                           if VType = vtObject then begin
                              Stream1 := TMemoryStream.Create;
                              try
                                 if VObject.InheritsFrom(TBitmap) then begin
                                    if not TBitmap(VObject).Empty then begin
                                       TBitmap(VObject).SaveToStream(Stream1);
                                       Q.Params.Items[i].LoadFromStream(Stream1, ftBlob);
                                    end
                                    else begin
                                         Q.Params.Items[i].DataType := ftBlob;
                                         Q.Params.Items[i].Clear;
                                    end;
                                 end;
                                 if VObject.InheritsFrom(TStrings) then begin
                                    TStrings(VObject).SaveToStream(Stream1);
                                    Q.Params.Items[i].LoadFromStream(Stream1, ftMemo);
                                 end;
                              finally
                                     Stream1.Free;
                              end;
                           end
                           else
                           if VType = vtExtended then begin
                              if VExtended^ = 0 then begin
                                 Q.Params.Items[i].DataType := ftDate;
                                 Q.Params.Items[i].Clear;
                              end
                              else
                                  Q.Params.Items[i].AsDateTime := VExtended^;
                           end;
                           bProcessed := True;
                           Break;
                        end;
                    end;
                    if not bProcessed then
                       case VType of
                            vtInteger: Q.Params.Items[i].AsInteger := VInteger;
                            vtBoolean: begin
                                            if VBoolean = True then
                                               Q.Params.Items[i].AsString := '1'
                                            else
                                                Q.Params.Items[i].AsString := '0';
                                       end;
                            vtChar: Q.Params.Items[i].AsString := VChar;
                            vtExtended: Q.Params.Items[i].AsFloat := VExtended^;
                            vtString: Q.Params.Items[i].AsString := VString^;
                            vtAnsiString: Q.Params.Items[i].AsString := string(VAnsiString);
                            vtCurrency: Q.Params.Items[i].AsCurrency := VCurrency^;
                            vtObject: begin
                                      end;
                       end;
               end;
           Q.ExecSQL;
           Result := True;
        except
             Result := False;
             raise;
        end;
     finally
           Q.Close;
           FreeAndNil(Q);
     end;
end;
Walter Landwehr
Mfg

Walter
  Mit Zitat antworten Zitat