Einzelnen Beitrag anzeigen

Ducksoul

Registriert seit: 19. Apr 2006
Ort: Ilmenau
87 Beiträge
 
RAD-Studio 2009 Pro
 
#3

Re: Blob (OLEOBJECT) via SQL kopieren

  Alt 16. Mär 2010, 10:48
Hm, ja das habe ich versucht. Es gibt auch keine Fehlermeldung oder so, aber wenn die Daten finden sich danach noch nicht in der Datenbank. Mache ich beim Speichern des Streams was falsch?

Delphi-Quellcode:
if blob = true then
                begin
                  for k := 0 to dbquery.Fields.Count - 1 do
                    if (dbquery.Fields[k].Datatype = ftBlob) and not
                       (dbquery.Fields[k].IsNull) then
                    begin
                      try
                        sSQL := 'Select ' + dbquery.Fields[k].Fieldname + ' FROM ' + arr_tables[i].tn + ' WHERE ' + pk + '=' + IntToStr(IDs.arr_ids[x]);
                        dbquery_in.SQL.Clear;
                        dbquery_in.SQL.Add(sSQL);
                        dbquery_in.Open;
                        dbquery_in.First;
                        bs1 := dbquery.CreateBlobStream(dbquery.Fields[k], bmread);
                        bs1.Seek(0, soFromBeginning);
                        dbquery_in.Edit;
                        bs2 := dbquery_in.CreateBlobStream(dbquery_in.FieldByName(dbquery.Fields[k].FieldName), bmwrite);
                        ShowMessage(IntToStr(bs2.CopyFrom(bs1, bs1.Size)));
                        ShowMessage(IntToStr(bs2.Size));
                        dbquery_in.Post;
                      finally
                        //FreeAndNil(bs1);
                        //FreeAndNil(bs2);
                      end;
                    end;
                end;
Viele Grüße

EDIT:

Hier die funktionierende Lösung.

Delphi-Quellcode:
if blob = true then
                begin
                  for k := 0 to dbquery.Fields.Count - 1 do
                    if (dbquery.Fields[k].Datatype = ftBlob) and not
                       (dbquery.Fields[k].IsNull) then
                    begin
                      try
                        sSQL := 'Select * FROM ' + arr_tables[i].tn + ' WHERE ' + pk + '=' + IntToStr(IDs.arr_ids[x]);
                        dbquery_in.SQL.Clear;
                        dbquery_in.SQL.Add(sSQL);
                        dbquery_in.Open;
                        dbquery_in.First;
                        bs1 := dbquery.CreateBlobStream(dbquery.Fields[k], bmread);
                        bs1.Seek(0, soFromBeginning);
                        dbquery_in.Edit;
                        bs2 := dbquery_in.CreateBlobStream(dbquery_in.FieldByName(dbquery.Fields[k].FieldName), bmwrite);
                        ShowMessage(IntToStr(bs2.CopyFrom(bs1, bs1.Size)));
                        ShowMessage(IntToStr(bs2.Size));
                      finally
                        FreeAndNil(bs1);
                        FreeAndNil(bs2);
                      end;
                      dbquery_in.Post;
                    end;
                end;
Gruß
Franz
  Mit Zitat antworten Zitat