'Declaration Public Class PgSqlLargeObject Inherits System.IO.Stream Implements System.Data.SqlTypes.INullable, System.IDisposable
public class PgSqlLargeObject : System.IO.Stream, System.Data.SqlTypes.INullable, System.IDisposable
'Declaration Public Class PgSqlLargeObject Inherits System.IO.Stream Implements System.Data.SqlTypes.INullable, System.IDisposable
public class PgSqlLargeObject : System.IO.Stream, System.Data.SqlTypes.INullable, System.IDisposable
The PgSqlLargeObject class is used to work with PostgreSQL large objects. An instance of PgSqlLargeObject holds an OID of large object and can be used for operations with this large object.
Note: all operations with large objects require an active transaction.
public static void Main(string[] args) { PgSqlConnection connection = new PgSqlConnection("user id=postgres;password=postgres;port=5432;host=localhost;"); connection.Open(); int oid = CreateLargeObject(connection); WriteToLargeObject(connection, oid); ReadFromLargeObject(connection, oid); Console.ReadLine(); } public static int CreateLargeObject(PgSqlConnection connection) { PgSqlLargeObject lo = new PgSqlLargeObject(connection); // Create a new large object in the database. lo.Create(); Console.WriteLine("Created new large object with OID = {0}", lo.Oid); return lo.Oid; } public static void WriteToLargeObject(PgSqlConnection connection, int oid) { // All operations with large objects require an active transaction. connection.BeginTransaction(); string str = "Hello, world!"; PgSqlLargeObject lo = new PgSqlLargeObject(connection, oid); lo.Open(); if (lo.CanWrite) { byte[] buffer = Encoding.UTF8.GetBytes(str); lo.Write(buffer, 0, buffer.Length); } lo.Close(); Console.WriteLine("Written to the large object : {0}", str); connection.Commit(); } public static void ReadFromLargeObject(PgSqlConnection connection, int oid) { // All operations with large objects require an active transaction. connection.BeginTransaction(); string str = string.Empty; PgSqlLargeObject lo = new PgSqlLargeObject(connection, oid); lo.Open(); if (lo.CanWrite) { byte[] buffer = new byte[lo.Length]; lo.Read(buffer, 0, buffer.Length); str = Encoding.UTF8.GetString(buffer); } lo.Close(); Console.WriteLine("Read from the large object : {0}", str); connection.Commit(); }
Public Sub Main() Dim connection As New PgSqlConnection("user id=postgres;password=postgres;port=5432;host=localhost;") connection.Open() Dim oid As Integer = CreateLargeObject(connection) WriteToLargeObject(connection, oid) ReadFromLargeObject(connection, oid) Console.ReadLine() End Sub Public Function CreateLargeObject(ByVal connection As PgSqlConnection) As Integer Dim lo As New PgSqlLargeObject(connection) ' Create a new large object in the database. lo.Create() Console.WriteLine("Created new large object with OID = {0}", lo.Oid) Return lo.Oid End Function Public Sub WriteToLargeObject(ByVal connection As PgSqlConnection, ByVal oid As Integer) ' All operations with large objects require an active transaction. connection.BeginTransaction() Dim str As String = "Hello, world!" Dim lo As New PgSqlLargeObject(connection, oid) lo.Open() If lo.CanWrite Then Dim buffer As Byte() = Encoding.UTF8.GetBytes(str) lo.Write(buffer, 0, buffer.Length) End If lo.Close() Console.WriteLine("Written to the large object : {0}", str) connection.Commit() End Sub Public Sub ReadFromLargeObject(ByVal connection As PgSqlConnection, ByVal oid As Integer) ' All operations with large objects require an active transaction. connection.BeginTransaction() Dim str As String = String.Empty Dim lo As New PgSqlLargeObject(connection, oid) lo.Open() If lo.CanWrite Then Dim buffer As Byte() = New Byte(lo.Length - 1) {} lo.Read(buffer, 0, buffer.Length) str = Encoding.UTF8.GetString(buffer) End If lo.Close() Console.WriteLine("Read from the large object : {0}", str) connection.Commit() End Sub
System.Object
System.MarshalByRefObject
System.IO.Stream
Devart.Data.PostgreSql.PgSqlLargeObject
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2