MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Source for file mssql.php

Documentation is available at mssql.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5                                                 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith, Frank M. Kromann                       |
  8. // | All rights reserved.                                                 |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11. // | API as well as database abstraction for PHP applications.            |
  12. // | This LICENSE is in the BSD license style.                            |
  13. // |                                                                      |
  14. // | Redistribution and use in source and binary forms, with or without   |
  15. // | modification, are permitted provided that the following conditions   |
  16. // | are met:                                                             |
  17. // |                                                                      |
  18. // | Redistributions of source code must retain the above copyright       |
  19. // | notice, this list of conditions and the following disclaimer.        |
  20. // |                                                                      |
  21. // | Redistributions in binary form must reproduce the above copyright    |
  22. // | notice, this list of conditions and the following disclaimer in the  |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // |                                                                      |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission.                                                  |
  29. // |                                                                      |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Frank M. Kromann <frank@kromann.info>                        |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: mssql.php,v 1.68 2005/04/25 13:09:03 lsmith Exp $
  47. //
  48.  
  49. /**
  50.  * MDB2 MSSQL Server driver
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author  Frank M. Kromann <frank@kromann.info>
  55.  */
  56. {
  57.     // {{{ properties
  58.     var $escape_quotes = "'";
  59.  
  60.     // }}}
  61.     // {{{ constructor
  62.  
  63.     /**
  64.      * Constructor
  65.      */
  66.     function __construct()
  67.     {
  68.         parent::__construct();
  69.  
  70.         $this->phptype = 'mssql';
  71.         $this->dbsyntax = 'mssql';
  72.  
  73.         $this->supported['sequences'= true;
  74.         $this->supported['indexes'= true;
  75.         $this->supported['affected_rows'= true;
  76.         $this->supported['transactions'= true;
  77.         $this->supported['summary_functions'= true;
  78.         $this->supported['order_by_text'= true;
  79.         $this->supported['current_id'= false;
  80.         $this->supported['limit_queries'= true;
  81.         $this->supported['LOBs'= true;
  82.         $this->supported['replace'= true;
  83.         $this->supported['sub_selects'= true;
  84.         $this->supported['auto_increment'= true;
  85.  
  86.         $db->options['database_device'= false;
  87.         $db->options['database_size'= false;
  88.     }
  89.  
  90.     // }}}
  91.     // {{{ errorInfo()
  92.  
  93.     /**
  94.      * This method is used to collect information about an error
  95.      *
  96.      * @param integer $error 
  97.      * @return array 
  98.      * @access public
  99.      */
  100.     function errorInfo($error = null)
  101.     {
  102.         $native_code = null;
  103.         if ($this->connection{
  104.             $result @mssql_query('select @@ERROR as ErrorCode'$this->connection);
  105.             if ($result{
  106.                 $native_code @mssql_result($result00);
  107.                 @mssql_free_result($result);
  108.             }
  109.         }
  110.         $native_msg @mssql_get_last_message();
  111.         if (is_null($error)) {
  112.             static $ecode_map;
  113.             if (empty($ecode_map)) {
  114.                 $ecode_map = array(
  115.                     110   => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  116.                     155   => MDB2_ERROR_NOSUCHFIELD,
  117.                     170   => MDB2_ERROR_SYNTAX,
  118.                     207   => MDB2_ERROR_NOSUCHFIELD,
  119.                     208   => MDB2_ERROR_NOSUCHTABLE,
  120.                     245   => MDB2_ERROR_INVALID_NUMBER,
  121.                     515   => MDB2_ERROR_CONSTRAINT_NOT_NULL,
  122.                     547   => MDB2_ERROR_CONSTRAINT,
  123.                     1913  => MDB2_ERROR_ALREADY_EXISTS,
  124.                     2627  => MDB2_ERROR_CONSTRAINT,
  125.                     2714  => MDB2_ERROR_ALREADY_EXISTS,
  126.                     3701  => MDB2_ERROR_NOSUCHTABLE,
  127.                     8134  => MDB2_ERROR_DIVZERO,
  128.                 );
  129.             }
  130.             if (isset($ecode_map[$native_code])) {
  131.                 if ($native_code == 3701
  132.                     && preg_match('/Cannot drop the index/i'$msg)
  133.                 {
  134.                    $error MDB2_ERROR_NOT_FOUND;
  135.                 else {
  136.                     $error $ecode_map[$native_code];
  137.                 }
  138.             }
  139.         }
  140.         return array($error$native_code$native_msg);
  141.     }
  142.  
  143.     // }}}
  144.     // {{{ quoteIdentifier()
  145.  
  146.     /**
  147.      * Quote a string so it can be safely used as a table / column name
  148.      *
  149.      * Quoting style depends on which database driver is being used.
  150.      *
  151.      * @param string $str  identifier name to be quoted
  152.      *
  153.      * @return string  quoted identifier string
  154.      *
  155.      * @since 1.6.0
  156.      * @access public
  157.      */
  158.     function quoteIdentifier($str)
  159.     {
  160.         return '[' str_replace(']'']]'$str']';
  161.     }
  162.  
  163.     // }}}
  164.     // {{{ beginTransaction()
  165.  
  166.     /**
  167.      * Start a transaction.
  168.      *
  169.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  170.      * @access public
  171.      */
  172.     function beginTransaction()
  173.     {
  174.         $this->debug('starting transaction''beginTransaction');
  175.         if ($this->in_transaction{
  176.             return MDB2_OK;  //nothing to do
  177.         }
  178.         if (!$this->destructor_registered && $this->opened_persistent{
  179.             $this->destructor_registered = true;
  180.             register_shutdown_function('MDB2_closeOpenTransactions');
  181.         }
  182.         $result $this->_doQuery('BEGIN TRANSACTION'true);
  183.         if (PEAR::isError($result)) {
  184.             return $result;
  185.         }
  186.         $this->in_transaction = true;
  187.         return MDB2_OK;
  188.     }
  189.  
  190.     // }}}
  191.     // {{{ commit()
  192.  
  193.     /**
  194.      * Commit the database changes done during a transaction that is in
  195.      * progress.
  196.      *
  197.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  198.      * @access public
  199.      */
  200.     function commit()
  201.     {
  202.         $this->debug('commit transaction''commit');
  203.         if (!$this->in_transaction{
  204.             return $this->raiseError(MDB2_ERRORnullnull,
  205.                 'commit: transaction changes are being auto committed');
  206.         }
  207.         $result $this->_doQuery('COMMIT TRANSACTION'true);
  208.         if (PEAR::isError($result)) {
  209.             return $result;
  210.         }
  211.         $this->in_transaction = false;
  212.         return MDB2_OK;
  213.     }
  214.  
  215.     // }}}
  216.     // {{{ rollback()
  217.  
  218.     /**
  219.      * Cancel any database changes done during a transaction that is in
  220.      * progress.
  221.      *
  222.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  223.      * @access public
  224.      */
  225.     function rollback()
  226.     {
  227.         $this->debug('rolling back transaction''rollback');
  228.         if (!$this->in_transaction{
  229.             return $this->raiseError(MDB2_ERRORnullnull,
  230.                 'rollback: transactions can not be rolled back when changes are auto committed');
  231.         }
  232.         $result $this->_doQuery('ROLLBACK TRANSACTION'true);
  233.         if (PEAR::isError($result)) {
  234.             return $result;
  235.         }
  236.         $this->in_transaction = false;
  237.         return MDB2_OK;
  238.     }
  239.  
  240.     // }}}
  241.     // {{{ connect()
  242.  
  243.     /**
  244.      * Connect to the database
  245.      *
  246.      * @return true on success, MDB2 Error Object on failure
  247.      */
  248.     function connect()
  249.     {
  250.         if (is_resource($this->connection)) {
  251.             if (count(array_diff($this->connected_dsn$this->dsn)) == 0
  252.                 && $this->opened_persistent == $this->options['persistent']
  253.             {
  254.                 return MDB2_OK;
  255.             }
  256.             $this->disconnect(false);
  257.         }
  258.  
  259.         if (!PEAR::loadExtension($this->phptype)) {
  260.             return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  261.                 'connect: extension '.$this->phptype.' is not compiled into PHP');
  262.         }
  263.  
  264.         $params = array(
  265.             $this->dsn['hostspec'$this->dsn['hostspec''localhost',
  266.             $this->dsn['username'$this->dsn['username': null,
  267.             $this->dsn['password'$this->dsn['password': null,
  268.         );
  269.         if ($this->dsn['port']{
  270.             $params[0.= ((substr(PHP_OS03== 'WIN'',' ':')
  271.                         . $this->dsn['port'];
  272.         }
  273.  
  274.         $connect_function $this->options['persistent''mssql_pconnect' 'mssql_connect';
  275.  
  276.         $connection @call_user_func_array($connect_function$params);
  277.         if ($connection <= 0{
  278.             return $this->raiseError(MDB2_ERROR_CONNECT_FAILED);
  279.         }
  280.  
  281.         $this->connection = $connection;
  282.         $this->connected_dsn = $this->dsn;
  283.         $this->connected_database_name = '';
  284.         $this->opened_persistent = $this->options['persistent'];
  285.         $this->dbsyntax = $this->dsn['dbsyntax'$this->dsn['dbsyntax'$this->phptype;
  286.  
  287.        if ((bool) ini_get('mssql.datetimeconvert')) {
  288.            ini_set('mssql.datetimeconvert''0');
  289.        }
  290.        @mssql_query('SET DATEFORMAT ymd'$this->connection);
  291.  
  292.         return MDB2_OK;
  293.     }
  294.  
  295.     // }}}
  296.     // {{{ disconnect()
  297.  
  298.     /**
  299.      * Log out and disconnect from the database.
  300.      *
  301.      * @return mixed true on success, false if not connected and error
  302.      *                 object on error
  303.      * @access public
  304.      */
  305.     function disconnect($force = true)
  306.     {
  307.         if (is_resource($this->connection)) {
  308.             if (!$this->opened_persistent || $force{
  309.                 @mssql_close($this->connection);
  310.             }
  311.             $this->connection = 0;
  312.         }
  313.         return MDB2_OK;
  314.     }
  315.  
  316.     // }}}
  317.     // {{{ _doQuery()
  318.  
  319.     /**
  320.      * Execute a query
  321.      * @param string $query  query
  322.      * @param boolean $isManip  if the query is a manipulation query
  323.      * @param resource $connection 
  324.      * @param string $database_name 
  325.      * @return result or error object
  326.      * @access protected
  327.      */
  328.     function _doQuery($query$isManip = false$connection = null$database_name = null)
  329.     {
  330.         $this->last_query = $query;
  331.         $this->debug($query'query');
  332.         if ($this->options['disable_query']{
  333.             if ($isManip{
  334.                 return MDB2_OK;
  335.             }
  336.             return null;
  337.         }
  338.  
  339.         if (is_null($connection)) {
  340.             $error $this->connect();
  341.             if (PEAR::isError($error)) {
  342.                 return $error;
  343.             }
  344.             $connection $this->connection;
  345.         }
  346.         if (is_null($database_name)) {
  347.             $database_name $this->database_name;
  348.         }
  349.  
  350.         if ($database_name{
  351.             if ($database_name != $this->connected_database_name{
  352.                 if (!@mssql_select_db($database_name$connection)) {
  353.                     return $this->raiseError();
  354.                 }
  355.                 $this->connected_database_name = $database_name;
  356.             }
  357.         }
  358.  
  359.         $result @mssql_query($query$connection);
  360.         if (!$result{
  361.             return $this->raiseError();
  362.         }
  363.  
  364.         if ($isManip{
  365.             return @mssql_rows_affected($connection);
  366.         }
  367.         return $result;
  368.     }
  369.  
  370.     // }}}
  371.     // {{{ _modifyQuery()
  372.  
  373.     /**
  374.      * Changes a query string for various DBMS specific reasons
  375.      *
  376.      * @param string $query  query to modify
  377.      * @return the new (modified) query
  378.      * @access protected
  379.      */
  380.     function _modifyQuery($query$isManip$limit$offset)
  381.     {
  382.         if ($limit > 0{
  383.             $fetch $offset $limit;
  384.             if (!$isManip{
  385.                 return preg_replace('/^([\s(])*SELECT(?!\s*TOP\s*\()/i',
  386.                     "\\1SELECT TOP($fetch)"$query);
  387.             }
  388.         }
  389.         return $query;
  390.     }
  391.  
  392.     // }}}
  393.     // {{{ nextID()
  394.  
  395.     /**
  396.      * returns the next free id of a sequence
  397.      *
  398.      * @param string  $seq_name name of the sequence
  399.      * @param boolean $ondemand when true the seqence is
  400.      *                           automatic created, if it
  401.      *                           not exists
  402.      *
  403.      * @return mixed MDB2 Error Object or id
  404.      * @access public
  405.      */
  406.     function nextID($seq_name$ondemand = true)
  407.     {
  408.         $sequence_name $this->getSequenceName($seq_name);
  409.         $query = "INSERT INTO $sequence_name (".$this->options['seqcol_name'].") VALUES (0)";
  410.         $this->expectError(MDB2_ERROR_NOSUCHTABLE);
  411.         $result $this->_doQuery($querytrue);
  412.         $this->popExpect();
  413.         if (PEAR::isError($result)) {
  414.             if ($ondemand && $result->getCode(== MDB2_ERROR_NOSUCHTABLE{
  415.                 $this->loadModule('Manager');
  416.                 // Since we are creating the sequence on demand
  417.                 // we know the first id = 1 so initialize the
  418.                 // sequence at 2
  419.                 $result $this->manager->createSequence($seq_name2);
  420.                 if (PEAR::isError($result)) {
  421.                     return $this->raiseError(MDB2_ERRORnullnull,
  422.                         'nextID: on demand sequence '.$seq_name.' could not be created');
  423.                 else {
  424.                     // First ID of a newly created sequence is 1
  425.                     return 1;
  426.                 }
  427.             }
  428.             return $result;
  429.         }
  430.         $value $this->queryOne("SELECT @@IDENTITY FROM $sequence_name"'integer');
  431.         if (is_numeric($value)) {
  432.             $query = "DELETE FROM $sequence_name WHERE ".$this->options['seqcol_name']." < $value";
  433.             $result $this->_doQuery($querytrue);
  434.             if (PEAR::isError($result)) {
  435.                 $this->warnings['nextID: could not delete previous sequence table values';
  436.             }
  437.         }
  438.         return $value;
  439.     }
  440.  
  441.     // }}}
  442.     // {{{ getAfterID()
  443.  
  444.     /**
  445.      * returns the autoincrement ID if supported or $id
  446.      *
  447.      * @param mixed $id value as returned by getBeforeId()
  448.      * @param string $table name of the table into which a new row was inserted
  449.      * @return mixed MDB2 Error Object or id
  450.      * @access public
  451.      */
  452.     function getAfterID($id$table)
  453.     {
  454.         $this->loadModule('Native');
  455.         return $this->native->getInsertID($table);
  456.     }
  457. }
  458.  
  459. class MDB2_Result_mssql extends MDB2_Result_Common
  460. {
  461.     // {{{ _skipLimitOffset()
  462.  
  463.     /**
  464.      * Skip the first row of a result set.
  465.      *
  466.      * @param resource $result 
  467.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  468.      * @access protected
  469.      */
  470.     function _skipLimitOffset()
  471.     {
  472.         if ($this->limit{
  473.             if ($this->rownum >= $this->limit{
  474.                 return MDB2_ERROR;
  475.             }
  476.         }
  477.         if ($this->offset{
  478.             while ($this->offset_count $this->offset{
  479.                 ++$this->offset_count;
  480.                 if (!is_array(@mysql_fetch_row($this->result))) {
  481.                     $this->offset_count $this->limit;
  482.                     return MDB2_ERROR;
  483.                 }
  484.             }
  485.         }
  486.         return MDB2_OK;
  487.     }
  488.  
  489.     // }}}
  490.     // {{{ fetchRow()
  491.  
  492.     /**
  493.      * Fetch a row and insert the data into an existing array.
  494.      *
  495.      * @param int       $fetchmode  how the array data should be indexed
  496.      * @param int    $rownum    number of the row where the data can be found
  497.      * @return int data array on success, a MDB2 error on failure
  498.      * @access public
  499.      */
  500.     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT$rownum = null)
  501.     {
  502.         if (!$this->_skipLimitOffset()) {
  503.             return null;
  504.         }
  505.         if (!is_null($rownum)) {
  506.             $seek $this->seek($rownum);
  507.             if (PEAR::isError($seek)) {
  508.                 return $seek;
  509.             }
  510.         }
  511.         if ($fetchmode == MDB2_FETCHMODE_DEFAULT{
  512.             $fetchmode $this->db->fetchmode;
  513.         }
  514.         if ($fetchmode MDB2_FETCHMODE_ASSOC{
  515.             $row @mssql_fetch_assoc($this->result);
  516.             if (is_array($row)
  517.                 && $this->db->options['portability'MDB2_PORTABILITY_LOWERCASE
  518.             {
  519.                 $row array_change_key_case($rowCASE_LOWER);
  520.             }
  521.         else {
  522.             $row @mssql_fetch_row($this->result);
  523.         }
  524.         if (!$row{
  525.             if (is_null($this->result)) {
  526.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  527.                     'fetchRow: resultset has already been freed');
  528.             }
  529.             return null;
  530.         }
  531.         if ($this->db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL{
  532.             $this->db->_convertEmptyArrayValuesToNull($row);
  533.         }
  534.         if (isset($this->values)) {
  535.             $this->_assignBindColumns($row);
  536.         }
  537.         if (isset($this->types)) {
  538.             $row $this->db->datatype->convertResultRow($this->types$row);
  539.         }
  540.         if ($fetchmode === MDB2_FETCHMODE_OBJECT{
  541.             $object_class $this->db->options['fetch_class'];
  542.             if ($object_class == 'stdClass'{
  543.                 $row = (object) $row;
  544.             else {
  545.                 $row &new $object_class($row);
  546.             }
  547.         }
  548.         ++$this->rownum;
  549.         return $row;
  550.     }
  551.  
  552.     // }}}
  553.     // {{{ _getColumnNames()
  554.  
  555.     /**
  556.      * Retrieve the names of columns returned by the DBMS in a query result.
  557.      *
  558.      * @param resource $result result identifier
  559.      * @return mixed                an associative array variable
  560.      *                               that will hold the names of columns. The
  561.      *                               indexes of the array are the column names
  562.      *                               mapped to lower case and the values are the
  563.      *                               respective numbers of the columns starting
  564.      *                               from 0. Some DBMS may not return any
  565.      *                               columns when the result set does not
  566.      *                               contain any rows.
  567.      *
  568.      *                               a MDB2 error on failure
  569.      * @access private
  570.      */
  571.     function _getColumnNames()
  572.     {
  573.         $columns = array();
  574.         $numcols $this->numCols();
  575.         if (PEAR::isError($numcols)) {
  576.             return $numcols;
  577.         }
  578.         for ($column = 0; $column $numcols$column++{
  579.             $column_name @mssql_field_name($this->result$column);
  580.             $columns[$column_name$column;
  581.         }
  582.         if ($this->db->options['portability'MDB2_PORTABILITY_LOWERCASE{
  583.             $columns array_change_key_case($columnsCASE_LOWER);
  584.         }
  585.         return $columns;
  586.     }
  587.  
  588.     // }}}
  589.     // {{{ numCols()
  590.  
  591.     /**
  592.      * Count the number of columns returned by the DBMS in a query result.
  593.      *
  594.      * @return mixed integer value with the number of columns, a MDB2 error
  595.      *       on failure
  596.      * @access public
  597.      */
  598.     function numCols()
  599.     {
  600.         $cols @mssql_num_fields($this->result);
  601.         if (is_null($cols)) {
  602.             if (is_null($this->result)) {
  603.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  604.                     'numCols: resultset has already been freed');
  605.             }
  606.             return $this->db->raiseError();
  607.         }
  608.         return $cols;
  609.     }
  610.  
  611.     // }}}
  612.     // {{{ nextResult()
  613.  
  614.     /**
  615.      * Move the internal result pointer to the next available result
  616.      * Currently not supported
  617.      *
  618.      * @return true if a result is available otherwise return false
  619.      * @access public
  620.      */
  621.     function nextResult()
  622.     {
  623.         if (is_null($this->result)) {
  624.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  625.                 'nextResult: resultset has already been freed');
  626.         }
  627.         return @mssql_next_result($this->result);
  628.     }
  629.  
  630.     // }}}
  631.     // {{{ free()
  632.  
  633.     /**
  634.      * Free the internal resources associated with $result.
  635.      *
  636.      * @return boolean true on success, false if $result is invalid
  637.      * @access public
  638.      */
  639.     function free()
  640.     {
  641.         $free @mssql_free_result($this->result);
  642.         if (!$free{
  643.             if (is_null($this->result)) {
  644.                 return MDB2_OK;
  645.             }
  646.             return $this->db->raiseError();
  647.         }
  648.         $this->result = null;
  649.         return MDB2_OK;
  650.     }
  651. }
  652.  
  653. class MDB2_BufferedResult_mssql extends MDB2_Result_mssql
  654. {
  655.     // }}}
  656.     // {{{ seek()
  657.  
  658.     /**
  659.     * seek to a specific row in a result set
  660.     *
  661.     * @param int    $rownum    number of the row where the data can be found
  662.     * @return mixed MDB2_OK on success, a MDB2 error on failure
  663.     * @access public
  664.     */
  665.     function seek($rownum = 0)
  666.     {
  667.         if ($this->rownum != ($rownum - 1&& !@mssql_data_seek($this->result$rownum)) {
  668.             if (is_null($this->result)) {
  669.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  670.                     'seek: resultset has already been freed');
  671.             }
  672.             return $this->db->raiseError(MDB2_ERROR_INVALIDnullnull,
  673.                 'seek: tried to seek to an invalid row number ('.$rownum.')');
  674.         }
  675.         $this->rownum $rownum - 1;
  676.         return MDB2_OK;
  677.     }
  678.  
  679.     // {{{ valid()
  680.  
  681.     /**
  682.      * check if the end of the result set has been reached
  683.      *
  684.      * @return mixed true or false on sucess, a MDB2 error on failure
  685.      * @access public
  686.      */
  687.     function valid()
  688.     {
  689.         $numrows $this->numRows();
  690.         if (PEAR::isError($numrows)) {
  691.             return $numrows;
  692.         }
  693.         return $this->rownum ($numrows - 1);
  694.     }
  695.  
  696.     // }}}
  697.     // {{{ numRows()
  698.  
  699.     /**
  700.      * returns the number of rows in a result object
  701.      *
  702.      * @return mixed MDB2 Error Object or the number of rows
  703.      * @access public
  704.      */
  705.     function numRows()
  706.     {
  707.         $rows @mssql_num_rows($this->result);
  708.         if (is_null($rows)) {
  709.             if (is_null($this->result)) {
  710.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  711.                     'numRows: resultset has already been freed');
  712.             }
  713.             return $this->raiseError();
  714.         }
  715.         if ($this->limit{
  716.             $rows -= $this->limit;
  717.             if ($rows < 0{
  718.                 $rows = 0;
  719.             }
  720.         }
  721.         return $rows;
  722.     }
  723. }
  724.  
  725. class MDB2_Statement_mssql extends MDB2_Statement_Common
  726. {
  727.  
  728. }
  729.  
  730. ?>

Documentation generated on Mon, 11 Mar 2019 14:20:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.