get_last_query() public static method

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
return string
コード例 #1
0
ファイル: TagController.php プロジェクト: netdust/ntdst-cms
 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
ファイル: table.php プロジェクト: bubach/VisualQuery
 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
ファイル: index.php プロジェクト: monstergfx/pi-music
<?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
ファイル: fetchNext.php プロジェクト: aquarion/Lifestream
    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
ファイル: GranadaTest.php プロジェクト: arunkapil/Granada
 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
ファイル: test_queries.php プロジェクト: zilionis/idiorm
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
ファイル: test_classes.php プロジェクト: powerpak/dakota
 /**
  * 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);
     }
 }
コード例 #9
0
 public function get_last_query()
 {
     return \ORM::get_last_query($this->connectionName);
 }
コード例 #10
0
ファイル: SQLBackend.php プロジェクト: phpwax/db
 public function last_query()
 {
     return Query::get_last_query();
 }
コード例 #11
0
ファイル: leven.php プロジェクト: winiceo/job
    }
    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
ファイル: default.php プロジェクト: agroff/FindPuppies
<?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');
コード例 #14
0
 public function getLastQuery()
 {
     return \ORM::get_last_query();
 }