Page 1 of 1

insert and read Raw

Posted: Mon 06 Oct 2008 08:39
by stevenhanz
Hi,

I am trying to insert a 32 bytes long string in a raw(32) field, because i don't want to oracle do any internal coding on the string. The string is actually composed by 8 integers, which make a 32 bytes string.

For my application, the speed is very important, so i would like commit thousands of records each time. I suppose inserting a string field is faster than that of 8 integers.

But it seems it can insert into the table but can not get the right value back from the raw field? My code looks like:

Code: Select all

with OraSQL1.SQL do begin
    Clear;
    Add('BEGIN');
    Add('INSERT INTO '+ tablename + ' VALUES(');
    Add(':RID, :SID, :A1);');
    Add('END;');
end;
OraSQL1.Prepare;
counter := 0;
for I := 0 to Length(SLinks) - 1 do
begin
    with OraSQL1.Params do begin
      inc(counter);
      Items[0].ItemAsInteger[counter] := SLinks[I].RId;
      Items[1].ItemAsInteger[counter] := SLinks[I].SId;
      Items[2].ItemAsString[counter] := SLinks[I].PackedStr;         
    end;
    // data insert
    if counter mod 5000 = 0 then
    begin
       OraSQL1.Execute(counter);
       OraSession1.Commit;
       counter := 0;
    end;
end;
...
reading with the code:

Code: Select all

str := OraQuery1.FieldByName('Abs').AsString;
And I got an empty string here. Can you help me with the problem? Thank you.

Posted: Thu 09 Oct 2008 07:48
by Plash
The DataType property of a parameter is set to ftString if you use the ItemAsString property. Oracle treats a value of string parameter as a hex string when it is inserted into RAW column.

If you want to insert a value as it is, without conversion from hex, you should set the DataType property of the parameter to ftVarBytes. Assign value to the parameter using the ItemValue property. This property will not change data type to ftString.