602SQL Documentation Index  



boolean wb_lob_write(resource lob, integer offset, integer size, string data)


An open LOB, the result of the wb_result function in the WB_LOBMODE_RESOURCE mode, or one of the array items returned by the wb_fetch_into function.
The beginning position of the LOB that will be rewritten with the data string in characters.
Size of the data that will be written to the LOB in characters.
String containing the data to be written to the LOB.


Rewrites a part of the lob LOB starting at the offset position (the first character of the lob has offset=0) with the data from the data string (size characters). If size==0, then the entire data string contents will be written (up to the last character with ASCII code 0); this option is not recommended for BLOBs, since binary data often contains characters with code 0.

Characters are:

The allowed range of the offset value is 0 to N, where N is the LOB length before the wb_lob_write function was executed. If offset==N, then the data string value (or its part) will be appended after the current LOB value (no character of the original LOB value will be rewritten). In all other cases there will always be at least one character from the original LOB value that will be overwritten.

If you are writing to CLOBs or BLOBs then there must be client_encoding=WB_ENC_ASCII, or you must set a different coding with 1-byte sized characters (see wb_set_client_encoding), data must be an ASCII string. The size parameter specifies the count of 1-byte characters that will be written to the LOB. If you are writing to NCLOBs, the string coding on the client side may be chosen at will, since the PHP module will always convert the string from the specified coding to the UCS-2 coding prior to writing. The data parameter must contain a string in the specified coding and the size size specifies the number of characters to be written to the NCLOB (a character is understood as a character in the given client coding, e.g. UTF-8 characters for the WB_ENC_UTF8 coding).


TRUE if successful, otherwise FALSE.


Write the file contents to a BLOB in a new record:

wb_exec($conn,"INSERT INTO Files_table(filename) VALUES($filename)")
  or die("Cannot create record.");
$cur=wb_exec($conn,"SELECT content FROM Files_table WHERE filename=$filename")
  or die("Cannot open cursor.");
wb_fetch_row($cur) or die("Record does not exist.");
$lob=wb_result($cur,1) or die("Cannot open LOB.");
do {
   $data=fread($handle, 8192);
   if( $datalen==0 ) { break; }
   wb_lob_write($lob,$offset,$datalen,$data) or break;
} while(true);


Append a string to a NCLOB:

$cursor=wb_exec($connection,"SELECT nclob_column FROM Unicode_table WHERE id=1")
  or die("Cannot open cursor.");
wb_fetch_into($cursor,$buff) or die("Record does not exist.");
// we assume that the $str variable is a UTF-8 string
wb_set_client_encoding($connection, WB_ENC_UTF8);
// we assume that the $str_iso variable is a ISO-8859-2 string
wb_set_client_encoding($connection, WB_ENC_ISO_8859_2);