MSSQLCallableStatement Class Reference

Inheritance diagram for MSSQLCallableStatement:

MSSQLPreparedStatement CallableStatement PreparedStatementCommon PreparedStatement PreparedStatement

List of all members.

Public Member Functions

 __construct (Connection $conn, $stmt)
 Construct new MSSQLCallableStatement.
 getResource ()
 close ()
 executeQuery ($p1=null, $fetchmode=null)
 getMoreResults ()
 registerOutParameter ($paramIndex, $sqlType, $maxLength=null)
 setArray ($paramIndex, $value, $out=false)
 setBoolean ($paramIndex, $value, $out=false)
 setBlob ($paramIndex, $blob, $out=false)
 setClob ($paramIndex, $clob, $out=false)
 setDate ($paramIndex, $value, $out=false)
 setFloat ($paramIndex, $value, $out=false)
 setInt ($paramIndex, $value, $out=false)
 setNull ($paramIndex)
 setString ($paramIndex, $value, $out=false)
 setTime ($paramIndex, $value, $out=false)
 setTimestamp ($paramIndex, $value, $out=false)
 getArray ($paramIndex)
 getBoolean ($paramIndex)
 getBlob ($paramIndex)
 getClob ($paramIndex)
 getDate ($paramIndex, $fmt= '%Y-%m-%d')
 getFloat ($paramIndex)
 getInt ($paramIndex)
 getString ($paramIndex)
 getTime ($paramIndex, $format='%X')
 getTimestamp ($paramIndex, $format= 'Y-m-d H:i:s')

Private Attributes

 $boundOutVars = array()
 Output variables.
 $stmt
 $result

Static Private Attributes

static $typeMap


Detailed Description

Definition at line 42 of file MSSQLCallableStatement.php.


Constructor & Destructor Documentation

MSSQLCallableStatement::__construct ( Connection conn,
stmt 
)

Construct new MSSQLCallableStatement.

Parameters:
Connection $conn
resource $stmt

Reimplemented from PreparedStatementCommon.

Definition at line 89 of file MSSQLCallableStatement.php.

References $stmt.

00090     {
00091         print " - > IN CONSTRUCTOR \n";
00092         $this->conn = $conn;
00093         $this->stmt = $stmt;
00094     }   


Member Function Documentation

MSSQLCallableStatement::close (  ) 

See also:
CallableStatement::close()

Reimplemented from PreparedStatementCommon.

Definition at line 107 of file MSSQLCallableStatement.php.

00108     {
00109         @mssql_free_statement($this->stmt);
00110         $this->rsFetchCount = 0;
00111     }

MSSQLCallableStatement::executeQuery ( p1 = null,
fetchmode = null 
)

See also:
CallableStatement::executeQuery()

Reimplemented from MSSQLPreparedStatement.

Definition at line 116 of file MSSQLCallableStatement.php.

00117     {
00118         $params = null;
00119         if ($fetchmode !== null) {
00120             $params = $p1;
00121         } elseif ($p1 !== null) {
00122             if (is_array($p1)) $params = $p1;
00123             else $fetchmode = $p1;
00124         }
00125         
00126         if ($params) {
00127             for($i=0,$cnt=count($params); $i < $cnt; $i++) {
00128                 $this->set($i+1, $params[$i]);
00129             }
00130         }                
00131         
00132         $this->result = mssql_execute($this->stmt);
00133         if (!$this->result) {
00134             throw new SQLException('unable to execute callable statement', mssql_get_last_message());
00135         }
00136         
00137         return new MSSQLResultSet($this->conn, $this->result, $fetchmode, $this->offset, $this->limit);
00138     }

MSSQLCallableStatement::getArray ( paramIndex  ) 

See also:
CallableStatement::getArray()

Implements CallableStatement.

Definition at line 324 of file MSSQLCallableStatement.php.

00325     {
00326         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00327             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00328         }
00329         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00330         return (array) unserialize($this->boundOutVars[$paramIndex]);
00331     } 

MSSQLCallableStatement::getBlob ( paramIndex  ) 

See also:
CallableStatement::getBlob()

Implements CallableStatement.

Definition at line 348 of file MSSQLCallableStatement.php.

00349     {
00350         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00351             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00352         }
00353         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00354         require_once 'creole/util/Blob.php';
00355         $b = new Blob();
00356         $b->setContents($this->boundOutVars[$paramIndex]);
00357         return $b;
00358     }     

MSSQLCallableStatement::getBoolean ( paramIndex  ) 

See also:
CallableStatement::getBoolean()

Implements CallableStatement.

Definition at line 336 of file MSSQLCallableStatement.php.

00337     {
00338         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00339             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00340         }
00341         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00342         return (boolean) $this->boundOutVars[$paramIndex];
00343     }

MSSQLCallableStatement::getClob ( paramIndex  ) 

See also:
CallableStatement::getClob()

Implements CallableStatement.

Definition at line 363 of file MSSQLCallableStatement.php.

00364     {
00365         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00366             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00367         }
00368         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00369         require_once 'creole/util/Clob.php';
00370         $c = new Clob();
00371         $c->setContents($this->boundOutVars[$paramIndex]);
00372         return $c;
00373     } 

MSSQLCallableStatement::getDate ( paramIndex,
fmt = '%Y-%m-%d' 
)

See also:
CallableStatement::getDate()

Implements CallableStatement.

Definition at line 378 of file MSSQLCallableStatement.php.

00379     {
00380         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00381             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00382         }
00383         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00384         
00385         $ts = strtotime($this->boundOutVars[$paramIndex]);        
00386         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
00387             throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
00388         }        
00389         if (strpos($format, '%') !== false) {
00390             return strftime($format, $ts);
00391         } else {
00392             return date($format, $ts);
00393         }
00394         
00395         return $this->boundOutVars[$paramIndex];
00396     } 

MSSQLCallableStatement::getFloat ( paramIndex  ) 

Parameters:
mixed $paramIndex Column name (string) or index (int).
Returns:
float

Implements CallableStatement.

Definition at line 402 of file MSSQLCallableStatement.php.

00403     {
00404         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00405             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00406         }
00407         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00408         return (float) $this->boundOutVars[$paramIndex];
00409     }

MSSQLCallableStatement::getInt ( paramIndex  ) 

See also:
CallableStatement::getInt()

Implements CallableStatement.

Definition at line 414 of file MSSQLCallableStatement.php.

00415     {
00416         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00417             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00418         }
00419         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00420         return (int) $this->boundOutVars[$paramIndex];
00421     }            

MSSQLCallableStatement::getMoreResults (  ) 

See also:
CallableStatement::getMoreResults()

Reimplemented from PreparedStatementCommon.

Definition at line 143 of file MSSQLCallableStatement.php.

00144     {
00145         $this->rsFetchCount++; // we track this because 
00146         $hasMore = mssql_next_result($this->result);
00147         if ($this->resultSet) $this->resultSet->close();                    
00148         if ($hasMore) {
00149             $clazz = $this->resultClass;
00150             $this->resultSet = new $clazz($this, $this->result);
00151         } else {
00152             $this->resultSet = null;
00153         }
00154         return $hasMore;
00155     }

MSSQLCallableStatement::getResource (  ) 

See also:
CallableStatement::getResource()

Reimplemented from PreparedStatementCommon.

Definition at line 99 of file MSSQLCallableStatement.php.

00100     {
00101         return $this->stmt;
00102     }

MSSQLCallableStatement::getString ( paramIndex  ) 

See also:
CallableStatement::getString()

Implements CallableStatement.

Definition at line 426 of file MSSQLCallableStatement.php.

00427     {
00428         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00429             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00430         }
00431         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00432         return (string) $this->boundOutVars[$paramIndex];
00433     } 

MSSQLCallableStatement::getTime ( paramIndex,
format = '%X' 
)

See also:
CallableStatement::getTime()

Implements CallableStatement.

Definition at line 438 of file MSSQLCallableStatement.php.

00439     {
00440         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00441             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00442         }
00443         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00444         
00445         $ts = strtotime($this->boundOutVars[$paramIndex]);        
00446         if ($ts === -1  || $ts === false) { // in PHP 5.1 return value changes to FALSE
00447             throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
00448         }        
00449         if (strpos($format, '%') !== false) {
00450             return strftime($format, $ts);
00451         } else {
00452             return date($format, $ts);
00453         }
00454             
00455     }

MSSQLCallableStatement::getTimestamp ( paramIndex,
format = 'Y-m-d H:i:s' 
)

See also:
CallableStatement::getTimestamp()

Implements CallableStatement.

Definition at line 460 of file MSSQLCallableStatement.php.

00460                                                          :i:s') 
00461     {
00462         if (!array_key_exists($paramIndex, $this->boundOutVars)) {
00463             throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
00464         }
00465         if ($this->boundOutVars[$paramIndex] === null) { return null; }
00466                 
00467         $ts = strtotime($this->boundOutVars[$paramIndex]);        
00468         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
00469             throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
00470         }        
00471         if (strpos($format, '%') !== false) {
00472             return strftime($format, $ts);
00473         } else {
00474             return date($format, $ts);
00475         }
00476     }    

MSSQLCallableStatement::registerOutParameter ( paramIndex,
sqlType,
maxLength = null 
)

See also:
CallableStatement::registerOutParameter()

Implements CallableStatement.

Definition at line 160 of file MSSQLCallableStatement.php.

00161     {
00162         mssql_bind($this->stmt, $paramIndex, $this->boundOutVars[$paramIndex], self::$typeMap[$sqlType], true, false, $maxLength);
00163     }

MSSQLCallableStatement::setArray ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setArray()

Definition at line 168 of file MSSQLCallableStatement.php.

References setNull().

00169     {
00170         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00171         if ($value === null) {
00172             $this->setNull($paramIndex);
00173         } else {
00174             $value = serialize($value);
00175             mssql_bind($this->stmt, $paramIndex, $value, SQLTEXT, $out);
00176         }
00177     }

MSSQLCallableStatement::setBlob ( paramIndex,
blob,
out = false 
)

See also:
CallableStatement::setBlob()

Definition at line 197 of file MSSQLCallableStatement.php.

References setNull().

00198     {
00199         if ($blob === null) {
00200             $this->setNull($paramIndex);
00201         } else {
00202             if (is_object($blob)) {
00203                 $blob = $blob->__toString();
00204             }
00205             if ($out) $this->boundOutVars[$paramIndex] = &$blob; // reference means that changes to value, will be reflected        
00206             $data = unpack("H*hex", $blob);
00207             mssql_bind($this->stmt, $paramIndex, $data, SQLTEXT, $out);
00208         }
00209     } 

MSSQLCallableStatement::setBoolean ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setBoolean()

Definition at line 182 of file MSSQLCallableStatement.php.

References setNull().

00183     {
00184         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected        
00185         if ($value === null) {
00186             $this->setNull($paramIndex);
00187         } else {
00188             $value = ($value) ? 1 : 0;
00189             mssql_bind($this->stmt, $paramIndex, $value, SQLBIT, $out);
00190         }
00191     }

MSSQLCallableStatement::setClob ( paramIndex,
clob,
out = false 
)

See also:
CallableStatement::setClob()

Definition at line 214 of file MSSQLCallableStatement.php.

References setNull().

00215     {
00216         if ($clob === null) {
00217             $this->setNull($paramIndex);
00218         } else {
00219             if (is_object($clob)) {
00220                 $clob = $clob->__toString();
00221             }
00222             if ($out) $this->boundOutVars[$paramIndex] = &$clob; // reference means that changes to value, will be reflected
00223             mssql_bind($this->stmt, $paramIndex, $clob, SQLTEXT, $out);
00224         }
00225     }

MSSQLCallableStatement::setDate ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setDate()

Definition at line 230 of file MSSQLCallableStatement.php.

References setNull().

00231     {
00232         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00233         if ($value === null) {
00234             $this->setNull($paramIndex);
00235         } else {
00236             if (is_numeric($value)) $value = date("Y-m-d", $value);
00237             mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
00238         }
00239     } 

MSSQLCallableStatement::setFloat ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setFloat()

Definition at line 244 of file MSSQLCallableStatement.php.

References setNull().

00245     {
00246         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00247         if ($value === null) {
00248             $this->setNull($paramIndex);
00249         } else {
00250             $value = (float) $value;
00251             mssql_bind($this->stmt, $paramIndex, $value, SQLFLT8, $out);
00252         }
00253     }

MSSQLCallableStatement::setInt ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setInt()

Definition at line 258 of file MSSQLCallableStatement.php.

References setNull().

00259     {
00260         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00261         if ($value === null) {
00262             $this->setNull($paramIndex);
00263         } else {
00264             $value = (int) $value;
00265             mssql_bind($this->stmt, $paramIndex, $value, SQLINT4, $out);
00266         }
00267     }    

MSSQLCallableStatement::setNull ( paramIndex  ) 

See also:
CallableStatement::setNull()

Reimplemented from PreparedStatementCommon.

Definition at line 272 of file MSSQLCallableStatement.php.

Referenced by setArray(), setBlob(), setBoolean(), setClob(), setDate(), setFloat(), setInt(), setString(), setTime(), and setTimestamp().

00273     {
00274         // hopefully type isn't essential here :)
00275         $value = null; // wants a var to pass by reference
00276         mssql_bind($this->stmt, $paramIndex, $value, $type=null, $out=false, $is_null=true);
00277     }

MSSQLCallableStatement::setString ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setString()

Definition at line 282 of file MSSQLCallableStatement.php.

References setNull().

00283     {    
00284         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00285         if ($value === null) {
00286             $this->setNull($paramIndex);
00287         } else {
00288             $value = (string) $value;            
00289             mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
00290         }
00291     } 

MSSQLCallableStatement::setTime ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setTime()

Definition at line 296 of file MSSQLCallableStatement.php.

References setNull().

00297     {    
00298         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00299         if ($value === null) {
00300             $this->setNull($paramIndex);
00301         } else {
00302             if (is_numeric($value)) $value = date("H:i:s", $value);
00303             mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
00304         }
00305     }

MSSQLCallableStatement::setTimestamp ( paramIndex,
value,
out = false 
)

See also:
CallableStatement::setTimestamp()

Definition at line 310 of file MSSQLCallableStatement.php.

References setNull().

00311     {
00312         if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
00313         if ($value === null) {
00314             $this->setNull($paramIndex);
00315         } else {
00316             if (is_numeric($value)) $value = date('Y-m-d H:i:s', $value);
00317             mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
00318         }
00319     }            


Member Data Documentation

MSSQLCallableStatement::$boundOutVars = array() [private]

Output variables.

Definition at line 45 of file MSSQLCallableStatement.php.

MSSQLCallableStatement::$result [private]

Definition at line 81 of file MSSQLCallableStatement.php.

MSSQLCallableStatement::$stmt [private]

Definition at line 74 of file MSSQLCallableStatement.php.

Referenced by __construct().

MSSQLCallableStatement::$typeMap [static, private]

Initial value:

 array(
        CreoleTypes::BOOLEAN => SQLBIT,
        CreoleTypes::BIGINT => SQLINT4,
        CreoleTypes::SMALLINT => SQLINT2,
        CreoleTypes::TINYINT => SQLINT2,
        CreoleTypes::INTEGER => SQLINT4,
        CreoleTypes::CHAR => SQLCHAR,
        CreoleTypes::VARCHAR => SQLVARCHAR,
        CreoleTypes::TEXT => SQLTEXT,
        CreoleTypes::FLOAT => SQLFLT8,
        CreoleTypes::DOUBLE => SQLFLT8,
        CreoleTypes::DATE => SQLVARCHAR,
        CreoleTypes::TIME => SQLVARCHAR,
        CreoleTypes::TIMESTAMP => SQLVARCHAR,
        CreoleTypes::VARBINARY => SQLVARCHAR,
        CreoleTypes::NUMERIC => SQLINT4,
        CreoleTypes::DECIMAL => SQLFLT8                                        
    )

Definition at line 51 of file MSSQLCallableStatement.php.


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:10:50 2009 for fareofficelib by  doxygen 1.5.8