AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Probleme mit TQuery und Records als Blob
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit TQuery und Records als Blob

Ein Thema von sandrocm · begonnen am 5. Apr 2008 · letzter Beitrag vom 7. Apr 2008
Antwort Antwort
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.276 Beiträge
 
Delphi 10.4 Sydney
 
#1

Re: Probleme mit TQuery und Records als Blob

  Alt 7. Apr 2008, 19:16
Hallo,

hier 2 meiner Routinen


Heiko

Delphi-Quellcode:

{
name:
  UpdateTextBlobField_Ex
usage:
  update a blob field
parameter:
  theTableName      - table name
  thePrimaryKeyName  - name of the primary key
  thePrimaryKeyValue - value of the primary key
  theFieldName      - field name of the blob field
  theText            - field value
return parameter:
  theErrorStr - error message
return:
  false on error
notes:
  - additional to UpdateTextBlobField name of the
    primary key is needed
}

function UpdateTextBlobField_Ex(const theTableName: String;
  const thePrimaryKeyName: String; thePrimaryKeyValue: Integer;
  const theFieldName: String; const theText: String;
  var theErrorStr: String): Boolean;
var
  FQuerySQL : TQuery;
begin
  Result:= False;
  theErrorStr:= S_internal_error;

  try
    FQuerySQL := CreateQuery; // TQuery.Create ...
    try
      with FQuerySQL do
      begin
        DataBaseName:= C_ALIASNAME; // Konstante

        SQL.Add('Update '+theTableName+' Set ');
        SQL.Add(theFieldName+'=:'+theFieldName);
        SQL.Add('Where '+thePrimaryKeyName+'=:Id');
        ParamByName('Id').AsInteger:= thePrimaryKeyValue;
        if theText='then
        begin
          ParamByName(theFieldName).DataType:= ftBlob;
          ParamByName(theFieldName).Clear;
          ParamByName(theFieldName).Bound:= True;
        end
        else
        begin
          ParamByName(theFieldName).AsBlob:= theText;
        end;
        ExecSQL;
      end; { with FQuerySQL do }

      Result:= True;
    finally
      FQuerySQL.Free;
    end;
  except
    on E: Exception do theErrorStr:= E.message;
  end;
end; { UpdateTextBlobField_Ex }

{
name:
  LoadTextBlobField_Ex
usage:
  load the text from the blob field
parameter:
  theTableName      - table name
  thePrimaryKeyName  - name of the primary key
  thePrimaryKeyValue - value of the primary key
  theFieldName      - field name of the blob field
return parameter
  theText            - the loaded field value
  theErrorStr        - error message
return:
  false on error
notes:
  - additional to LoadTextBlobField name of the
    primary key is needed
}

function LoadTextBlobField_Ex(const theTableName: String;
  const thePrimaryKeyName: String; thePrimaryKeyValue: Integer;
  const theFieldName: String; var theText: String;
  var theErrorStr: String): Boolean;
var
  FQuerySQL : TQuery;
  StringStream : TStringStream;
  Stream : TStream;
  bOK : Boolean;
begin
  bOK:= False;

  theErrorStr:= S_internal_error;

  theText:= '';

  try
    FQuerySQL := CreateQuery; // TQuery.Create ...
    StringStream := TStringStream.Create('');
    try
      with FQuerySQL do
      begin
        SQL.Add('Select '+theFieldName+' From '+theTableName);
        SQL.Add('Where '+thePrimaryKeyName+'=:Id');
        ParamByName('Id').AsInteger:= thePrimaryKeyValue;
        Open;
        try
          if QueryIsNotEmpty then
          begin
            Stream:= CreateBlobStream(FieldByName(theFieldName),bmRead);
            try
              StringStream.CopyFrom(Stream,0);
            finally
              Stream.Free;
            end;

            theText:= StringStream.DataString;

            bOK:= True;
          end;
        finally
          Close;
        end;
      end; { with FQuerySQL do }
    finally
      FQuerySQL.Free;
      StringStream.Free;
    end;
  except
    on E: Exception do
    begin
      theErrorStr:= E.message;
    end;
  end;

  Result:= bOK;
end; { LoadTextBlobField_Ex }
Heiko
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz