dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlAttribute Class
Members Example

In This Topic
    PgSqlAttribute Class
    In This Topic
    Represents PostgreSQL column in a composite type.
    Syntax
    'Declaration
     
    Public Class PgSqlAttribute 
    public class PgSqlAttribute 
    Remarks
    Use PgSqlAttribute to handle columns in PostgreSQL composite types. To obtain the attribute use items of PgSqlAttributeCollection, which in turn can be obtained with PgSqlRowType.Attributes property. To get a value that corresponds to the attribute use one of the PgSqlRow.Item methods.

    For detailed information on PostgreSQL composite types and how they are treated in dotConnect for PostgreSQL refer to article Working with Composite Types.

    Example
    This sample demonstrates usage of PgSqlRow, PgSqlRowType, PgSqlAttribute, and PgSqlAttributeCollection classes. It retrieves data from a column of composite type in a table and renders the data to console. To run the samples successfully you have to create server objects with the following script: CREATE TYPE tperson AS (name text, age integer); CREATE TABLE personnel (id integer, person tperson);
    static void ReadData(PgSqlConnection conn)  
    { 
      string str = "SELECT person FROM personnel"; 
      PgSqlCommand pgCommand = new PgSqlCommand(str,conn); 
      PgSqlDataReader pgReader = pgCommand.ExecuteReader(); 
      while (pgReader.Read())  
      { 
        //obtain data
        PgSqlRow pgRow = pgReader.GetPgSqlRow(0);
        if (pgRow == null) 
        {
          Console.WriteLine();
          continue;
        }
        //obtain data description
        PgSqlRowType pgRowType = pgRow.RowType;
        //iterate through all columns
        foreach(PgSqlAttribute pgAttr in pgRowType.Attributes)
        {
          Console.Write(pgRow[pgAttr] + "\t"); 
        }
        Console.WriteLine();
      } 
      pgReader.Close(); 
    }
    Sub ReadData(ByVal conn As PgSqlConnection)
      Dim str As String = "SELECT person FROM personnel"
      Dim pgCommand As PgSqlCommand = New PgSqlCommand(str, conn)
      Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader()
      While pgReader.Read()
        'obtain data
        Dim pgRow As PgSqlRow = pgReader.GetPgSqlRow(0)
        If pgRow Is Nothing Then
          Console.WriteLine()
        Else
          'obtain data description
          Dim pgRowType As PgSqlRowType = pgRow.RowType
          'iterate through all columns
          For Each pgAttr As PgSqlAttribute In pgRowType.Attributes
            Console.Write(pgRow(pgAttr) & Chr(9))
          Next pgAttr
          Console.WriteLine()
        End If
      End While
      pgReader.Close()
    End Sub
    Inheritance Hierarchy

    System.Object
       Devart.Data.PostgreSql.PgSqlAttribute

    Requirements

    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

    See Also