This:
is converted by the SQL precompiler to this:
I had a realisation. UNS(10) is a 4 byte unsigned integer. A varchar has a 2 or 4 byte prefix to store the numeric number of characters, just like the myClob_LEN component of SqlType(CLOB).
Which means, the memory layout for these two definitions:
should be the same - 4 byte unsigned integer for number of characters, followed by 3000 bytes of characters.
Which means, it should be safe to use pointers to overlay the two variables on top of each other? We have programs that use varchars larger than the maximum 32kb supported by SQL, and being able to directly overlay a larger varchar with a CLOB would make them simpler to deal with if we ever needed to process that variable in SQL. Example:
So RPG code can use myDataV and SQL can use myDataC, and both are manipulating the same data.
Is this safe? Or are there reasons to not do this?
Code:
Dcl-S myClob SqlType(CLOB:3000);
Code:
Dcl-Ds myClob; myClob_LEN UNS(10); myClob_DATA CHAR(3000); End-Ds;
Which means, the memory layout for these two definitions:
Code:
Dcl-S myClob SqlType(CLOB:3000); Dcl-S myVar Varchar(3000:4);
Which means, it should be safe to use pointers to overlay the two variables on top of each other? We have programs that use varchars larger than the maximum 32kb supported by SQL, and being able to directly overlay a larger varchar with a CLOB would make them simpler to deal with if we ever needed to process that variable in SQL. Example:
Code:
Dcl-S myDataC SqlType(CLOB:3000000); Dcl-S myDataV Varchar(3000000:4) based(@myDataV); Dcl-S @myDataV Pointer inz(%addr(myDataC)); myDataV = 'some long data'; exec sql set :myDataC = upper(:myDataC); // myDataV now equals 'SOME LONG DATA'
Is this safe? Or are there reasons to not do this?
Comment