Chapter 5: General Objects and Methods  add()

Chapter 5: General Objects and Methods

Binary large objects

Binary large objects (blobs) objects are a collection of bytes containing arbitrary values that include null characters terminated by a length value. The maximum size of a blob equals the maximum size of an integer on your computer system. For most computer systems, the maximum size is 4 GB. To define a blob, use this format:

blob obj_name;

Using the += operator to add a string to a blob:

blob my_blob;
string str;
my_blob = “something”;
str = “ stringy”;
my_blob += str;
//my_blob now contains "something stringy"

Using the += operator to add a blob to another blob:

blob my_blob;
blob blob2;
my_blob = “something”;
blob2 = “ blob-like”;
my_blob += blob2;
//my_blob now contains "something blob-like"

Using the add() method to add a string to a blob:

blob my_blob;
string str;
my_blob = “something”;
str = “ methodical”;
my_blob.add(str);
// my_blob now contains "something methodical"
//my_blob.add(&str) would serve the same purpose

NoteThe add() method does not support using the blob itself as an argument. Instead, you must use the blob address.

Using the add() method to add a blob to a blob:

blob my_blob;
blob blob2;
my_blob = “something”;
blob 2 = “ methodical”;
blob2
my_blob.add(&blob2);

You can also access individual bytes of blob data by indexing into the blob object. blob objects have a 0-based index. If you subscript past the current size of the blob, ODL extends the blob with null bytes to fit the required size. You can reference the blob directly as shown in the following example, or you can use a pointer to the blob.

blob myblob;
char ch;
//variable to hold the character read
myblob = “abcdefg”;
ch = my_blob[5];
//ch now contains “f”

NoteIf you use a pointer to a blob, use the format shown in the “Pointer to object” column of the usage tables. Otherwise, use the formats shown in the “Object” column of the usage tables.





Copyright © 2005. Sybase Inc. All rights reserved. add()

View this book as PDF