Print Thread
best way to fill oracle raw field with TOracleDataSet
#52653 12/07/15 02:24 PM
Joined: Oct 2000
Posts: 5
germany
T
tschuk Offline OP
Member
OP Offline
Member
T
Joined: Oct 2000
Posts: 5
germany
Hello,
I'm facing some trouble with raw field's in oracle. I made a simple test case with a raw field with 504 Bytes:

>>>>>>>>>
create table test (r4 RAW(504));
<<<<<<<<<

I want to write some coefficients into the database field with DOA:

>>>>>>>>>
procedure TForm1.Button1Click(Sender: TObject);
var
koeff126: array[0..125] of Single;
I: Integer;
begin
for I := 0 to 126 - 1 do
koeff126[i] := I;
with OracleDataSet1 do
begin
Insert;
WriteKoeff(FieldByName('r4'), koeff126, 126);
Post;
end;
end;

procedure TForm1.WriteKoeff(fld: TField; koeff: array of Single;
nKoeff: Integer);
var
aMS: TMemoryStream;
i: Integer;
s: String;
pB: PByte;
begin
aMS := nil;

try
aMS := TMemoryStream.Create;
// Werte erstmal in Stream speichern
for i := 0 to nKoeff - 1 do
aMS.Write(koeff[i], sizeof(Single));
// aus dem Stream einen HEXADEZIMAL-String erzeugen
s := '';
pB := PByte(aMS.Memory);
for i := 0 to aMS.Size - 1 do
begin
s := s + IntToHex(pB^,2);
Inc (pB);
end;
fld.AsString := s;
finally
if aMS <> nil then FreeAndNil(aMS);
end;
end;
<<<<<<<<<

Running this code the ORA-01480 exception is thrown. Writing to raw fields shouldn't depend on NLS-Settings, but for completness here they are:

>>>>>>>>>
NLS_LANGUAGE GERMAN
NLS_TERRITORY GERMANY
NLS_CURRENCY ?
NLS_ISO_CURRENCY GERMANY
NLS_NUMERIC_CHARACTERS ,.
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD.MM.RR
NLS_DATE_LANGUAGE GERMAN
NLS_SORT GERMAN
NLS_TIME_FORMAT HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT DD.MM.RR HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT DD.MM.RR HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY ?
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0
<<<<<<<<<

I'm using Delphi 2006 with DOA 4.1.1. What can i do to write the values to the field?

thanks for your help,

regards Frank

Re: best way to fill oracle raw field with TOracleDataSet
tschuk #52661 12/08/15 10:17 AM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
Can you check Length(s) before you assign it to fld.AsString? Can you also check if it has the expected hexadecimal string value?


Marco Kalter
Allround Automations
Re: best way to fill oracle raw field with TOracleDataSet
Marco Kalter #52664 12/08/15 11:06 AM
Joined: Oct 2000
Posts: 5
germany
T
tschuk Offline OP
Member
OP Offline
Member
T
Joined: Oct 2000
Posts: 5
germany
Hello Marco,

thanks for your reply, Length(s) evaluates to 1008, s contains a valid HEX-String (please ignore the single quotes, they are from the expression evaluator):

>>>>>>>>>>>>>>>>>>>>>
'000000000000803F0000004000004040000080400000A0400000C0400000E0400000004100001041000020410000304100004041000050410000604100007041000080410000884100009041000098410000A0410000A8410000B0410000B8410000C0410000C8410000D0410000D8410000E0410000E8410000F0410000F84100000042000004420000084200000C4200001042000014420000184200001C4200002042000024420000284200002C4200003042000034420000384200003C4200004042000044420000484200004C4200005042000054420000584200005C4200006042000064420000684200006C4200007042000074420000784200007C42000080420000824200008442000086420000884200008A4200008C4200008E42000090420000924200009442000096420000984200009A4200009C4200009E420000A0420000A2420000A4420000A6420000A8420000AA420000AC420000AE420000B0420000B2420000B4420000B6420000B8420000BA420000BC420000BE420000C0420000C2420000C4420000C6420000C8420000CA420000CC420000CE420000D0420000D2420000D4420000D6420000D8420000DA420000DC420000DE420000E0420000E2420000E4420000E6420000E8420000EA420000EC420000EE420000F0420000F2420000F4420000F6420000F8420000FA42'
>>>>>>>>>>>>>>>>>>>>>

regards
Frank


Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.081s Queries: 14 (0.005s) Memory: 2.5088 MB (Peak: 3.0422 MB) Data Comp: Off Server Time: 2024-05-20 03:55:13 UTC
Valid HTML 5 and Valid CSS