PgSQLPreparedStatement Class Reference

Inheritance diagram for PgSQLPreparedStatement:

PreparedStatementCommon PreparedStatement

List of all members.

Public Member Functions

 setArray ($paramIndex, $value)
 Sets an array.
 setBoolean ($paramIndex, $value)
 For setting value of Postgres BOOLEAN column.
 setBlob ($paramIndex, $blob)
 Applies sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.
 setTime ($paramIndex, $value)
 setTimestamp ($paramIndex, $value)

Protected Member Functions

 escape ($str)
 Quotes string using native pgsql function (pg_escape_string).

Private Member Functions

 arrayToStr ($arr)
 Recursive function to turn multi-dim array into str representation.


Detailed Description

Definition at line 32 of file PgSQLPreparedStatement.php.


Member Function Documentation

PgSQLPreparedStatement::arrayToStr ( arr  )  [private]

Recursive function to turn multi-dim array into str representation.

Parameters:
array $arr
Returns:
string Array in pgsql-friendly string notation: {val1, val2} or {{sub1,sub2}, {sub3, sub4}}

Definition at line 49 of file PgSQLPreparedStatement.php.

References escape().

Referenced by setArray().

00050     {
00051         $parts = array();
00052         foreach((array)$arr as $el) {
00053             if (is_array($el)) {
00054                 $parts[] = $this->arrayToStr($el);
00055             } else {
00056                 if (is_string($el)) {
00057                     $parts[] = '"' . $this->escape($el) . '"';
00058                 } else {
00059                     $parts[] = $el;
00060                 }                
00061             }
00062         }        
00063         return '{' . implode(',', $parts) . '}';
00064     }

PgSQLPreparedStatement::escape ( str  )  [protected]

Quotes string using native pgsql function (pg_escape_string).

Parameters:
string $str
Returns:
string

Reimplemented from PreparedStatementCommon.

Definition at line 39 of file PgSQLPreparedStatement.php.

Referenced by arrayToStr(), and setTime().

00040     {
00041         return pg_escape_string($str);
00042     }

PgSQLPreparedStatement::setArray ( paramIndex,
value 
)

Sets an array.

Unless a driver-specific method is used, this means simply serializing the passed parameter and storing it as a string.

Parameters:
int $paramIndex
array $value
Returns:
void
See also:
PreparedStatement::setArray()

Reimplemented from PreparedStatementCommon.

Definition at line 75 of file PgSQLPreparedStatement.php.

References arrayToStr(), and PreparedStatementCommon::setNull().

00076     {
00077         if( $paramIndex > $this->positionsCount || $paramIndex < 1) {
00078             throw new SQLException('Cannot bind to invalid param index: '.$paramIndex);
00079         }
00080         if ($value === null)
00081             $this->setNull($paramIndex);
00082         else
00083             $this->boundInVars[$paramIndex] = "'" . $this->arrayToStr($value) . "'";        
00084     }

PgSQLPreparedStatement::setBlob ( paramIndex,
blob 
)

Applies sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.

Parameters:
int $paramIndex
mixed $blob Blob object or string containing data.
Returns:
void

Reimplemented from PreparedStatementCommon.

Definition at line 109 of file PgSQLPreparedStatement.php.

References PreparedStatementCommon::setNull().

00110     {    
00111         if ($blob === null) {
00112             $this->setNull($paramIndex);
00113         } else {
00114             // they took magic __toString() out of PHP5.0.0; this sucks
00115             if (is_object($blob)) {
00116                 $blob = $blob->__toString();
00117             }            
00118             $this->boundInVars[$paramIndex] = "'" . pg_escape_bytea( $blob ) . "'";
00119         }    
00120         
00121     }

PgSQLPreparedStatement::setBoolean ( paramIndex,
value 
)

For setting value of Postgres BOOLEAN column.

Parameters:
int $paramIndex
boolean $value
Returns:
void

Reimplemented from PreparedStatementCommon.

Definition at line 92 of file PgSQLPreparedStatement.php.

References PreparedStatementCommon::setNull().

00093     {
00094         if( $paramIndex > $this->positionsCount || $paramIndex < 1) {
00095             throw new SQLException('Cannot bind to invalid param index: '.$paramIndex);
00096         }        
00097         if ($value === null)
00098             $this->setNull($paramIndex);
00099         else
00100             $this->boundInVars[$paramIndex] = ($value ? "'t'" : "'f'");
00101     }

PgSQLPreparedStatement::setTime ( paramIndex,
value 
)

Parameters:
int $paramIndex
string $value
Returns:
void

Reimplemented from PreparedStatementCommon.

Definition at line 128 of file PgSQLPreparedStatement.php.

References escape(), and PreparedStatementCommon::setNull().

00129     {        
00130         if ($value === null) {
00131             $this->setNull($paramIndex);
00132         } else {
00133             if ( is_numeric ( $value ) ) {
00134         $value = date ( "H:i:s O", $value );
00135       } elseif ( is_object ( $value ) ) {
00136         $value = date ( "H:i:s O", $value->getTime ( ) );
00137       }
00138             $this->boundInVars [ $paramIndex ] = "'" . $this->escape ( $value ) . "'";
00139         }
00140     }

PgSQLPreparedStatement::setTimestamp ( paramIndex,
value 
)

Parameters:
int $paramIndex
string $value
Returns:
void

Reimplemented from PreparedStatementCommon.

Definition at line 147 of file PgSQLPreparedStatement.php.

References PreparedStatementCommon::setNull().

00148     {        
00149         if ($value === null) {
00150             $this->setNull($paramIndex);
00151         } else {
00152             if (is_numeric($value)) $value = date('Y-m-d H:i:s O', $value);
00153             elseif (is_object($value)) $value = date("Y-m-d H:i:s O", $value->getTime());
00154             $this->boundInVars[$paramIndex] = "'".$this->escape($value)."'";
00155         }
00156     }


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