Einzelnen Beitrag anzeigen

Ducksoul

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

Blob (OLEOBJECT) via SQL kopieren

  Alt 15. Mδr 2010, 14:09
Datenbank: Access • Version: 2000 • Zugriff όber: ADO
Hallo,

innerhalb meines Tabellenimports kann es sein, dass ich Datensδtze mit Blobs zwischen zwei Datenbanken kopieren muss, was zu einer Exception fόhrt.
Mφchte ich zum Beispiel einen Datensatz aus der Tabelle Kundenbilder (in welcher zu jedem Kunden ein Bild gespeichert werden kann) kopieren, so erhalte ich folgenden SQL-Code:

'INSERT INTO KundenBilder (Kundenschluessel, Logo) VALUES (811660545, 'BM6ω'#$15#0#0#0#0#0'6'#0#0#0'('#0#0#0' '#3#0#0'X'#2#0#0#1#0#$18#0#0#0#0#0#0'ω'#$15#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0'‹)'#$B'…#'#5'‚ '#2'„"'#4'„"'#4#$81#$1F#1'‚ '#2'ˆ&'#8'‚ '#2'€'#$1E#0'}'#$1B#0'{'#$19#0'{'#$19#0'}'#$1B#0'€'#$1E#0'‚ '#2'‡&'#5'€'#$1F#0#$7F#$1E#0'…$'#3'‰('#7'†%'#4'…$'#3'‡&'#5#$81' '#0'Š)'#8#$8D','#$B'‡&'#5'„#'#2'†%'#4'…$'#3#$81' '#0'…$'#2'ƒ#'#0'‚!'#0'„#'#1'‡%'#7'Š('#$A'Š'''#$B'‰&'#$A'‚'#$1F#3'„!'#5'†$'#6'„#'#2'‚!'#0#$81' '#0'‚"'#0'„#'#1'„"'#4'‚'#$1F#3'€'#$1E#0#$81#$1F#1'‚ '#2'‚ '#2'~'#$1D#0'z'#$19#0'‚!'#0'„#'#1'†%'#3'‡&'#4'‡'''#3'†&'#2'„$'#0'‚"'#0'†%'#4'‚!'#0'ƒ"'#1'ˆ'''#6'ˆ'''#6#$81' '#0'~'#$1D#0#$7F#$1E#0'ƒ"'#1'„#'#2'…$'#3'…$'#3'„#'#2#$81' '#0'~'#$1D#0'{'#$1A#0#$81#$1F#0'ƒ"'#0'†%'#1'‰('#4'‰'''#5'ˆ&'#4'†$'#2'„"'#0'…"'#2'†#'#3'„ '#3#$81#$1D#0'‡#'#6'Ž*'#$D'‰%'#9#$7F#$1B#0'Œ*'#8#$8D','#8'†%'#1'…$'#0'Œ+'#7'…$'#0'€'#$1F#0'Œ+'#7'‚!'#0'‚!'#0'ƒ"'#0'„#'#0'†%'#1'ˆ'''#3'‰('#4'‹*'#6#$8D'*'#$A#$8D'+'#9#$8D'+'#9'Œ+'#5'Š*'#2'ˆ)'#0'†%'#0'„#'#0'„"'#0'„!'#1'„ '#3'„!'#1'…"'#2'‡&'#2'‰('#2'Š*'#2'„#'#0'„#'#0'„#'#0'…$'#0'…$'#0'‡&'#2'ˆ'''#3'‰('#4'€'#$1F#0'…$'#0'‹*'#6#$8D','#8'Š)'#5'…$'#0'‚!'#0#$81#$1F#0'ˆ$'#7'„ '#4#$81#$1D#0'€'#$1C#0'ƒ'#$1F#2'…!'#4'†#'#3'†#'#3'…#'#1'„"'#0'„"'#0'…#'#1'†%'#1'‡&'#2'‡&'#2'‡&'#0'Œ'''#1#$8D'('#1'‘+'#1'’,'#2'‘+'#1#$8D'('#1'‰&'#0'„#'#1#$7F'"'#3'w'#$1B#0'|'#$1F#5'‚$'#7#$81'"'#1'Š)'#5'•0'#$A'”-'#6#$90'+'#4#$90'+'#4#$8D'('#1'‹&'#0'Š%'#0'‹&'#0'Œ'''#0'Œ'''#0'‘,'#5#$8F'*'#3#$8D'('#1#$8D'('#1'Ž)'#2#$8D'('#1'‰$'#0'† '#0'Œ#'#8'ˆ'#$1E#6'…'#$1D#0'†'#$1F#0'‹%'#2#$8F'*'#4'‘,'#5#$90'+'#4'Ž)'#3'‹&'#0#$8D'('#1'”0'#6'•2'#6#$90'.'#0#$90'0'#0'–5'#3'Ž)'#2'‹%'#2'‡!'#0'‡!'#0'Š$'#1#$8D''''#4'Ž('#5'Ž('#5'† '#0'Š$'#1#$8D''''#4'Œ&'#3'‰#'#0'…'#$1F#0'„'#$1E#0'„'#$1E#0'‹$'#3'‰#'#0'‡!'#0'ˆ#'#0'‹&'#0'Œ('#0'Š&'#0'ˆ%'#0'Œ)'#0'Ž+'#0'‹&'#0'… '#0'‡"'#0#$8D'('#2'Œ%'#4'…'#$1F#0#$8D'"'#0'Ž%'#0#$90''''#0'‘*'#0'’+'#0'‘+'#0#$8F'('#0'Ž&'#0#$90''''#0'‘('#1'“)'#4'•,'#5'—.'#7'˜0'#5'—0'#3'–/'#2'š2'#7'”+'#2'’)'#0'“*'#1#$90''''#0'‹"'#0'Š!'#0'Ž%'#0'’)'#0'’)'#0'‘('#0'‘('#0'’)'#0'”+'#2'—.'#5'˜2'#8'Ž'''#0'Œ'''#0'‹&'#0'Š%'#0'ˆ%'#0'‰&'#0'Š&'#3'Š&'#3'‡%'#3'Š('#6'Š)'#7'ˆ'''#5'„#'#2'€'#$1F#0'}'#$1E#0'~ '#0'ˆ'''#3'‰('#2'Œ*'#2'Ž,'#2'”.'#4'–0'#5'™2'#5'š3'#6'’+'#0'’+'#0'‘+'#0#$90'-'#1#$90'+'#4'Œ*'#2'‡&'#0'‡%'#0'˜3'#6'—0'#3'”+'#2'‘'''#2#$8F'$'#3'Ž"'#3#$8F'$'#3#$90'%'#3'’)'#2#$90'('#0#$8F'('#0'’,'#0'•/'#0'–0'#0'“,'#0#$90'*'#0#$9D'7'#7'˜2'#1'‘-'#0'‘,'#0'•/'#4'•.'#7#$8F'*'#4'‰#'#0'‹'''#5'Š&'#4'ˆ#'#3'‡"'#2'…#'#1'†$'#2'ˆ'''#3'‰('#2#$8F'*'#4'Œ'''#0#$8F'*'#3'•0'#9'•0'#9#$8F'*'#3'Œ'''#0#$8F'*'#3#$8F'*'#3'‹&'#0'†!'#0'… '#0'ˆ#'#0'‹&'#0'Œ'''#0'‹&'#0#$8D'$'#0'Ž%'#0#$8F'&'#0'Ž%'#0'Œ#'#0'Œ#'#0#$8F'&'#0'’)'#2'–-'#6'•,'#5'“*'#3'‘('#1#$90''''#0#$90''''#0#$90''''#0'Ž('#0'”.'#4#$8F','#0'Œ'''#0'Œ'''#0#$8D'('#2#$8D'('#2'Š#'#2'‡ '#0'…'#$1E#0'‹%'#2#$90'*'#7#$90'+'#5'Œ'''#0'Š&'#0#$8D')'#0'’/'#3'‹&'#0#$8D'('#1#$8F'*'#3'‘,'#5#$90'+'#4#$8D'('#1'‰$'#0'‡"'#0'–1'#$A'“.'#7#$90'+'#4'Ž)'#2'Ž)'#2#$90'+'#4'’-'#6'”0'#6'‘('#0'™0'#7'œ3'#$C'”*'#5'Ž#'#2#$8F'$'#3'’'''#5'‘'''#2#$8F'&'#0'‘('#0'”,'#1'•-'#2'”+'#4'‘'''#2#$8D'"'#0'ˆ'#$1F#0'ˆ'#$1F#0'Ž('#5'’,'#9#$90'+'#5'’-'#6'–2'#8'“/'#5'Œ)'#0'Œ)'#0#$8F','#0'‘,'#5#$90'+'#4'Ž)'#3'Ž)'#3#$90')'#8'“-'#$A'“*'#3'“*'#1'“*'#1'“*'#1'‘('#0#$8F'&'#0'Œ#'#0'‹"'#0'‹"'#0#$90''''#0'•,'#3'–-'#4'”+'#2'’)'#0'“*'#1'”+'#4'–+'#9'”)'#7#$90')'#2'Ž('#0#$8D')'#0#$90'-'#0'’0'#0'•3'#5#$8F'-'#3#$8D'*'#4'Š&'#3'ˆ$'#2'†$'#2'ˆ&'#4'‹*'#6#$8D','#8'‡!'#0'ˆ"'#0'‹%'#2#$8D''''#4'Ž('#5#$8D''''#4'Œ'''#1'‹&'#0'“.'#7... Wie bekomme ich nun gόltigen SQL-Code, wenn ich Blobfelder habe?

Mein Code:

Delphi-Quellcode:
  //jeden im Array zur Tabelle gespeicherten Datensatz durchgehen
            for x := 0 to Length(IDs.arr_ids) - 1 do
            begin
                // DS im Array auswδhlen
              sSQL := 'SELECT * FROM ' + arr_tables[i].tn;
              sSQL := sSQL + ' WHERE ' + pk + '=' + IntToStr(IDs.arr_ids[x]);

              dbQuery.SQL.Clear;
              //ShowMessage(sSQL);
              dbQuery.SQL.Add(sSQL);
              dbQuery.Open;
              dbquery.First;

                // alle Felder in Zieldb auswδhlen
              dbquery_in.SQL.Clear;
              dbquery_in.SQL.ADD('SELECT * FROM ' + arr_tables[i].tn);
              dbquery_in.Open;

                // Felder kopieren
              if not dbquery.Fields[0].IsNull then
              begin
                sSQL2 := 'INSERT INTO ' + arr_tables[i].tn + ' (';
                for k := 0 to dbQuery.Fields.Count - 1 do
                  if (dbquery_in.FindField(dbquery.Fields[k].FullName) <> nil) and
                  not (dbquery.Fields[k].IsNull) then
                    sSQL2 := sSQL2 + dbquery.Fields[k].FieldName + ', ';
                  sSQL2 := Copy(sSQL2, 1, Length(sSQL2) - 2);
                  sSQL2 := sSQL2 + ') VALUES (';

                for k := 0 to dbquery.Fields.Count - 1 do
                  if (dbquery_in.FindField(dbquery.Fields[k].FullName) <> nil) and
                  not (dbquery.Fields[k].IsNull) then
                    if dbquery.Fields[k].Datatype = ftBoolean then
                      sSQL2 := sSQL2 + BoolToStr(dbquery.Fields[k].AsBoolean) + ', '

                    else if dbquery.Fields[k].Datatype = ftInteger then
                      sSQL2 := sSQL2 + dbquery.Fields[k].AsString + ', '
                    else
                      sSQL2 := sSQL2 + QuotedStr(dbquery.Fields[k].AsString) + ', ';
                    sSQL2 := Copy(sSQL2, 1, Length(sSQL2) - 2);
                    sSQL2 := sSQL2 + ')';

                dbcomm_in.CommandText := sSQL2;
                dbcomm_in.Execute;
              end;
Gruί
Franz
  Mit Zitat antworten Zitat