get_last_query() публичный статический Метод

Get the last query executed. Only works if the 'logging' config option is set to true. Otherwise this will return null. Returns last query from all connections if no connection_name is specified
public static get_last_query ( null | string $connection_name = null ) : string
$connection_name null | string Which connection to use
Результат string
Пример #1
0
 public function find($tag, $key = "tags")
 {
     // search pages table with pages that has a certain tag
     $r = \ORM::for_table('cms_page')->distinct()->select('cms_page.*')->join('cms_page_meta', array('cms_page.id', '=', 'cms_page_meta.page_id'))->join('cms_page_meta_translation', array('cms_page_meta.id', '=', 'cms_page_meta_translation.meta_id'))->where_equal('cms_page_meta.key', $key)->where_raw("FIND_IN_SET({$tag}, cms_page_meta_translation.value)")->find_many();
     print_r($r);
     print_r(\ORM::get_last_query());
 }
Пример #2
0
 public function testPrefixOnAutoTableNameWithTableSpecified()
 {
     Model::$auto_prefix_models = 'MockPrefix_';
     Model::factory('TableSpecified')->find_many();
     $expected = 'SELECT * FROM `simple`';
     $this->assertEquals($expected, ORM::get_last_query());
 }
Пример #3
0
 public function index()
 {
     $_SESSION['tableData'] = array();
     // Checks whether or not user is logged in
     self::checkLogin();
     // enable query profiling
     Flight::get('db')->query('SET profiling = 1;');
     // get specified table data as array
     $records = ORM::for_table(Flight::get('lastSegment'))->find_array();
     //pretty_print($records);
     // find out time above query was ran for
     $exec_time_result = Flight::get('db')->query('SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;');
     $exec_time_row = $exec_time_result->fetchAll(PDO::FETCH_NUM);
     // table columns
     $stmt = Flight::get('db')->query("DESCRIBE " . Flight::get('lastSegment'));
     $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
     //pretty_print($columns);
     $fields = array();
     foreach ($columns as $values) {
         if (isset($values['Field'])) {
             $fields[] = $values['Field'];
         }
     }
     //pretty_print($fields);
     // store table fields/columns + data rows in session for exporting later
     $_SESSION['tableData'] = array_merge($fields, $records);
     $fieldTypes = array();
     /*
     foreach ($columns as $values) {
         if (isset($values['Field'])) {
             $fieldTypes['type'][] = $values['Type'];
             $fieldTypes['primary'][] = $values['Key'];
         }
     }
     //pretty_print($fieldTypes, false);
     */
     $records = Presenter::listTableData($records, $fieldTypes);
     Flight::render('table', array('title' => Flight::get('lastSegment'), 'icon' => self::$icon, 'table_data' => $records, 'fields' => getOptions($fields), 'query' => SqlFormatter::format(ORM::get_last_query(ORM::DEFAULT_CONNECTION)), 'timetaken' => $exec_time_row[0][1]));
 }
Пример #4
0
<?php

try {
    // include the autoload file, which will include any other required files
    //
    require_once __DIR__ . '/../vendor/autoload.php';
    // handle any "bootstrapping" - application-wide configuration tasks
    //
    require_once __DIR__ . '/../bootstrap.php';
    // start the route processor
    //
    require_once __DIR__ . '/../routes.php';
} catch (Exception $e) {
    // oh no!
    echo "<h1>Unhandled Exception!</h1>";
    echo "\n<!--\n\n";
    print_r($e);
    echo "-->\n\n";
    // dump the exception
    Kint::dump($e);
    // if database logging is enabled...
    if (Config::get('database.logging')) {
        // try to get the last query (or a "none" message if there isn't one)
        $last = ORM::get_last_query() ?: '-- none --';
        // report the last query
        echo "<h2>Last Query</h2>";
        echo "<pre>{$last}</pre>";
    }
}
Пример #5
0
    if ($location_before_ts) {
        $location_query->where_lt("timestamp", $location_before_ts);
    } else {
        $location_query->order_by_desc("timestamp");
    }
    return $location_query;
}
if (DO_LOCATIONS) {
    $openpath_query = generate_location_query($location_before_ts, $location_after_ts);
    $openpath_query->where("source", "openpaths");
    $openpath_rows = $openpath_query->find_array();
    $return['log'][] = ORM::get_last_query();
    $foursquare_query = generate_location_query($location_before_ts, $location_after_ts);
    $foursquare_query->where_not_equal("source", "openpaths");
    $foursquare_rows = $foursquare_query->find_array();
    $return['log'][] = ORM::get_last_query();
    // echo "<pre>";
    // var_dump($openpath_rows);
    // echo "\n\n";
    // var_dump(ORM::get_last_query());
    // die("HellO");
    $locations = array();
    $location_rows = array_merge($openpath_rows, $foursquare_rows);
    foreach ($openpath_rows as $row) {
        if (!$row['lat'] || !$row['long']) {
            continue;
        }
        if ($row['title']) {
            $title = $row['title'];
        } else {
            $title = $row['timestamp'];
Пример #6
0
 public function testHasManyThroughRelationWithCustomIntermediateModelAndKeyNames()
 {
     $book2 = Model::factory('BookTwo')->find_one(1);
     $authors2 = $book2->authors()->find_many();
     $expected = "SELECT `author`.* FROM `author` JOIN `author_book` ON `author`.`id` = `author_book`.`custom_author_id` WHERE `author_book`.`custom_book_id` = '1'";
     $this->assertEquals($expected, ORM::get_last_query());
 }
Пример #7
0
ORM::for_table('widget')->find_one(5);
$expected = "SELECT * FROM `widget` WHERE `primary_key` = '5' LIMIT 1";
Tester::check_equal("Setting: id_column", $expected);
ORM::configure('id_column_overrides', array('widget' => 'widget_id', 'widget_handle' => 'widget_handle_id'));
ORM::for_table('widget')->find_one(5);
$expected = "SELECT * FROM `widget` WHERE `widget_id` = '5' LIMIT 1";
Tester::check_equal("Setting: id_column_overrides, first test", $expected);
ORM::for_table('widget_handle')->find_one(5);
$expected = "SELECT * FROM `widget_handle` WHERE `widget_handle_id` = '5' LIMIT 1";
Tester::check_equal("Setting: id_column_overrides, second test", $expected);
ORM::for_table('widget_nozzle')->find_one(5);
$expected = "SELECT * FROM `widget_nozzle` WHERE `primary_key` = '5' LIMIT 1";
Tester::check_equal("Setting: id_column_overrides, third test", $expected);
ORM::for_table('widget')->use_id_column('new_id')->find_one(5);
$expected = "SELECT * FROM `widget` WHERE `new_id` = '5' LIMIT 1";
Tester::check_equal("Instance ID column, first test", $expected);
ORM::for_table('widget_handle')->use_id_column('new_id')->find_one(5);
$expected = "SELECT * FROM `widget_handle` WHERE `new_id` = '5' LIMIT 1";
Tester::check_equal("Instance ID column, second test", $expected);
ORM::for_table('widget_nozzle')->use_id_column('new_id')->find_one(5);
$expected = "SELECT * FROM `widget_nozzle` WHERE `new_id` = '5' LIMIT 1";
Tester::check_equal("Instance ID column, third test", $expected);
// Test caching. This is a bit of a hack.
ORM::configure('caching', true);
ORM::for_table('widget')->where('name', 'Fred')->where('age', 17)->find_one();
ORM::for_table('widget')->where('name', 'Bob')->where('age', 42)->find_one();
$expected = ORM::get_last_query();
ORM::for_table('widget')->where('name', 'Fred')->where('age', 17)->find_one();
// this shouldn't run a query!
Tester::check_equal("Caching, same query not run twice", $expected);
Tester::report();
Пример #8
0
 /**
  * Check the provided string is equal to the last
  * query generated by the dummy database class.
  */
 public static function check_query($test_name, $query)
 {
     $last_query = ORM::get_last_query();
     if ($query === $last_query) {
         self::report_pass($test_name);
     } else {
         self::report_failure($test_name, $query, $last_query);
     }
 }
 public function get_last_query()
 {
     return \ORM::get_last_query($this->connectionName);
 }
Пример #10
0
 public function last_query()
 {
     return Query::get_last_query();
 }
Пример #11
0
    }
    echo implode(";", $items);
});
$app->post('/genv/payhulu', function ($request, $response) {
    $uid = $_SESSION['uid'];
    $amount = $this->request->getParam("amount");
    try {
        ORM::get_db()->setAttribute(PDO::ATTR_AUTOCOMMIT, 0);
        ORM::get_db()->beginTransaction();
        //减去余额
        $sql = vsprintf("UPDATE %s SET `balance` = balance-%d WHERE `uid` = %d and `balance`>=%d ", array(table("members_points"), $amount, $uid, $amount));
        ORM::raw_execute($sql);
        //增加积分;
        $sql = vsprintf("UPDATE %s SET `points` = points+%d WHERE `uid` = %d   ", array(table("members_points"), $amount, $uid));
        ORM::raw_execute($sql);
        echo ORM::get_last_query();
        //
        //        Order::deduct_stock($order['coohua_id'], $order['product_id'], $order['order_code']);
        //        ORM::raw_execute("UPDATE `order` SET `check` = 5 WHERE `order_code` = ? and `check`=4 ", array($order['order_code']));
        ORM::get_db()->commit();
        ORM::get_db()->setAttribute(PDO::ATTR_AUTOCOMMIT, 1);
    } catch (Exception $e) {
        //dump($e);
        ORM::get_db()->rollBack();
    }
});
function listDir($dir)
{
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
Пример #12
0
 public function testStaticBackwardsCompatibilityNotices()
 {
     // adding the return until the fix has been implemented.
     $this->setExpectedException('PHPUnit_Framework_Error_Notice');
     ORM::for_table('widget')->find_many();
     $expected = "SELECT * FROM `widget`";
     $this->assertEquals($expected, ORM::get_last_query());
 }
Пример #13
0
<?php 
view('header');
?>


<div class="starter-template">
	<h1>An error occured!</h1>

	<p class="lead"><?php 
o($error->getMessage());
?>
</p>
	<p class="lead"><?php 
o(\ORM::get_last_query());
?>
</p>
	<div class="left-aligned">
		<?php 
dbg($error);
?>
	</div>
</div>

<?php 
view('footer');
 public function getLastQuery()
 {
     return \ORM::get_last_query();
 }