Einzelnen Beitrag anzeigen

wschrabi

Registriert seit: 16. Jan 2005
437 Beiträge
 
#7

AW: Sounddatei als Blob in SQLite

  Alt 23. Nov 2016, 20:26
Hallo
Ich habe ein ähnliches PRoblem:

Ich habe eine SQLITE DB wo ID in Table REF und Location und ReferenceID in Table LOcation BLOB sind. (sind eigl. GUID in binärer Form, da das Devat Unidac die OPtion Binary GUID = False nicht hat muß ich so herumwurschtln)

Jetzt möchte ich in Location einen Record in Location mit random ID und einen von REF herausgelesenen GUID eintragen (insert)
Doch ich komm nicht weiter... vielleicht muss es doch viel einfacher gehen

BIn für jeden RAT DANKBAR!

Ich dachte mir so:

Delphi-Quellcode:
procedure TForm1.Button3Click(Sender: TObject);
var
   blobID, blobRefID: system.Classes.TStream;
   MyStreamID: TMemoryStream;
   MyGuid0: TGUID;
   sISBN,oldURL: string;
   sLINK: string;
   nRECNUM: integer;
  k: Integer;
begin
   nRecnum:=0;
   while not(uniquery1.Eof) do
      begin
      nRecNUm:=nrECNUm+1;
      sISBN:=Uniquery1.FieldByName('ISBN').AsString;
           
      if getlinefromMemo(sISBN) then
         begin
         label4.Caption:=Format('LINKs found: %d @ RecNr.: %d',[listbox1.Count,Nrecnum]);
         for k := 0 to listbox1.Count-1 do
            begin
            MyStreamID := TMemoryStream.Create;

            
            if UniConnection1.ProviderName='SQLitethen
               begin
               (*
              // INsert into location in Citavi DB
              > insert into Location (ID,Address,ReferenceID,CreatedOn,ModifiedOn,AddressInfo,LocationType,PreviewBehaviour)
              > (
              >    :MyRANDGUID,
              >    :FILENAME,
              >    :RefID,
              >    datetime(strftime('%s','now'), 'unixepoch', 'localtime'),
              >    datetime(strftime('%s','now'), 'unixepoch', 'localtime'),
              >    1,
              >    0,
              >    0); 
                 *)

                 blobID := UniQuery1.CreateBlobStream(UniQuery1.FieldByName('ID'), bmRead); // HIER HAPPERTS.
                 MyStreamID.Clear;
                 MyStreamID.LoadFromStream(blobID );
                 uniquery2.ParamByName('RefID').LoadFromStream(MyStreamID, ftBlob);
                 CreateGUID(MyGuid0);
                 uniquery2.ParamByName('MyRandGUID').AsBlob:=TEncoding.UTF8.GetBytes(GUIDToString(MyGuid0));
                 
                 
               Label5.Caption:=Format('DB Record GUID: %s : %s',[uniquery1.FieldByName('MYID').AsString,uniquery1.FieldByName('ID').AsString]);
               end
            else
               begin
               uniquery2.SQL.Text:=' Update refs set URL = :Filename where id = :RefID';
               
               if not(checkbox3.Checked) then
                  uniquery2.SQL.Text:=' Update refs set link_to_pdf = :Filename where id = :RefID';
               
               uniquery2.ParamByName('RefID').AsString:=uniquery1.FieldByName('id').AsString;
               end;
               
            if (UniConnection1.ProviderName='MySQL') then
               begin
               if not(checkbox3.Checked) then
                  oldURL:=uniquery1.FieldByName('link_to_pdf').AsString
               else
                  oldURL:=uniquery1.FieldByName('url').AsString;
               
               end;
            if trim(oldURL) = 'then
               uniquery2.ParamByName('Filename').AsString:=convertfn(listbox1.Items[k])
            else
               uniquery2.ParamByName('Filename').AsString:=oldURL+#13#10+convertfn(listbox1.Items[k]) ;
               
            uniquery2.Execute;
            MyStreamID.Free;
            WriteLOgMemo(Format('UPD: ISBN: %s -> Affected Rows: %d',[sISBN,uniquery2.RowsAffected]));
            end;
         Application.ProcessMessages;
         
         end;
      
      uniquery1.Next;
      end;
      WriteLOgMemo(Format('UPDATE with URLs finished: Total affected Rows: %d',[nrecnum]));
      
end;
so hab ich es auch probiert: Immer ungültige Typenumwandlung bei der 1. zeil

Delphi-Quellcode:
                 blobID := UniQuery1.FieldByName('ID') as TBlobField;
                 BlobID.LoadFromStream(MyStreamID);
                 TBlobField(UniQuery2.FieldByName('RefID')).LoadFromStream(MyStreamID);
                 CreateGUID(MyGuid0);
                 uniquery2.ParamByName('MyRandGUID').AsBlob:=TEncoding.UTF8.GetBytes(GUIDToString(MyGuid0));

Geändert von wschrabi (23. Nov 2016 um 20:45 Uhr)
  Mit Zitat antworten Zitat