PGResult

public final class PGResult

Undocumented

  • The result pointer

    Declaration

    Swift

    let pgResult: OpaquePointer
  • Init with an valid result pointer

    Declaration

    Swift

    public init(result: OpaquePointer)
  • Frees the storage associated with a PGresult.

    Declaration

    Swift

    deinit
  • Frees the storage associated with a PGresult.

    You can keep a PGresult object around for as long as you need it; it does not go away when you issue a new command, nor even if you close the connection. To get rid of it, you must call PQclear. Failure to do this will result in memory leaks in your application.

    Declaration

    Swift

    private func clear()
  • Raw result status of the command

    Declaration

    Swift

    public lazy var rawStatus: ExecStatusType =
  • Result status of the command

    Declaration

    Swift

    public lazy var status: PGResultStatus? =
  • Readable result status of the command

    Declaration

    Swift

    public lazy var statusString: String? =
  • Error message associated with the command, or nil if there was no error or the returned error message is empty.

    If there was an error, the returned string will include a trailing newline.

    Declaration

    Swift

    public lazy var errorMessage: String? =
  • Number of rows (tuples) in the query result.

    Declaration

    Swift

    public lazy var numberOfRows: Int32 =
  • Number of columns (fields) in each row of the query result.

    Declaration

    Swift

    public lazy var numberOfColumns: Int32 =
  • Returns the column name associated with the given column number.

    Column numbers start at 0. The caller should not free the result directly. nil is returned if the column number is out of range.

    Declaration

    Swift

    public func columnName(columnNumber: Int32) -> String?
  • Returns the column number associated with the given column name.

    -1 is returned if the given name does not match any column.

    The given name is treated like an identifier in an SQL command, that is, it is downcased unless double-quoted. For example, given a query result generated from the SQL command:

    SELECT 1 AS FOO, 2 AS "BAR";

    we would have the results:

    columnName(0) -> foo

    columnName(1) -> BAR

    columnNumber("FOO") -> 0

    columnNumber("foo") -> 0

    columnNumber("BAR") -> -1

    columnNumber("\"BAR\"") -> 1

    Declaration

    Swift

    public func columnNumber(columnName: String) -> Int32
  • Returns the OID of the table from which the given column was fetched.

    Column numbers start at 0. InvalidOid is returned if the column number is out of range, or if the specified column is not a simple reference to a table column, or when using pre-3.0 protocol. You can query the system table pg_class to determine exactly which table is referenced.

    Declaration

    Swift

    public func columnOid(columnNumber: Int32) -> Oid
  • Returns the column number (within its table) of the column making up the specified query result column.

    Query-result column numbers start at 0, but table columns have nonzero numbers. Zero is returned if the column number is out of range, or if the specified column is not a simple reference to a table column, or when using pre-3.0 protocol.

    Declaration

    Swift

    public func tableColumnNumber(columnNumber: Int32) -> Int32
  • Returns the format code indicating the format of the given column.

    Column numbers start at 0. Format code zero indicates textual data representation, while format code one indicates binary representation. (Other codes are reserved for future definition.)

    Declaration

    Swift

    public func formatCode(columnNumber: Int32) -> Int32
  • Returns the data type associated with the given column number.

    The integer returned is the internal OID number of the type. Column numbers start at 0. You can query the system table pg_type to obtain the names and properties of the various data types. The OIDs of the built-in data types are defined in the file src/include/catalog/pg_type.h in the source tree.

    Declaration

    Swift

    public func dataType(columnNumber: Int32) -> Oid
  • Returns the type modifier of the column associated with the given column number.

    Column numbers start at 0. The interpretation of modifier values is type-specific; they typically indicate precision or size limits. The value -1 is used to indicate “no information available”. Most data types do not use modifiers, in which case the value is always -1.

    Declaration

    Swift

    public func typeModifier(columnNumber: Int32) -> Int32
  • Returns the size in bytes of the column associated with the given column number.

    Column numbers start at 0. PQfsize returns the space allocated for this column in a database row, in other words the size of the server’s internal representation of the data type. (Accordingly, it is not really very useful to clients.) A negative value indicates the data type is variable-length.

    Declaration

    Swift

    public func columnSize(columnNumber: Int32) -> Int32
  • Returns a single field value of one row of a PGresult.

    Row and column numbers start at 0.

    nil is returned if the field value is null. See getIsNil() to distinguish null values from empty-string values.

    Declaration

    Swift

    private func value(rowNumber: Int32, columnNumber: Int32) -> UnsafeMutablePointer<Int8>?
  • Undocumented

    Declaration

    Swift

    public func stringValue(rowNumber row: Int32, columnNumber column: Int32) -> String?
  • Tests a field for a null value.

    Row and column numbers start at 0. This function returns true if the field is nil and false if it contains a non-null value. (Note that value() will return an empty string, not nil, for a nil field.)

    Declaration

    Swift

    public func isNil(rowNumber: Int32, columnNumber: Int32) -> Bool
  • Returns the actual length of a field value in bytes.

    Row and column numbers start at 0. This is the actual data length for the particular data value, that is, the size of the object pointed to by value(). For text data format this is the same as strlen(). For binary format this is essential information. Note that one should not rely on columnSize() to obtain the actual data length.

    Declaration

    Swift

    public func length(rowNumber: Int32, columnNumber: Int32) -> Int32
  • Number of parameters of a prepared statement.

    This property is only useful when inspecting the result of describePrepared(). For other types of queries it will return zero.

    Declaration

    Swift

    public lazy var numberOfParameter: Int32 =
  • Returns the data type of the indicated statement parameter.

    Parameter numbers start at 0. This function is only useful when inspecting the result of describePrepared(). For other types of queries it will return zero.

    Declaration

    Swift

    public func dataType(parameterNumber: Int32) -> Oid