function test_walkIntersectTree() { $tree = array("children" => array("1" => array("slug" => "aaa", "parent" => 0, "node_id" => 1), "2" => array("slug" => "bbb", "parent" => 0, "node_id" => 2, "children" => array("5" => array("slug" => "eee", "parent" => 2, "node_id" => 5, "children" => array("14" => array("slug" => "aaa", "parent" => 5, "node_id" => 14), "15" => array("slug" => "bbb", "parent" => 5, "node_id" => 15, "children" => array("17" => array("slug" => "xxx", "parent" => 15, "node_id" => 17))), "16" => array("slug" => "ccc", "parent" => 5, "node_id" => 16, "children" => array("18" => array("slug" => "yyy", "parent" => 16, "node_id" => 18), "19" => array("slug" => "zzz", "parent" => 16, "node_id" => 19))))), "6" => array("slug" => "fff", "parent" => 2, "node_id" => 6), "7" => array("slug" => "ggg", "parent" => 2, "node_id" => 7))), "3" => array("slug" => "ccc", "parent" => 0, "node_id" => 3, "children" => array("8" => array("slug" => "hhh", "parent" => 3, "node_id" => 8), "9" => array("slug" => "iii", "parent" => 3, "node_id" => 9), "10" => array("slug" => "jjj", "parent" => 3, "node_id" => 10))), "4" => array("slug" => "ddd", "parent" => 0, "node_id" => 4, "children" => array("11" => array("slug" => "hhh", "parent" => 4, "node_id" => 11), "12" => array("slug" => "iii", "parent" => 4, "node_id" => 12), "13" => array("slug" => "jjj", "parent" => 4, "node_id" => 13))))); // Exact match // =============================================== $walk = array("0" => "bbb", "1" => "eee", "2" => "aaa"); $check = array("endpoint_id" => 14, "endpoint_name" => "aaa", "walk_key" => 2, "transect" => array()); $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error); $this->assertEquals($check, $result, FOX_debug::formatError_print($error)); unset($error); // Walk longer than graph // =============================================== $walk = array("0" => "bbb", "1" => "eee", "2" => "ccc", "3" => "qqq", "4" => "ttt"); $check = array("endpoint_id" => 16, "endpoint_name" => "ccc", "walk_key" => 2, "transect" => array("qqq", "ttt")); $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error); $this->assertEquals($check, $result, FOX_debug::formatError_print($error)); unset($error); // Graph longer than walk // =============================================== $walk = array("0" => "ccc"); $check = array("endpoint_id" => 3, "endpoint_name" => "ccc", "walk_key" => 0, "transect" => array()); $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error); $this->assertEquals($check, $result, FOX_debug::formatError_print($error)); unset($error); // Null intersect // =============================================== $walk = array("0" => "zzz"); $check = array("endpoint_id" => null, "endpoint_name" => null, "walk_key" => null, "transect" => array()); $result = FOX_sUtil::walkIntersectTree($walk, $tree, $error); $this->assertEquals($check, $result, FOX_debug::formatError_print($error)); unset($error); }
public function dumpString_iterator($depth, $obj, $ctrl = null) { $pos_1 = strrpos($obj->data['file'], "/"); // Linux $pos_2 = strrpos($obj->data['file'], "\\"); // Windows $offset = max($pos_1, $pos_2); $length = strlen($obj->data['file']); $file = substr($obj->data['file'], $offset + 1, $length - $offset); $result .= "\nCODE: " . $obj->data['numeric'] . "\n"; $result .= "TEXT: " . $obj->data['text'] . "\n"; $result .= "FILE: " . $file . "\n"; $result .= "LINE: " . $obj->data['line'] . "\n"; if ($ctrl['data'] == true) { $result .= "DATA: " . FOX_debug::dumpToString($obj->data['data']); } if (is_object($obj->data['child']) && $depth > 0) { $result .= self::dumpString_iterator($depth - 1, $obj->data['child'], $ctrl); } return $result; }
function test_getParentAlbum() { // Clear the albums table, medias table, and caches // =================================================== $this->alb->truncate(); $this->alb->flushCache(); $this->med->truncate(); $this->med->flushCache(); // Load albums class with test data // =================================================== $test_data = array(array('date_created' => "2011-01-01 15:14:13", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 3, 'module_id' => 1), array('date_created' => "2011-01-01 15:14:14", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 2, 'module_id' => 1), array('date_created' => "2011-01-01 15:14:15", 'title' => "Test Title", 'caption' => "Test Caption", 'privacy' => 1, 'module_id' => 2)); $result = $this->alb->addItemMulti($user_id = 1, $test_data, $error); // Return result should be "true" because its a multi-add $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); // Add media items to test albums // =================================================== $test_data = array('owner_id' => 1, 'album_id' => 3, 'title' => "Test Media Title 01", 'caption' => "Test Media Caption 01", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01"); $result = $this->med->addItem($test_data, $media_object, $error); $this->assertEquals(1, $result, FOX_debug::formatError_print($error)); $test_data = array('owner_id' => 1, 'album_id' => 2, 'title' => "Test Media Title 02", 'caption' => "Test Media Caption 02", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01"); $result = $this->med->addItem($test_data, $media_object, $error); $this->assertEquals(2, $result, FOX_debug::formatError_print($error)); $test_data = array('owner_id' => 1, 'album_id' => 1, 'title' => "Test Media Title 03", 'caption' => "Test Media Caption 03", 'date_created' => "2011-02-02 17:18:19", 'module_slug' => "slug_01"); $result = $this->med->addItem($test_data, $media_object, $error); $this->assertEquals(3, $result, FOX_debug::formatError_print($error)); // Fetch parent album // =================================================== $result = $this->alb->getParentAlbum($media_id = 3); $this->assertEquals(1, $result); }
function fox_exceptionHandler($error) { global $fox; if (method_exists($error, 'dumpString')) { $fox->error->add($error); // Not dumping errors deep enough and truncating them with // a "..."? xDebug is hijacking var_dump. Disable it in php.ini $out = $error->dumpString(array('depth' => 20, 'data' => true)); FOX_debug::dump($out); } else { var_dump($error); } }
/** * Deletes all data from a database table, given an array defining the table's structure * * @version 1.0 * @since 1.0 * * @param array $struct | Structure of the db table, @see class FOX_db header for examples * => VAL @param string 'db_table_name' | Name of the db table * => VAL @param array 'columns' | Array of database column arrays. * => ARR @param string '' | Name of the db column this key describes * => VAL @param string 'format' | Display format of column, usually %s or %d, @see http://php.net/manual/en/function.sprintf.php * => VAL @param string 'type' Build string used in table creation query * => VAL @param bool 'index' True if the column is indexed by the SQL server. False if not. * * @param array $ctrl | Control args (not yet implemented) * * @return bool | True on success. Exception on failure. */ public function runTruncateTable($struct, $ctrl = null) { if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "method_start", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } // Check table array exists, because if its sent in with // an empty name variable, it could damage the database // ======================================================= if ($this->print_query_args == true) { ob_start(); print_r($struct); $out = ob_get_clean(); FOX_debug::addToFile($out); } if (empty($struct["table"])) { throw new FOX_exception(array('numeric' => 1, 'text' => "Called with missing table name", 'data' => array("struct" => $struct, 'ctrl' => $ctrl), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // Build query string // ======================= if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "build_query", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } try { $query = $this->builder->buildTruncateTable($struct); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Error in query generator", 'data' => array("struct" => $struct, 'ctrl' => $ctrl), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } // Run on SQL server // ======================= if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "run_query", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } try { $result = $this->runner->runQuery($query, array("format" => "raw")); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 3, 'text' => "Error executing query on SQL server", 'data' => array("query" => $query, "ctrl" => $ctrl), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "method_end", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } return $result; }
/** * Renders the "Server" tab * * This tab rendering function creates a single tab within the admin page that its parent class generates. The tab's form * contains a hidden field called 'page_options'. The class's "processor" function parses the variable names in this field * to determine which POST data fields to load and which objects in the $bp->bpa->options[] global to update. * * @version 1.0 * @since 1.0 */ function render() { global $fox; $version = new FOX_version(); ?> <form name="pathsform" method="POST" action="<?php echo $this->filepath . '#paths'; ?> " > <?php wp_nonce_field('fox_admin_settings'); ?> <?php $fox->config->initNodesArray(); ?> <?php if (FOX_EXPERT_MODE == 1) { $locked = ''; $lock_status = '<div class="bpa-unlocked-small"></div>'; } else { $locked = 'disabled="true"'; $lock_status = '<div class="bpa-locked-small"></div>'; } ?> <div class="panel_section w25"> <div class="title"><?php _e('Server Environment', "foxfire"); ?> </div> <div class="fox_section_advice"> <?php _e("Your server is reporting the file paths listed below. You can override these values by defining them in your wp-config.php file,<br>\n\t\t\t\texample... <i>define( 'WP_CONTENT_URL', 'http://mysite.com/test/installs/wp-content');</i>", "foxfire"); ?> </div> <table class="form-table"> <?php $constants = array('PHP_OS', 'PHP_VERSION', 'WP_CONTENT_URL', 'WP_CONTENT_DIR', 'WP_PLUGIN_DIR', 'WP_PLUGIN_URL', 'FOX_FOLDER', 'FOX_URL_BASE', 'FOX_PATH_BASE'); foreach ($constants as $const) { ?> <tr valign="top"> <th align="left"><?php echo $const; ?> </th> <td> <input type="text" size="80" maxlength="200" name="<?php echo $const; ?> " disabled="disabled" value="<?php echo constant($const); ?> " /> </td> </tr> <?php } ?> <tr valign="top"> <th align="left"><?php _e('SQL_VERSION', "foxfire"); ?> </th> <td> <input type="text" size="80" maxlength="200" name="SQL_VERSION" disabled="disabled" value="<?php echo $version->getSQLVersion(); ?> " /> </td> </tr> <tr valign="top"> <th align="left"><?php _e('APACHE_VERSION', "foxfire"); ?> </th> <td> <input type="text" size="80" maxlength="200" name="APACHE_VERSION" disabled="disabled" value="<?php echo $version->getApacheVersion(); ?> " /> </td> </tr> </table> </div> <div class="panel_section w25"> <div class="title"><?php _e("PHP INFO", "foxfire"); ?> </div> <table class="form-table"> <tr valign="top"> <td> <?php FOX_debug::php_info_dump(); ?> </td> </tr> </table> </div> <?php $fox->config->printNodesArray(); ?> </form> <!-- End Path settings --> <?php }
/** * Runs a query on the database. Returns results in a specific format. * * @version 1.0 * @since 1.0 * @link https://github.com/FoxFire/foxfirewiki/DOCS_FOX_db_select_formatter * * @param string $sql | SQL query string * * @param array $ctrl | Control parameters for the query * => VAL @param string $format | Return format for query: "col", "row", "var", "array_key_object", "array_key_array" * "array_key_single", "array_object", "array_array", "raw", or (null) * @see result formatter headers inside this method for detailed docs * * => VAL @see FOX_db::runSelectQuery() and FOX_db::runSelectQueryJoin() for docs on remaining $ctrl options * * @return bool | Exception on failure. Query results array on success. */ public function runQuery($query, $ctrl = null) { $ctrl_default = array('format' => 'raw'); $ctrl = FOX_sUtil::parseArgs($ctrl, $ctrl_default); if ($this->print_query_args == true) { ob_start(); print_r($query); print_r($ctrl); $out = ob_get_clean(); FOX_debug::addToFile($out); } // Handle single parameter as string/int, or multiple // parameters passed as an array // ================================================== if (is_array($query)) { $sql = $this->driver->prepare($query['query'], $query['params']); } else { $sql = $query; $query = array('types' => array()); $ctrl = array("format" => "raw"); } // TODO: This prevents PHP from throwing a warning in queryResult() when the table // builder methods run their queries (which have no return type), but it should be // improved to prevent queries that are accidentally missing return data types // from leaking through if (!array_key_exists('types', $query)) { $query['types'] = array(); } if ($this->print_query_sql == true) { FOX_debug::addToFile($sql); } // EXAMPLE TABLE "test_table" // ================================= // col_1 | col_2 | col_3 | col_4 | // ================================= // 1 | red | dog | big | // 2 | green| cat | med | // 3 | blue | bird | small | // 4 | black| fish | tiny | $cast = new FOX_cast(); switch ($ctrl["format"]) { // VAR // ============================================================================= // Used when fetching query results that return a single variable. // // EXAMPLE: "SELECT COUNT(*) FROM test_table WHERE col_2 = red" // RESULT: string "1" (all data is returned in string format) case "var": try { $sql_result = $this->driver->get_var($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "\nRAW, format = var\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $result = $sql_result; } else { $result = $cast->queryResult($format = "var", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = var\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } } break; // COL // ============================================================================= // Used when fetching query results which only contain values from a single column. // // EXAMPLE: "SELECT col2 FROM test_table" // RESULT: array("red", "green", "blue", "black") // COL // ============================================================================= // Used when fetching query results which only contain values from a single column. // // EXAMPLE: "SELECT col2 FROM test_table" // RESULT: array("red", "green", "blue", "black") case "col": try { $sql_result = $this->driver->get_col($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "\nRAW, format = col\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $result = $sql_result; } else { $result = $cast->queryResult($format = "col", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = col\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } } break; // ROW_OBJECT // ============================================================================= // Returns a single database row as an object, with variable names mapped to // column names. If the query returns multiple rows, only the first row is returned. // // EXAMPLE: "SELECT * FROM test_table WHERE col_1 = 2" // RESULT: object stdClass( // col_1->2 // col_2->"green" // col_3->"cat" // col_4->"med" // ) // ROW_OBJECT // ============================================================================= // Returns a single database row as an object, with variable names mapped to // column names. If the query returns multiple rows, only the first row is returned. // // EXAMPLE: "SELECT * FROM test_table WHERE col_1 = 2" // RESULT: object stdClass( // col_1->2 // col_2->"green" // col_3->"cat" // col_4->"med" // ) case "row_object": try { $sql_result = $this->driver->get_row($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 3, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "\nRAW, format = row\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $result = $sql_result; } else { $result = $cast->queryResult($format = "row_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = row_object\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } } break; // ROW_ARRAY // ============================================================================= // Returns a single database row as an array, with key names mapped to column // names. If the query returns multiple rows, only the first row is returned. // // EXAMPLE: "SELECT * FROM test_table WHERE col_1 = 2" // RESULT: array( // "col_1"=>2 // "col_2"=>"green" // "col_3"=>"cat" // "col_4"=>"med" // ) // ROW_ARRAY // ============================================================================= // Returns a single database row as an array, with key names mapped to column // names. If the query returns multiple rows, only the first row is returned. // // EXAMPLE: "SELECT * FROM test_table WHERE col_1 = 2" // RESULT: array( // "col_1"=>2 // "col_2"=>"green" // "col_3"=>"cat" // "col_4"=>"med" // ) case "row_array": try { $sql_result = $this->driver->get_row($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 4, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "\nRAW, format = row_array\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "row_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = row_array\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); // Convert row object into array foreach ($data as $key => $value) { $result[$key] = $value; } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = row_array\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_OBJECT // ============================================================================= // // When used with a single column name passed as a string: // // Returns results as an array of objects, where the primary array key names are // set based on the contents of a database column. // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"]="col_3" // RESULT: array( // "dog" =>stdClass( "col_1"->1, "col_2"->"red", "col_3"->"dog", "col_4"->"big"), // "cat" =>stdClass( "col_1"->2, "col_2"->"green", "col_3"->"cat", "col_4"->"med"), // "bird"=>stdClass( "col_1"->3, "col_2"->"blue", "col_3"->"bird", "col_4"->"small"), // "fish"=>stdClass( "col_1"->4, "col_2"->"black", "col_3"->"fish", "col_4"->"tiny"), // ) // When used with multiple column names passed as an array of strings: // // Returns results as an array of arrays^N, where the array key names and heirarchy // are set based on the contents of the $key_col array. This output format REQUIRES // that each taxonomy group (in the example below "col_3" + "col_4") is UNIQUE // // EXAMPLE TABLE "test_table_2" // ====================================== // col_1 | col_2 | col_3 | col_4 | col_5 // ====================================== // 1 | red | dog | big | heavy // 2 | green| dog | med | light // 3 | blue | bird | small | light // 4 | black| fish | tiny | average // 5 | black| fish | large | light // // UNIQUE KEY col_3_col4(col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_3, "col_4") // RESULT: array( // "dog" =>array( // "big"=>stdClass("col_1"->1, "col_2"->"red", "col_5"->"heavy"), // "med"=>stdClass("col_1"->2, "col_2"->"green", "col_5"->"light") // ), // "bird"=>array( // "small"=>stdClass("col_1"->3, "col_2"->"blue", "col_5"->"light") // ), // "fish"=>array( // "tiny"=>stdClass("col_1"->4, "col_2"->"black", "col_5"->"average"), // "large"=>stdClass("col_1"->5, "col_2"->"black", "col_5"->"light") // ) // ) // ARRAY_KEY_OBJECT // ============================================================================= // // When used with a single column name passed as a string: // // Returns results as an array of objects, where the primary array key names are // set based on the contents of a database column. // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"]="col_3" // RESULT: array( // "dog" =>stdClass( "col_1"->1, "col_2"->"red", "col_3"->"dog", "col_4"->"big"), // "cat" =>stdClass( "col_1"->2, "col_2"->"green", "col_3"->"cat", "col_4"->"med"), // "bird"=>stdClass( "col_1"->3, "col_2"->"blue", "col_3"->"bird", "col_4"->"small"), // "fish"=>stdClass( "col_1"->4, "col_2"->"black", "col_3"->"fish", "col_4"->"tiny"), // ) // When used with multiple column names passed as an array of strings: // // Returns results as an array of arrays^N, where the array key names and heirarchy // are set based on the contents of the $key_col array. This output format REQUIRES // that each taxonomy group (in the example below "col_3" + "col_4") is UNIQUE // // EXAMPLE TABLE "test_table_2" // ====================================== // col_1 | col_2 | col_3 | col_4 | col_5 // ====================================== // 1 | red | dog | big | heavy // 2 | green| dog | med | light // 3 | blue | bird | small | light // 4 | black| fish | tiny | average // 5 | black| fish | large | light // // UNIQUE KEY col_3_col4(col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_3, "col_4") // RESULT: array( // "dog" =>array( // "big"=>stdClass("col_1"->1, "col_2"->"red", "col_5"->"heavy"), // "med"=>stdClass("col_1"->2, "col_2"->"green", "col_5"->"light") // ), // "bird"=>array( // "small"=>stdClass("col_1"->3, "col_2"->"blue", "col_5"->"light") // ), // "fish"=>array( // "tiny"=>stdClass("col_1"->4, "col_2"->"black", "col_5"->"average"), // "large"=>stdClass("col_1"->5, "col_2"->"black", "col_5"->"light") // ) // ) case "array_key_object": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 5, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "\nRAW, format = array_key_object\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_object\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); // If a single column name is passed as a string, use the more efficient // direct assignment algorithm to build a 1 level tree if (!is_array($ctrl["key_col"])) { foreach ($data as $row) { $key = $row->{$ctrl["key_col"]}; $result[$key] = $row; } } else { foreach ($data as $row) { // Since there is no functionality in PHP for creating a new array key // based on a name stored in a variable ( $$ variable variable syntax does // not work for multidimensional arrays, we have to build a string of PHP // code and use eval() to run it $eval_str = "\$result"; foreach ($ctrl["key_col"] as $keyname) { $eval_str .= '["' . $row->{$keyname} . '"]'; } $eval_str .= " = \$row_copy;"; $row_copy = new stdClass(); // Copy the row object into a new stdClass, skipping keys that are used as the // branch variables foreach ($row as $key => $value) { if (array_search($key, $ctrl["key_col"]) === false) { $row_copy->{$key} = $value; } } // Run the PHP string we have built eval($eval_str); } } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_key_object\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_ARRAY // ============================================================================= // When used with a single column name passed as a string: // // Returns results as an array of arrays, where the primary array key names are // set based on the contents of a database column. // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"]="col_3" // RESULT: array( // "dog" =>array( "col_1"=>1, "col_2"=>"red", "col_3"=>"dog", "col_4"=>"big"), // "cat" =>array( "col_1"=>2, "col_2"=>"green", "col_3"=>"cat", "col_4"=>"med"), // "bird"=>array( "col_1"=>3, "col_2"=>"blue", "col_3"=>"bird", "col_4"=>"small"), // "fish"=>array( "col_1"=>4, "col_2"=>"black", "col_3"=>"fish", "col_4"=>"tiny"), // ) // // When used with multiple column names passed as an array of strings: // // Returns results as an array of arrays^N, where the array key names and heirarchy // are set based on the contents of the $key_col array. This output format REQUIRES // that each taxonomy group (in the example below "col_3" + "col_4") is UNIQUE // // EXAMPLE TABLE "test_table_2" // ====================================== // col_1 | col_2 | col_3 | col_4 | col_5 // ====================================== // 1 | red | dog | big | heavy // 2 | green| dog | med | light // 3 | blue | bird | small | light // 4 | black| fish | tiny | average // 5 | black| fish | large | light // // UNIQUE KEY col_3_col4(col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_3, "col_4") // RESULT: array( // "dog" =>array( // "big"=>array("col_1"=>1, "col_2"=>"red", "col_5"=>"heavy"), // "med"=>array("col_1"=>2, "col_2"=>"green", "col_5"=>"light") // ), // "bird"=>array( // "small"=>array("col_1"=>3, "col_2"=>"blue", "col_5"=>"light") // ), // "fish"=>array( // "tiny"=>array("col_1"=>4, "col_2"=>"black", "col_5"=>"average"), // "large"=>array("col_1"=>5, "col_2"=>"black", "col_5"=>"light") // ) // ) // ARRAY_KEY_ARRAY // ============================================================================= // When used with a single column name passed as a string: // // Returns results as an array of arrays, where the primary array key names are // set based on the contents of a database column. // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"]="col_3" // RESULT: array( // "dog" =>array( "col_1"=>1, "col_2"=>"red", "col_3"=>"dog", "col_4"=>"big"), // "cat" =>array( "col_1"=>2, "col_2"=>"green", "col_3"=>"cat", "col_4"=>"med"), // "bird"=>array( "col_1"=>3, "col_2"=>"blue", "col_3"=>"bird", "col_4"=>"small"), // "fish"=>array( "col_1"=>4, "col_2"=>"black", "col_3"=>"fish", "col_4"=>"tiny"), // ) // // When used with multiple column names passed as an array of strings: // // Returns results as an array of arrays^N, where the array key names and heirarchy // are set based on the contents of the $key_col array. This output format REQUIRES // that each taxonomy group (in the example below "col_3" + "col_4") is UNIQUE // // EXAMPLE TABLE "test_table_2" // ====================================== // col_1 | col_2 | col_3 | col_4 | col_5 // ====================================== // 1 | red | dog | big | heavy // 2 | green| dog | med | light // 3 | blue | bird | small | light // 4 | black| fish | tiny | average // 5 | black| fish | large | light // // UNIQUE KEY col_3_col4(col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_3, "col_4") // RESULT: array( // "dog" =>array( // "big"=>array("col_1"=>1, "col_2"=>"red", "col_5"=>"heavy"), // "med"=>array("col_1"=>2, "col_2"=>"green", "col_5"=>"light") // ), // "bird"=>array( // "small"=>array("col_1"=>3, "col_2"=>"blue", "col_5"=>"light") // ), // "fish"=>array( // "tiny"=>array("col_1"=>4, "col_2"=>"black", "col_5"=>"average"), // "large"=>array("col_1"=>5, "col_2"=>"black", "col_5"=>"light") // ) // ) case "array_key_array": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 6, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_key_array\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_array\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); // If a single column name is passed as a string, use the more efficient // direct assignment algorithm to build a 1 level tree if (!is_array($ctrl["key_col"])) { foreach ($data as $row) { $arr = array(); // Convert row object into array foreach ($row as $key => $value) { $arr[$key] = $value; } // Insert row array into primary array as named key $result[$row->{$ctrl["key_col"]}] = $arr; } } else { foreach ($data as $row) { // Since there is no functionality in PHP for creating a new array key // based on a name stored in a variable ( $$ variable variable syntax does // not work for multidimensional arrays), we have to build a string of PHP // code and use eval() to run it $eval_str = "\$result"; foreach ($ctrl["key_col"] as $keyname) { $eval_str .= '["' . $row->{$keyname} . '"]'; } $eval_str .= " = \$arr;"; $arr = array(); // Convert row object into array, skipping keys that are used as the // branch variables foreach ($row as $key => $value) { // Check if this is a first-order row. If it is, "lift" it up a // level in the results array to avoid adding an unnecessary "L0" // wrapper array around it $order = count(array_keys((array) $row)) - count($ctrl["key_col"]); if ($order > 1) { if (array_search($key, $ctrl["key_col"]) === false) { $arr[$key] = $value; } } else { $arr = $value; } } // Run the PHP string we have built eval($eval_str); } } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_key_array\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_ARRAY_GROUPED // ============================================================================= // // Requires at least TWO column names, and columns not specified in $key_col are not // included in the results set. Returns results as an array of arrays^N-1, where the // array key names and heirarchy are set based on the contents of the $key_col array. // Results in the last db column specified in $key_col are grouped together in an // int-keyed array. The key name corresponds to the order in which a rows is returned // from the database and the value of each key is the column's value in the database // row. For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_grouped() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"), // "green"=> array("B","C","D") // ), // "bird" =>array( // "blue"=> array("A"), // "black"=> array("A") // ), // "fish" =>array( // "black"=> array("A","B") // ) // ) // ARRAY_KEY_ARRAY_GROUPED // ============================================================================= // // Requires at least TWO column names, and columns not specified in $key_col are not // included in the results set. Returns results as an array of arrays^N-1, where the // array key names and heirarchy are set based on the contents of the $key_col array. // Results in the last db column specified in $key_col are grouped together in an // int-keyed array. The key name corresponds to the order in which a rows is returned // from the database and the value of each key is the column's value in the database // row. For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_grouped() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"), // "green"=> array("B","C","D") // ), // "bird" =>array( // "blue"=> array("A"), // "black"=> array("A") // ), // "fish" =>array( // "black"=> array("A","B") // ) // ) case "array_key_array_grouped": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 7, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_key_array_grouped\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_array_grouped\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { // Since there is no functionality in PHP for creating a new array key // based on a name stored in a variable ( $$ variable variable syntax does // not work for multidimensional arrays), we have to build a string of PHP // code and use eval() to run it $eval_str = "\$result"; $idx = sizeof($ctrl["key_col"]) - 1; $grouped_col = $ctrl["key_col"][$idx]; foreach ($ctrl["key_col"] as $keyname) { if ($keyname != $grouped_col) { $eval_str .= '["' . $row->{$keyname} . '"]'; } else { $eval_str .= '[]'; } } $eval_str .= " = \$row->" . $grouped_col . ";"; // Run the PHP string we have built eval($eval_str); } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_key_array_grouped\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_ARRAY_TRUE // ============================================================================= // // Returns results as an array of arrays^N-1, where the array key names and heirarchy // are set based on the contents of the $key_col array. Results in the last db column // specified in $key_col are grouped together in an result-keyed array where the key // name is the column's value in the database row and the key's value is (bool)true. // For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_true() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"=>"true"), // "green"=> array("B"=>"true","C"=>"true","D"=>"true") // ), // "bird" =>array( // "blue"=> array("A"=>"true"), // "black"=> array("A"=>"true") // ), // "fish" =>array( // "black"=> array("A"=>"true","B"=>"true") // ) // ) // ARRAY_KEY_ARRAY_TRUE // ============================================================================= // // Returns results as an array of arrays^N-1, where the array key names and heirarchy // are set based on the contents of the $key_col array. Results in the last db column // specified in $key_col are grouped together in an result-keyed array where the key // name is the column's value in the database row and the key's value is (bool)true. // For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_true() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"=>"true"), // "green"=> array("B"=>"true","C"=>"true","D"=>"true") // ), // "bird" =>array( // "blue"=> array("A"=>"true"), // "black"=> array("A"=>"true") // ), // "fish" =>array( // "black"=> array("A"=>"true","B"=>"true") // ) // ) case "array_key_array_true": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 8, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_key_array_true\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_array_true\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { // Since there is no functionality in PHP for creating a new array key // based on a name stored in a variable ( $$ variable variable syntax does // not work for multidimensional arrays), we have to build a string of PHP // code and use eval() to run it $eval_str = "\$result"; foreach ($ctrl["key_col"] as $keyname) { $eval_str .= '["' . $row->{$keyname} . '"]'; } $eval_str .= " = true;"; // Run the PHP string we have built eval($eval_str); } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_key_array_true\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_ARRAY_FALSE // ============================================================================= // // Returns results as an array of arrays^N-1, where the array key names and heirarchy // are set based on the contents of the $key_col array. Results in the last db column // specified in $key_col are grouped together in an result-keyed array where the key // name is the column's value in the database row and the key's value is (bool)false. // For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_false() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"=>"false"), // "green"=> array("B"=>"false","C"=>"false","D"=>"false") // ), // "bird" =>array( // "blue"=> array("A"=>"false"), // "black"=> array("A"=>"false") // ), // "fish" =>array( // "black"=> array("A"=>"false","B"=>"false") // ) // ) // ARRAY_KEY_ARRAY_FALSE // ============================================================================= // // Returns results as an array of arrays^N-1, where the array key names and heirarchy // are set based on the contents of the $key_col array. Results in the last db column // specified in $key_col are grouped together in an result-keyed array where the key // name is the column's value in the database row and the key's value is (bool)false. // For a working example of how to use this result formatter, see the function // database_resultFormatters::test_array_key_array_false() in the database unit tests. // // EXAMPLE TABLE "test_table_2" // =============================== // col_1 | col_2 | col_3 | col_4 // =============================== // 1 | red | dog | A // 2 | green| dog | B // 3 | green| dog | C // 4 | green| dog | D // 5 | blue | bird | A // 6 | black| bird | A // 7 | black| fish | A // 8 | black| fish | B // // UNIQUE KEY no_duplicates(col_2, col_3, col_4) // // EXAMPLE: "SELECT * FROM test_table" + $ctrl["key_col"] = array("col_2, "col_3", "col_4") // NOTE: "col_1" is excluded because it is not specified in $ctrl["key_col"] // RESULT: array( // "dog" =>array( // "red"=> array("A"=>"false"), // "green"=> array("B"=>"false","C"=>"false","D"=>"false") // ), // "bird" =>array( // "blue"=> array("A"=>"false"), // "black"=> array("A"=>"false") // ), // "fish" =>array( // "black"=> array("A"=>"false","B"=>"false") // ) // ) case "array_key_array_false": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 9, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_key_array_false"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_array_false"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { // Since there is no functionality in PHP for creating a new array key // based on a name stored in a variable ( $$ variable variable syntax does // not work for multidimensional arrays), we have to build a string of PHP // code and use eval() to run it $eval_str = "\$result"; foreach ($ctrl["key_col"] as $keyname) { $eval_str .= '["' . $row->{$keyname} . '"]'; } $eval_str .= " = false;"; // Run the PHP string we have built eval($eval_str); } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_key_array_false"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_KEY_SINGLE // ============================================================================= // Returns results as an array of ints or strings, where the array key names // are set based on the contents of a database column. // // EXAMPLE: "SELECT col_2, col_3 FROM test_table" + $ctrl["key_col"]="col_2", $ctrl["val_col"]="col_3" // RESULT: array( // "red"=>"dog", // "green"=>"cat", // "blue"=>"bird", // "black"=>"fish" // ) // ARRAY_KEY_SINGLE // ============================================================================= // Returns results as an array of ints or strings, where the array key names // are set based on the contents of a database column. // // EXAMPLE: "SELECT col_2, col_3 FROM test_table" + $ctrl["key_col"]="col_2", $ctrl["val_col"]="col_3" // RESULT: array( // "red"=>"dog", // "green"=>"cat", // "blue"=>"bird", // "black"=>"fish" // ) case "array_key_single": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 10, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_key_single\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_key_single\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { $result[$row->{$ctrl["key_col"]}] = $row->{$ctrl["val_col"]}; } if ($this->print_result_formatted == true) { ob_start(); echo "\nCAST, format = array_key_single\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_OBJECT // ============================================================================= // Returns results as an array of objects, where the primary array keys are // zero-indexed ints // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // stdClass( "col_1"->1, "col_2"->"red", "col_3"->"dog", "col_4"->"big"), // stdClass( "col_1"->2, "col_2"->"green", "col_3"->"cat", "col_4"->"med"), // stdClass( "col_1"->3, "col_2"->"blue", "col_3"->"bird", "col_4"->"small"), // stdClass( "col_1"->4, "col_2"->"black", "col_3"->"fish", "col_4"->"tiny"), // ) // ARRAY_OBJECT // ============================================================================= // Returns results as an array of objects, where the primary array keys are // zero-indexed ints // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // stdClass( "col_1"->1, "col_2"->"red", "col_3"->"dog", "col_4"->"big"), // stdClass( "col_1"->2, "col_2"->"green", "col_3"->"cat", "col_4"->"med"), // stdClass( "col_1"->3, "col_2"->"blue", "col_3"->"bird", "col_4"->"small"), // stdClass( "col_1"->4, "col_2"->"black", "col_3"->"fish", "col_4"->"tiny"), // ) case "array_object": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 11, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_object\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $result = $sql_result; } else { $result = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_object\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($this->print_result_formatted == true) { ob_start(); print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } break; // ARRAY_ARRAY // ============================================================================= // Returns results as an array of arrays, where the primary array keys are // zero-indexed ints // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // array( "col_1"=>1, "col_2"=>"red", "col_3"=>"dog", "col_4"=>"big"), // array( "col_1"=>2, "col_2"=>"green", "col_3"=>"cat", "col_4"=>"med"), // array( "col_1"=>3, "col_2"=>"blue", "col_3"=>"bird", "col_4"=>"small"), // array( "col_1"=>4, "col_2"=>"black", "col_3"=>"fish", "col_4"=>"tiny"), // ) // ARRAY_ARRAY // ============================================================================= // Returns results as an array of arrays, where the primary array keys are // zero-indexed ints // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // array( "col_1"=>1, "col_2"=>"red", "col_3"=>"dog", "col_4"=>"big"), // array( "col_1"=>2, "col_2"=>"green", "col_3"=>"cat", "col_4"=>"med"), // array( "col_1"=>3, "col_2"=>"blue", "col_3"=>"bird", "col_4"=>"small"), // array( "col_1"=>4, "col_2"=>"black", "col_3"=>"fish", "col_4"=>"tiny"), // ) case "array_array": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 12, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_array\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_array\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { $arr = array(); // Convert row object into array foreach ($row as $key => $value) { $arr[$key] = $value; } // Insert row array into primary array as unnamed key $result[] = $arr; } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_array\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // ARRAY_ARRAY_OFFSET // ============================================================================= // Returns results as an array of arrays, where the primary array keys are // zero-indexed ints, and the secondary array keys are the offset of the // column in the table definition array // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // array( 1, "red", "dog", "big"), // array( 2, "green", "cat", "med"), // array( 3, "blue", "bird", "small"), // array( 4, "black", "fish", "tiny"), // ) // ARRAY_ARRAY_OFFSET // ============================================================================= // Returns results as an array of arrays, where the primary array keys are // zero-indexed ints, and the secondary array keys are the offset of the // column in the table definition array // // EXAMPLE: "SELECT * FROM test_table" // RESULT: array( // array( 1, "red", "dog", "big"), // array( 2, "green", "cat", "med"), // array( 3, "blue", "bird", "small"), // array( 4, "black", "fish", "tiny"), // ) case "array_array_offset": try { $sql_result = $this->driver->get_results($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 12, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "RAW, format = array_array_offset\n"; print_r($sql_result); $out = ob_get_clean(); FOX_debug::addToFile($out); } if ($this->disable_typecast_read == true) { $data = $sql_result; } else { $data = $cast->queryResult($format = "array_object", $sql_result, $query["types"]); if ($this->print_result_cast == true) { ob_start(); echo "\nCAST, format = array_array_offset\n"; print_r($data); $out = ob_get_clean(); FOX_debug::addToFile($out); } } if ($data) { $result = array(); foreach ($data as $row) { $arr = array(); // Convert row object into array foreach ($row as $key => $value) { $arr[] = $value; } // Insert row array into primary array as unnamed key $result[] = $arr; } if ($this->print_result_formatted == true) { ob_start(); echo "\nFORMATTED, format = array_array_offset\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } unset($data); // Reduce memory usage } break; // RAW // ============================================================================= // Runs a default SQL query. Returned result format depends on the query. // RAW // ============================================================================= // Runs a default SQL query. Returned result format depends on the query. case "raw": try { $result = $this->driver->query($sql); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 13, 'text' => "Error in database driver", 'data' => array('query' => $query, 'sql' => $sql), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($this->print_result_raw == true) { ob_start(); echo "format = null\n"; print_r($result); $out = ob_get_clean(); FOX_debug::addToFile($out); } break; default: throw new FOX_exception(array('numeric' => 14, 'text' => "Invalid query runner format", 'data' => array('faulting_format' => $ctrl["format"], "query" => $query, "ctrl" => $ctrl), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // END switch($ctrl["format"]) return $result; }
function test_data_integrity() { // Clear the table and cache // =================================================== $result = $this->cls->truncate($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); $result = $this->cls->flushCache($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); // Load test data // =================================================== $insert_data = array(array("slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), array("slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), array("slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), array("slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), array("slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false)); $check_ids = array(0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5); $result = $this->cls->addMulti($insert_data, $error); $this->assertEquals($check_ids, $result, FOX_debug::formatError_print($error)); // Verify correct ids are returned unset($error); // Verify correct data is returned // =================================================== $check_db = array(1 => array("module_id" => 1, "slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), 2 => array("module_id" => 2, "slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), 3 => array("module_id" => 3, "slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), 4 => array("module_id" => 4, "slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), 5 => array("module_id" => 5, "slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false)); $result = $this->cls->getAllModules($error); $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error)); unset($error); // Verify correct cache state // =================================================== $check_cache = array("module_id" => array(1 => array("module_id" => 1, "slug" => "slug_01", "name" => "name_01", "php_class" => "class_01", "active" => true), 2 => array("module_id" => 2, "slug" => "slug_02", "name" => "name_02", "php_class" => "class_02", "active" => true), 3 => array("module_id" => 3, "slug" => "slug_03", "name" => "name_03", "php_class" => "class_03", "active" => false), 4 => array("module_id" => 4, "slug" => "slug_04", "name" => "name_04", "php_class" => "class_04", "active" => true), 5 => array("module_id" => 5, "slug" => "slug_05", "name" => "name_05", "php_class" => "class_05", "active" => false)), "php_class" => array("class_01" => 1, "class_02" => 2, "class_03" => 3, "class_04" => 4, "class_05" => 5), "slug" => array("slug_01" => 1, "slug_02" => 2, "slug_03" => 3, "slug_04" => 4, "slug_05" => 5), "active_modules" => array(1 => true, 2 => true, 4 => true), "all_cached" => true); $this->assertEquals($check_cache, $this->cls->cache); unset($error); // Fail on missing module_id // ================================= $data = array("slug" => "slug_01_updated", "name" => "name_01_updated", "php_class" => "class_01_updated", "active" => true); $result = $this->cls->edit($data, $unit_test = true); $this->assertEquals(false, $result); // Verify cache was not modified $this->assertEquals($check_cache, $this->cls->cache); unset($error); // Clear cache $result = $this->cls->flushCache($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); // Verify db was not modified $result = $this->cls->getAllModules($error); $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error)); unset($error); // Fail on slug collision // ================================= $data = array("module_id" => 1, "slug" => "slug_02"); $result = $this->cls->edit($data, $unit_test = true); $this->assertEquals(false, $result); // Verify cache was not modified $this->assertEquals($check_cache, $this->cls->cache); unset($error); // Clear cache $result = $this->cls->flushCache($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); // Verify db was not modified $result = $this->cls->getAllModules($error); $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error)); unset($error); // Fail on php_class collision // ================================= $data = array("module_id" => 1, "php_class" => "class_02"); $result = $this->cls->edit($data, $unit_test = true); $this->assertEquals(false, $result); // Verify cache was not modified $this->assertEquals($check_cache, $this->cls->cache); unset($error); // Clear cache $result = $this->cls->flushCache($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); // Verify db was not modified $result = $this->cls->getAllModules($error); $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error)); unset($error); // Fail on name collision // ================================= $data = array("module_id" => 1, "name" => "name_02"); $result = $this->cls->edit($data, $unit_test = true); $this->assertEquals(false, $result); // Verify cache was not modified $this->assertEquals($check_cache, $this->cls->cache); unset($error); // Clear cache $result = $this->cls->flushCache($error); $this->assertEquals(true, $result, FOX_debug::formatError_print($error)); unset($error); // Verify db was not modified $result = $this->cls->getAllModules($error); $this->assertEquals($check_db, $result, FOX_debug::formatError_print($error)); unset($error); }