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
Beispiel #1
0
 public function testInstanceIdColumnThree()
 {
     $this->setUpIdColumnOverrides();
     ORM::for_table('widget_nozzle')->use_id_column('new_id')->find_one(5);
     $expected = "SELECT * FROM `widget_nozzle` WHERE `new_id` = '5' LIMIT 1";
     $this->assertEquals($expected, ORM::get_last_query());
     $this->tearDownIdColumnOverrides();
 }
Beispiel #2
0
 public function testQueryGenerationOnlyOccursOnceWithMultipleConnections()
 {
     // Test caching with multiple connections (also a bit of a hack)
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one();
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Tom')->where('age', 120)->find_one();
     $expected = ORM::get_last_query();
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one();
     // this shouldn't run a query!
     $this->assertEquals($expected, ORM::get_last_query(self::ALTERNATE));
 }
 public function testFindOneOverDifferentConnections()
 {
     ORM::for_table('widget')->find_one();
     $statementOne = ORM::get_last_statement();
     $this->assertInstanceOf('MockPDOStatement', $statementOne);
     ORM::for_table('person', self::ALTERNATE)->find_one();
     $statementOne = ORM::get_last_statement();
     // get_statement is *not* per connection
     $this->assertInstanceOf('MockDifferentPDOStatement', $statementOne);
     $expected = "SELECT * FROM `widget` LIMIT 1";
     $this->assertNotEquals($expected, ORM::get_last_query());
     // Because get_last_query() is across *all* connections
     $this->assertEquals($expected, ORM::get_last_query(ORM::DEFAULT_CONNECTION));
     $expectedToo = "SELECT * FROM `person` LIMIT 1";
     $this->assertEquals($expectedToo, ORM::get_last_query(self::ALTERNATE));
 }
Beispiel #4
0
 public function testIssue90UsingSetExprAloneDoesTriggerQueryGeneration()
 {
     $widget = ORM::for_table('widget')->find_one(1);
     $widget->set_expr('added', 'NOW()');
     $widget->save();
     $expected = "UPDATE `widget` SET `added` = NOW() WHERE `id` = '1'";
     $this->assertEquals($expected, ORM::get_last_query());
 }
 public function testLimit()
 {
     ORM::for_table('widget')->limit(5)->find_many();
     $expected = 'SELECT TOP 5 * FROM "widget"';
     $this->assertEquals($expected, ORM::get_last_query());
 }