Registriert seit: 19. Apr 2006
Ort: Ilmenau
87 Beitrδge
RAD-Studio 2009 Pro
|
Blob (OLEOBJECT) via SQL kopieren
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'
$'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#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
|
|
Zitat
|