Public Member Functions | |
seek ($rownum) | |
Gets optimized PgSQLResultSetIterator. | |
next () | |
getRecordCount () | |
close () | |
getArray ($column) | |
Reads a column as an array. | |
getBlob ($column) | |
Returns Blob with contents of column value. | |
getBoolean ($column) | |
Private Member Functions | |
strToArray ($str) | |
Convert Postgres string representation of array into native PHP array. |
Definition at line 32 of file PgSQLResultSet.php.
PgSQLResultSet::close | ( | ) |
Implements ResultSet.
Definition at line 113 of file PgSQLResultSet.php.
PgSQLResultSet::getArray | ( | $ | column | ) |
Reads a column as an array.
The value of the column is unserialized & returned as an array.
mixed | $column Column name (string) or index (int) starting with 1. |
SQLException | - If the column specified is not a valid key in current field array. |
Reimplemented from ResultSetCommon.
Definition at line 166 of file PgSQLResultSet.php.
References strToArray().
00167 { 00168 if (is_int($column)) { $column--; } // because Java convention is to start at 1 00169 if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); } 00170 if ($this->fields[$column] === null) { return null; } 00171 return $this->strToArray($this->fields[$column]); 00172 }
PgSQLResultSet::getBlob | ( | $ | column | ) |
Returns Blob with contents of column value.
mixed | $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used). |
SQLException | - If the column specified is not a valid key in current field array. |
Reimplemented from ResultSetCommon.
Definition at line 181 of file PgSQLResultSet.php.
00182 { 00183 if (is_int($column)) { $column--; } // because Java convention is to start at 1 00184 if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); } 00185 if ($this->fields[$column] === null) { return null; } 00186 require_once 'creole/util/Blob.php'; 00187 $b = new Blob(); 00188 $b->setContents(pg_unescape_bytea($this->fields[$column])); 00189 return $b; 00190 }
PgSQLResultSet::getBoolean | ( | $ | column | ) |
mixed | $column Column name (string) or index (int) starting with 1. |
SQLException | - If the column specified is not a valid key in current field array. |
Reimplemented from ResultSetCommon.
Definition at line 197 of file PgSQLResultSet.php.
00198 { 00199 if (is_int($column)) { $column--; } // because Java convention is to start at 1 00200 if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); } 00201 if ($this->fields[$column] === null) { return null; } 00202 return ($this->fields[$column] === 't'); 00203 }
PgSQLResultSet::getRecordCount | ( | ) |
Implements ResultSet.
Definition at line 101 of file PgSQLResultSet.php.
Referenced by PgSQLResultSetIterator::__construct().
00102 { 00103 $rows = @pg_num_rows($this->result); 00104 if ($rows === null) { 00105 throw new SQLException("Error fetching num rows", pg_result_error($this->result)); 00106 } 00107 return (int) $rows; 00108 }
PgSQLResultSet::next | ( | ) |
Implements ResultSet.
Definition at line 74 of file PgSQLResultSet.php.
References ResultSetCommon::afterLast(), and ResultSet::FETCHMODE_ASSOC.
00075 { 00076 00077 $this->fields = @pg_fetch_array($this->result, $this->cursorPos, $this->fetchmode); 00078 00079 if (!$this->fields) { 00080 $err = @pg_result_error($this->result); 00081 if (!$err) { 00082 // We've advanced beyond end of recordset. 00083 $this->afterLast(); 00084 return false; 00085 } else { 00086 throw new SQLException("Error fetching result", $err); 00087 } 00088 } 00089 00090 if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) { 00091 $this->fields = array_change_key_case($this->fields, CASE_LOWER); 00092 } 00093 // Advance cursor position 00094 $this->cursorPos++; 00095 return true; 00096 }
PgSQLResultSet::seek | ( | $ | rownum | ) |
Gets optimized PgSQLResultSetIterator.
Implements ResultSet.
Definition at line 59 of file PgSQLResultSet.php.
00060 { 00061 if ($rownum < 0) { 00062 return false; 00063 } 00064 00065 // PostgreSQL rows start w/ 0, but this works, because we are 00066 // looking to move the position _before_ the next desired position 00067 $this->cursorPos = $rownum; 00068 return true; 00069 }
PgSQLResultSet::strToArray | ( | $ | str | ) | [private] |
Convert Postgres string representation of array into native PHP array.
string | $str Postgres string array rep: {1223, 2343} or {{"welcome", "home"}, {"test2", ""}} |
Definition at line 124 of file PgSQLResultSet.php.
Referenced by getArray().
00125 { 00126 $str = substr($str, 1, -1); // remove { } 00127 $res = array(); 00128 00129 $subarr = array(); 00130 $in_subarr = 0; 00131 00132 $toks = explode(',', $str); 00133 foreach($toks as $tok) { 00134 if ($in_subarr > 0) { // already in sub-array? 00135 $subarr[$in_subarr][] = $tok; 00136 if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component 00137 $res[] = $this->strToArray(implode(',', $subarr[$in_subarr])); 00138 $in_subarr--; 00139 } 00140 } elseif ($tok{0} === '{') { // we're inside a new sub-array 00141 if ('}' !== substr($tok, -1, 1)) { 00142 $in_subarr++; 00143 // if sub-array has more than one element 00144 $subarr[$in_subarr] = array(); 00145 $subarr[$in_subarr][] = $tok; 00146 } else { 00147 $res[] = $this->strToArray($tok); 00148 } 00149 } else { // not sub-array 00150 $val = trim($tok, '"'); // remove " (surrounding strings) 00151 // perform type castng here? 00152 $res[] = $val; 00153 } 00154 } 00155 00156 return $res; 00157 }