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.69 2005/06/06 09:28:43 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. class MDB2_Driver_mssql extends MDB2_Driver_Common
  57. {
  58.     // {{{ properties
  59.     var $escape_quotes = "'";
  60.  
  61.     // }}}
  62.     // {{{ constructor
  63.  
  64.     /**
  65.      * Constructor
  66.      */
  67.     function __construct()
  68.     {
  69.         parent::__construct();
  70.  
  71.         $this->phptype 'mssql';
  72.         $this->dbsyntax 'mssql';
  73.  
  74.         $this->supported['sequences'= true;
  75.         $this->supported['indexes'= true;
  76.         $this->supported['affected_rows'= true;
  77.         $this->supported['transactions'= true;
  78.         $this->supported['summary_functions'= true;
  79.         $this->supported['order_by_text'= true;
  80.         $this->supported['current_id'= false;
  81.         $this->supported['limit_queries'= true;
  82.         $this->supported['LOBs'= true;
  83.         $this->supported['replace'= true;
  84.         $this->supported['sub_selects'= true;
  85.         $this->supported['auto_increment'= true;
  86.  
  87.         $this->options['database_device'= false;
  88.         $this->options['database_size'= false;
  89.     }
  90.  
  91.     // }}}
  92.     // {{{ errorInfo()
  93.  
  94.     /**
  95.      * This method is used to collect information about an error
  96.      *
  97.      * @param integer $error 
  98.      * @return array 
  99.      * @access public
  100.      */
  101.     function errorInfo($error = null)
  102.     {
  103.         $native_code = null;
  104.         if ($this->connection{
  105.             $result @mssql_query('select @@ERROR as ErrorCode'$this->connection);
  106.             if ($result{
  107.                 $native_code @mssql_result($result00);
  108.                 @mssql_free_result($result);
  109.             }
  110.         }
  111.         $native_msg @mssql_get_last_message();
  112.         if (is_null($error)) {
  113.             static $ecode_map;
  114.             if (empty($ecode_map)) {
  115.                 $ecode_map = array(
  116.                     110   => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  117.                     155   => MDB2_ERROR_NOSUCHFIELD,
  118.                     170   => MDB2_ERROR_SYNTAX,
  119.                     207   => MDB2_ERROR_NOSUCHFIELD,
  120.                     208   => MDB2_ERROR_NOSUCHTABLE,
  121.                     245   => MDB2_ERROR_INVALID_NUMBER,
  122.                     515   => MDB2_ERROR_CONSTRAINT_NOT_NULL,
  123.                     547   => MDB2_ERROR_CONSTRAINT,
  124.                     1913  => MDB2_ERROR_ALREADY_EXISTS,
  125.                     2627  => MDB2_ERROR_CONSTRAINT,
  126.                     2714  => MDB2_ERROR_ALREADY_EXISTS,
  127.                     3701  => MDB2_ERROR_NOSUCHTABLE,
  128.                     8134  => MDB2_ERROR_DIVZERO,
  129.                 );
  130.             }
  131.             if (isset($ecode_map[$native_code])) {
  132.                 if ($native_code == 3701
  133.                     && preg_match('/Cannot drop the index/i'$msg)
  134.                 {
  135.                    $error = MDB2_ERROR_NOT_FOUND;
  136.                 else {
  137.                     $error $ecode_map[$native_code];
  138.                 }
  139.             }
  140.         }
  141.         return array($error$native_code$native_msg);
  142.     }
  143.  
  144.     // }}}
  145.     // {{{ quoteIdentifier()
  146.  
  147.     /**
  148.      * Quote a string so it can be safely used as a table / column name
  149.      *
  150.      * Quoting style depends on which database driver is being used.
  151.      *
  152.      * @param string $str  identifier name to be quoted
  153.      *
  154.      * @return string  quoted identifier string
  155.      *
  156.      * @since 1.6.0
  157.      * @access public
  158.      */
  159.     function quoteIdentifier($str)
  160.     {
  161.         return '[' str_replace(']'']]'$str']';
  162.     }
  163.  
  164.     // }}}
  165.     // {{{ beginTransaction()
  166.  
  167.     /**
  168.      * Start a transaction.
  169.      *
  170.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  171.      * @access public
  172.      */
  173.     function beginTransaction()
  174.     {
  175.         $this->debug('starting transaction''beginTransaction');
  176.         if ($this->in_transaction{
  177.             return MDB2_OK;  //nothing to do
  178.         }
  179.         if (!$this->destructor_registered && $this->opened_persistent{
  180.             $this->destructor_registered = true;
  181.             register_shutdown_function('MDB2_closeOpenTransactions');
  182.         }
  183.         $result $this->_doQuery('BEGIN TRANSACTION'true);
  184.         if (PEAR::isError($result)) {
  185.             return $result;
  186.         }
  187.         $this->in_transaction = true;
  188.         return MDB2_OK;
  189.     }
  190.  
  191.     // }}}
  192.     // {{{ commit()
  193.  
  194.     /**
  195.      * Commit the database changes done during a transaction that is in
  196.      * progress.
  197.      *
  198.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  199.      * @access public
  200.      */
  201.     function commit()
  202.     {
  203.         $this->debug('commit transaction''commit');
  204.         if (!$this->in_transaction{
  205.             return $this->raiseError(MDB2_ERRORnullnull,
  206.                 'commit: transaction changes are being auto committed');
  207.         }
  208.         $result $this->_doQuery('COMMIT TRANSACTION'true);
  209.         if (PEAR::isError($result)) {
  210.             return $result;
  211.         }
  212.         $this->in_transaction = false;
  213.         return MDB2_OK;
  214.     }
  215.  
  216.     // }}}
  217.     // {{{ rollback()
  218.  
  219.     /**
  220.      * Cancel any database changes done during a transaction that is in
  221.      * progress.
  222.      *
  223.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  224.      * @access public
  225.      */
  226.     function rollback()
  227.     {
  228.         $this->debug('rolling back transaction''rollback');
  229.         if (!$this->in_transaction{
  230.             return $this->raiseError(MDB2_ERRORnullnull,
  231.                 'rollback: transactions can not be rolled back when changes are auto committed');
  232.         }
  233.         $result $this->_doQuery('ROLLBACK TRANSACTION'true);
  234.         if (PEAR::isError($result)) {
  235.             return $result;
  236.         }
  237.         $this->in_transaction = false;
  238.         return MDB2_OK;
  239.     }
  240.  
  241.     // }}}
  242.     // {{{ connect()
  243.  
  244.     /**
  245.      * Connect to the database
  246.      *
  247.      * @return true on success, MDB2 Error Object on failure
  248.      */
  249.     function connect()
  250.     {
  251.         if (is_resource($this->connection)) {
  252.             if (count(array_diff($this->connected_dsn$this->dsn)) == 0
  253.                 && $this->opened_persistent == $this->options['persistent']
  254.             {
  255.                 return MDB2_OK;
  256.             }
  257.             $this->disconnect(false);
  258.         }
  259.  
  260.         if (!PEAR::loadExtension($this->phptype)) {
  261.             return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  262.                 'connect: extension '.$this->phptype.' is not compiled into PHP');
  263.         }
  264.  
  265.         $params = array(
  266.             $this->dsn['hostspec'$this->dsn['hostspec''localhost',
  267.             $this->dsn['username'$this->dsn['username': null,
  268.             $this->dsn['password'$this->dsn['password': null,
  269.         );
  270.         if ($this->dsn['port']{
  271.             $params[0.= ((substr(PHP_OS03== 'WIN'',' ':')
  272.                         . $this->dsn['port'];
  273.         }
  274.  
  275.         $connect_function $this->options['persistent''mssql_pconnect' 'mssql_connect';
  276.  
  277.         $connection @call_user_func_array($connect_function$params);
  278.         if ($connection <= 0{
  279.             return $this->raiseError(MDB2_ERROR_CONNECT_FAILED);
  280.         }
  281.  
  282.         $this->connection $connection;
  283.         $this->connected_dsn $this->dsn;
  284.         $this->connected_database_name '';
  285.         $this->opened_persistent $this->options['persistent'];
  286.         $this->dbsyntax $this->dsn['dbsyntax'$this->dsn['dbsyntax'$this->phptype;
  287.  
  288.        if ((bool) ini_get('mssql.datetimeconvert')) {
  289.            ini_set('mssql.datetimeconvert''0');
  290.        }
  291.        @mssql_query('SET DATEFORMAT ymd'$this->connection);
  292.  
  293.         return MDB2_OK;
  294.     }
  295.  
  296.     // }}}
  297.     // {{{ disconnect()
  298.  
  299.     /**
  300.      * Log out and disconnect from the database.
  301.      *
  302.      * @return mixed true on success, false if not connected and error
  303.      *                 object on error
  304.      * @access public
  305.      */
  306.     function disconnect($force = true)
  307.     {
  308.         if (is_resource($this->connection)) {
  309.             if (!$this->opened_persistent || $force{
  310.                 @mssql_close($this->connection);
  311.             }
  312.             $this->connection = 0;
  313.         }
  314.         return MDB2_OK;
  315.     }
  316.  
  317.     // }}}
  318.     // {{{ _doQuery()
  319.  
  320.     /**
  321.      * Execute a query
  322.      * @param string $query  query
  323.      * @param boolean $isManip  if the query is a manipulation query
  324.      * @param resource $connection 
  325.      * @param string $database_name 
  326.      * @return result or error object
  327.      * @access protected
  328.      */
  329.     function _doQuery($query$isManip = false$connection = null$database_name = null)
  330.     {
  331.         $this->last_query $query;
  332.         $this->debug($query'query');
  333.         if ($this->options['disable_query']{
  334.             if ($isManip{
  335.                 return MDB2_OK;
  336.             }
  337.             return null;
  338.         }
  339.  
  340.         if (is_null($connection)) {
  341.             $error $this->connect();
  342.             if (PEAR::isError($error)) {
  343.                 return $error;
  344.             }
  345.             $connection $this->connection;
  346.         }
  347.         if (is_null($database_name)) {
  348.             $database_name $this->database_name;
  349.         }
  350.  
  351.         if ($database_name{
  352.             if ($database_name != $this->connected_database_name{
  353.                 if (!@mssql_select_db($database_name$connection)) {
  354.                     return $this->raiseError();
  355.                 }
  356.                 $this->connected_database_name $database_name;
  357.             }
  358.         }
  359.  
  360.         $result @mssql_query($query$connection);
  361.         if (!$result{
  362.             return $this->raiseError();
  363.         }
  364.  
  365.         if ($isManip{
  366.             return @mssql_rows_affected($connection);
  367.         }
  368.         return $result;
  369.     }
  370.  
  371.     // }}}
  372.     // {{{ _modifyQuery()
  373.  
  374.     /**
  375.      * Changes a query string for various DBMS specific reasons
  376.      *
  377.      * @param string $query  query to modify
  378.      * @return the new (modified) query
  379.      * @access protected
  380.      */
  381.     function _modifyQuery($query$isManip$limit$offset)
  382.     {
  383.         if ($limit > 0{
  384.             $fetch $offset $limit;
  385.             if (!$isManip{
  386.                 return preg_replace('/^([\s(])*SELECT(?!\s*TOP\s*\()/i',
  387.                     "\\1SELECT TOP($fetch)"$query);
  388.             }
  389.         }
  390.         return $query;
  391.     }
  392.  
  393.     // }}}
  394.     // {{{ nextID()
  395.  
  396.     /**
  397.      * returns the next free id of a sequence
  398.      *
  399.      * @param string  $seq_name name of the sequence
  400.      * @param boolean $ondemand when true the seqence is
  401.      *                           automatic created, if it
  402.      *                           not exists
  403.      *
  404.      * @return mixed MDB2 Error Object or id
  405.      * @access public
  406.      */
  407.     function nextID($seq_name$ondemand = true)
  408.     {
  409.         $sequence_name $this->getSequenceName($seq_name);
  410.         $query = "INSERT INTO $sequence_name (".$this->options['seqcol_name'].") VALUES (0)";
  411.         $this->expectError(MDB2_ERROR_NOSUCHTABLE);
  412.         $result $this->_doQuery($querytrue);
  413.         $this->popExpect();
  414.         if (PEAR::isError($result)) {
  415.             if ($ondemand && $result->getCode(== MDB2_ERROR_NOSUCHTABLE{
  416.                 $this->loadModule('Manager');
  417.                 // Since we are creating the sequence on demand
  418.                 // we know the first id = 1 so initialize the
  419.                 // sequence at 2
  420.                 $result $this->manager->createSequence($seq_name2);
  421.                 if (PEAR::isError($result)) {
  422.                     return $this->raiseError(MDB2_ERRORnullnull,
  423.                         'nextID: on demand sequence '.$seq_name.' could not be created');
  424.                 else {
  425.                     // First ID of a newly created sequence is 1
  426.                     return 1;
  427.                 }
  428.             }
  429.             return $result;
  430.         }
  431.         $value $this->queryOne("SELECT @@IDENTITY FROM $sequence_name"'integer');
  432.         if (is_numeric($value)) {
  433.             $query = "DELETE FROM $sequence_name WHERE ".$this->options['seqcol_name']." < $value";
  434.             $result $this->_doQuery($querytrue);
  435.             if (PEAR::isError($result)) {
  436.                 $this->warnings['nextID: could not delete previous sequence table values';
  437.             }
  438.         }
  439.         return $value;
  440.     }
  441.  
  442.     // }}}
  443.     // {{{ getAfterID()
  444.  
  445.     /**
  446.      * returns the autoincrement ID if supported or $id
  447.      *
  448.      * @param mixed $id value as returned by getBeforeId()
  449.      * @param string $table name of the table into which a new row was inserted
  450.      * @return mixed MDB2 Error Object or id
  451.      * @access public
  452.      */
  453.     function getAfterID($id$table)
  454.     {
  455.         $this->loadModule('Native');
  456.         return $this->native->getInsertID($table);
  457.     }
  458. }
  459.  
  460. class MDB2_Result_mssql extends MDB2_Result_Common
  461. {
  462.     // {{{ _skipLimitOffset()
  463.  
  464.     /**
  465.      * Skip the first row of a result set.
  466.      *
  467.      * @param resource $result 
  468.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  469.      * @access protected
  470.      */
  471.     function _skipLimitOffset()
  472.     {
  473.         if ($this->limit{
  474.             if ($this->rownum >= $this->limit{
  475.                 return MDB2_ERROR;
  476.             }
  477.         }
  478.         if ($this->offset{
  479.             while ($this->offset_count $this->offset{
  480.                 ++$this->offset_count;
  481.                 if (!is_array(@mysql_fetch_row($this->result))) {
  482.                     $this->offset_count $this->limit;
  483.                     return MDB2_ERROR;
  484.                 }
  485.             }
  486.         }
  487.         return MDB2_OK;
  488.     }
  489.  
  490.     // }}}
  491.     // {{{ fetchRow()
  492.  
  493.     /**
  494.      * Fetch a row and insert the data into an existing array.
  495.      *
  496.      * @param int       $fetchmode  how the array data should be indexed
  497.      * @param int    $rownum    number of the row where the data can be found
  498.      * @return int data array on success, a MDB2 error on failure
  499.      * @access public
  500.      */
  501.     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT$rownum = null)
  502.     {
  503.         if (!$this->_skipLimitOffset()) {
  504.             return null;
  505.         }
  506.         if (!is_null($rownum)) {
  507.             $seek $this->seek($rownum);
  508.             if (PEAR::isError($seek)) {
  509.                 return $seek;
  510.             }
  511.         }
  512.         if ($fetchmode == MDB2_FETCHMODE_DEFAULT{
  513.             $fetchmode $this->db->fetchmode;
  514.         }
  515.         if ($fetchmode MDB2_FETCHMODE_ASSOC{
  516.             $row @mssql_fetch_assoc($this->result);
  517.             if (is_array($row)
  518.                 && $this->db->options['portability'MDB2_PORTABILITY_LOWERCASE
  519.             {
  520.                 $row array_change_key_case($rowCASE_LOWER);
  521.             }
  522.         else {
  523.             $row @mssql_fetch_row($this->result);
  524.         }
  525.         if (!$row{
  526.             if (is_null($this->result)) {
  527.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  528.                     'fetchRow: resultset has already been freed');
  529.             }
  530.             return null;
  531.         }
  532.         if ($this->db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL{
  533.             $this->db->_convertEmptyArrayValuesToNull($row);
  534.         }
  535.         if (isset($this->values)) {
  536.             $this->_assignBindColumns($row);
  537.         }
  538.         if (isset($this->types)) {
  539.             $row $this->db->datatype->convertResultRow($this->types$row);
  540.         }
  541.         if ($fetchmode === MDB2_FETCHMODE_OBJECT{
  542.             $object_class $this->db->options['fetch_class'];
  543.             if ($object_class == 'stdClass'{
  544.                 $row = (object) $row;
  545.             else {
  546.                 $row &new $object_class($row);
  547.             }
  548.         }
  549.         ++$this->rownum;
  550.         return $row;
  551.     }
  552.  
  553.     // }}}
  554.     // {{{ _getColumnNames()
  555.  
  556.     /**
  557.      * Retrieve the names of columns returned by the DBMS in a query result.
  558.      *
  559.      * @param resource $result result identifier
  560.      * @return mixed                an associative array variable
  561.      *                               that will hold the names of columns. The
  562.      *                               indexes of the array are the column names
  563.      *                               mapped to lower case and the values are the
  564.      *                               respective numbers of the columns starting
  565.      *                               from 0. Some DBMS may not return any
  566.      *                               columns when the result set does not
  567.      *                               contain any rows.
  568.      *
  569.      *                               a MDB2 error on failure
  570.      * @access private
  571.      */
  572.     function _getColumnNames()
  573.     {
  574.         $columns = array();
  575.         $numcols $this->numCols();
  576.         if (PEAR::isError($numcols)) {
  577.             return $numcols;
  578.         }
  579.         for ($column = 0; $column $numcols$column++{
  580.             $column_name @mssql_field_name($this->result$column);
  581.             $columns[$column_name$column;
  582.         }
  583.         if ($this->db->options['portability'MDB2_PORTABILITY_LOWERCASE{
  584.             $columns array_change_key_case($columnsCASE_LOWER);
  585.         }
  586.         return $columns;
  587.     }
  588.  
  589.     // }}}
  590.     // {{{ numCols()
  591.  
  592.     /**
  593.      * Count the number of columns returned by the DBMS in a query result.
  594.      *
  595.      * @return mixed integer value with the number of columns, a MDB2 error
  596.      *       on failure
  597.      * @access public
  598.      */
  599.     function numCols()
  600.     {
  601.         $cols @mssql_num_fields($this->result);
  602.         if (is_null($cols)) {
  603.             if (is_null($this->result)) {
  604.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  605.                     'numCols: resultset has already been freed');
  606.             }
  607.             return $this->db->raiseError();
  608.         }
  609.         return $cols;
  610.     }
  611.  
  612.     // }}}
  613.     // {{{ nextResult()
  614.  
  615.     /**
  616.      * Move the internal result pointer to the next available result
  617.      * Currently not supported
  618.      *
  619.      * @return true if a result is available otherwise return false
  620.      * @access public
  621.      */
  622.     function nextResult()
  623.     {
  624.         if (is_null($this->result)) {
  625.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  626.                 'nextResult: resultset has already been freed');
  627.         }
  628.         return @mssql_next_result($this->result);
  629.     }
  630.  
  631.     // }}}
  632.     // {{{ free()
  633.  
  634.     /**
  635.      * Free the internal resources associated with $result.
  636.      *
  637.      * @return boolean true on success, false if $result is invalid
  638.      * @access public
  639.      */
  640.     function free()
  641.     {
  642.         $free @mssql_free_result($this->result);
  643.         if (!$free{
  644.             if (is_null($this->result)) {
  645.                 return MDB2_OK;
  646.             }
  647.             return $this->db->raiseError();
  648.         }
  649.         $this->result = null;
  650.         return MDB2_OK;
  651.     }
  652. }
  653.  
  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:19:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.