* @param $sql String
* @param $columns Array
*/
- public function __construct( $db, $result, $num_rows, $sql, $columns ){
+ public function __construct( $db, $result, $num_rows, $sql, $columns ) {
$this->db = $db;
- if( $result instanceof ResultWrapper ){
+ if( $result instanceof ResultWrapper ) {
$this->result = $result->result;
- }
- else{
+ } else {
$this->result = $result;
}
* @return mixed Array on success, false on failure
* @throws DBUnexpectedError
*/
- public function fetchRow(){
+ public function fetchRow() {
if ( $this->result
&& $this->num_rows > 0
&& $this->current_pos >= 0
}
}
- if ( $this->loadedLines > $this->current_pos ){
+ if ( $this->loadedLines > $this->current_pos ) {
return $this->resultSet[$this->current_pos++];
}
* Free a DB2 result object
* @throws DBUnexpectedError
*/
- public function freeResult(){
+ public function freeResult() {
unset( $this->resultSet );
if ( !@db2_free_result( $this->result ) ) {
throw new DBUnexpectedError( $this, "Unable to free DB2 result\n" );
* Returns the database connection object
* @return Object
*/
- public function getDb(){
+ public function getDb() {
return $this->mConn;
}
* @param $user String
* @param $password String
* @param $dbName String: database name
+ * @throws DBConnectionError
* @return DatabaseBase a fresh connection
*/
public function open( $server, $user, $password, $dbName ) {
/**
* The DBMS-dependent part of query()
* @param $sql String: SQL query.
+ * @throws DBUnexpectedError
* @return object Result object for fetch functions or false on failure
*/
protected function doQuery( $sql ) {
// Wide characters are evil -- some of them look like '
$s = utf8_encode( $s );
// Fix its stupidity
- $from = array( "\\\\", "\\'", '\\n', '\\t', '\\"', '\\r' );
- $to = array( "\\", "''", "\n", "\t", '"', "\r" );
+ $from = array( "\\\\", "\\'", '\\n', '\\t', '\\"', '\\r' );
+ $to = array( "\\", "''", "\n", "\t", '"', "\r" );
$s = str_replace( $from, $to, $s ); // DB2 expects '', not \' escaping
return $s;
}
* LIST_SET - comma separated with field names, like a SET clause
* LIST_NAMES - comma separated field names
* LIST_SET_PREPARED - like LIST_SET, except with ? tokens as values
+ * @param array $a
+ * @param int $mode
+ * @throws DBUnexpectedError
* @return string
*/
function makeList( $a, $mode = LIST_COMMA ) {
*
* @param $sql string SQL query we will append the limit too
* @param $limit integer the SQL limit
- * @param $offset integer the SQL offset (default false)
+ * @param bool|int $offset SQL offset (default false)
+ * @throws DBUnexpectedError
* @return string
*/
public function limitResult( $sql, $limit, $offset=false ) {
// find out the primary keys
$keyres = $this->doQuery( "SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '"
- . strtoupper( $table )
- . "' AND TBCREATOR = '"
- . strtoupper( $schema )
- . "' AND KEYSEQ > 0" );
+ . strtoupper( $table )
+ . "' AND TBCREATOR = '"
+ . strtoupper( $schema )
+ . "' AND KEYSEQ > 0" );
$keys = array();
for (
* DELETE query wrapper
*
* Use $conds == "*" to delete all rows
- * @return bool|\ResultWrapper
+ * @param array $table
+ * @param array|string $conds
+ * @param string $fname
+ * @throws DBUnexpectedError
+ * @return bool|ResultWrapper
*/
public function delete( $table, $conds, $fname = 'DatabaseIbm_db2::delete' ) {
if ( !$conds ) {
/**
* Frees memory associated with a statement resource
* @param $res Object: statement resource to free
+ * @throws DBUnexpectedError
* @return Boolean success or failure
*/
public function freeResult( $res ) {
}
}
- if ( isset( $options['GROUP BY'] ) ) {
- $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
- }
- if ( isset( $options['HAVING'] ) ) {
- $preLimitTail .= " HAVING {$options['HAVING']}";
- }
- if ( isset( $options['ORDER BY'] ) ) {
- $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
- }
+ $preLimitTail .= $this->makeGroupByWithHaving( $options );
+
+ $preLimitTail .= $this->makeOrderBy( $options );
if ( isset( $noKeyOptions['DISTINCT'] )
|| isset( $noKeyOptions['DISTINCTROW'] ) )