SybResult class

index

# SybResult

This class represents a Sybase result set, which is usually generated by executing the sql method of SybSQL.

### Included Modules

- SybConstant

### Class Method

new(restype, rowset=nil)
  Rreturns a newly created result set object.

  Parameters:

  - restype
    The parameter restype indicates the type of result. the following table lists the possible value of restype.

    CS_CMD_SUCCEED | The success of a command that returns no data
    CS_CMD_DONE | The results of a command have been completely processed.
    CS_CMD_FAIL | The server encountered an error while executing a command
    CS_ROW_RESULT | Regular row results
    CS_PARAM_RESULT | Parameter results
    CS_STATUS_RESULT | Stored procedure return status results.
    CS_COMPUTE_RESULT | Compute row results

    These CS_XXX_XXXXX constants is defined in SybConstant module.

  - rowset
    Sets row results.
  - rowset[0] -- An array of column names.
  - rowset[1] -- Row datas as an array of array

### Methods

restype
  Returns result type (CS_ROW_RESULT, CS_CMD_FAIL etc. ).

rows
  Returns row results as Array of Array.

  If the result type is neither CS_ROW_RESULT,CS_PARAM_RESULT, CS_STATUS_RESULT nor CS_COMPUTE_RESULT, then it returns nil

columns
  Returns an array of column names

  If the result type is neither CS_ROW_RESULT nor CS_PARAM_RESULT, then it returns nil

nthrow( nth, clm=nil )
  - If clm was omitted,
    It returns the nth row results array.

  - If clm was specified to a kind of Numeric object,
    It returns a data value at the specified row number and column number.
    nth signifies row number. and , clm signifies column number.

  - If clm was specified to a kind of String object,
    It returns a data value at the specified row number and column name.
    nth signifies row number. and , clm signifies column name.

  Examples

        ## exec sp_who ##
        query.sql("sp_who")

        ## gets the first row result ##
        res=query.top_row_result  # res is a SybResult object

        ## print column names. ##
        print res.columns.join(','),"\n"
         -->
           spid,status,loginame,hostname,blk,dbname,cmd

        ## print row data ##
        res.rows.each{|r| print r.join(','), "\n"}
         -->
          1,running     ,sa          ,          ,0    ,master    ,SELECT
          2,sleeping    ,,          ,0    ,master    ,NETWORK HANDLER
          3,sleeping    ,,          ,0    ,master    ,DEADLOCK TUNE
          4,sleeping    ,,          ,0    ,master    ,MIRROR HANDLER
          5,sleeping    ,,          ,0    ,master    ,HOUSEKEEPER
          6,sleeping    ,,          ,0    ,master    ,CHECKPOINT SLEEP

        ## using column number ##
        print res.nthrow(0,1),"\n"
         -->
          "running     "

        ## Using column name ##
        print res.nthrow(5,"cmd"),"\n"
         -->
          "CHECKPOINT SLEEP"

tran_state
  Returns the current server transaction state.

  Returns:

  - SybConstant::CS_TRAN_IN_PROGRESS
    A transaction is progress.
  - SybConstant::CS_TRAN_COMPLETED
    The most recent transaction completed successfully.
  - SybConstant::CS_TRAN_FAIL
    The most recent transaction failed
  - SybConstant::CS_TRAN_STMT_FAIL
    The most recent transaction failed
  - SybConstant::CS_TRAN_UNDEFINED
    A transaction state is not defined.

row_count
  Returns the number of rows affected by the command.