PostgreSQLLargeObject

From Xojo Documentation

Class (inherits from Object)

Stores a PostgreSQL large object.

Properties
Length fa-lock-32.png Position


Methods
Close Seek Write
Read Tell

Notes

PostgreSQL requires that all large object operations be performed inside of a transaction. Therefore, you must start a transaction before you perform your first large object operation, like this:

db.ExecuteSQL "BEGIN TRANSACTION"

After you have performed your last large object operation, you should close the transaction, like this:

db.ExecuteSQL "END TRANSACTION"

Most large object operations will be performed using an instance of the PostgreSQLLargeObject class, which you will obtain by calling the OpenLargeObject method of the PostgreSQLDatabase class. There is no reason to ever create your own PostgreSQLLargeObject instance using New.

The PostgreSQLLargeObject class works similarly to BinaryStream. As with BinaryStreams, PostgreSQLLargeObjects are always positioned at a certain location in the large object. Whenever you read or write to the large object, the position moves to just after the read or write. You can also set the position using the Position property. You can have more control over the position by using the Seek method.

For example, if you wanted to position a large object at its end, you could call Seek as follows:

largeObject.Seek(0, 2)

The following Seek positions the large object at its beginning:

largeObject.Seek(0, 0)

Offsets can be negative as well, For example, the following call of Seek positions the large object 10 bytes before its current position:

largeObject.Seek(-10, 1)

Example

Read the data in a large object:

// db is a previously connected PostgreSQLDatabase
// objectID is an integer referring to a previously created large object
Var largeObject As PostgreSQLLargeObject
largeObject = db.OpenLargeObject(objectID)

Var data As String = largeObject.Read(largeObject.Length)

Example Projects

/Example Projects/Database/PostgreSQL/LargeObjects

See Also

PostgreSQLDatabase class.