123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace Medoo\Tests;
- use Medoo\Medoo;
- /**
- * @coversDefaultClass \Medoo\Medoo
- */
- class QueryTest extends MedooTestCase
- {
- /**
- * @covers ::query()
- * @covers ::isRaw()
- * @covers ::buildRaw()
- * @dataProvider typesProvider
- */
- public function testQuery($type)
- {
- $this->setType($type);
- $this->database->query("SELECT <account.email>,<account.nickname> FROM <account> WHERE <id> != 100");
- $this->assertQuery(
- <<<EOD
- SELECT "account"."email","account"."nickname"
- FROM "account"
- WHERE "id" != 100
- EOD,
- $this->database->queryString
- );
- }
- /**
- * @covers ::query()
- * @covers ::isRaw()
- * @covers ::buildRaw()
- */
- public function testQueryWithPrefix()
- {
- $database = new Medoo([
- 'testMode' => true,
- 'prefix' => 'PREFIX_'
- ]);
- $database->type = "sqlite";
- $database->query("SELECT <account.name> FROM <account>");
- $this->assertQuery(
- <<<EOD
- SELECT "PREFIX_account"."name"
- FROM "PREFIX_account"
- EOD,
- $database->queryString
- );
- }
- /**
- * @covers ::query()
- * @covers ::isRaw()
- * @covers ::buildRaw()
- */
- public function testQueryTableWithPrefix()
- {
- $database = new Medoo([
- 'testMode' => true,
- 'prefix' => 'PREFIX_'
- ]);
- $database->type = "sqlite";
- $database->query("DROP TABLE IF EXISTS <account>");
- $this->assertQuery(
- <<<EOD
- DROP TABLE IF EXISTS "PREFIX_account"
- EOD,
- $database->queryString
- );
- }
- /**
- * @covers ::query()
- * @covers ::isRaw()
- * @covers ::buildRaw()
- * @dataProvider typesProvider
- */
- public function testPreparedStatementQuery($type)
- {
- $this->setType($type);
- $this->database->query(
- "SELECT * FROM <account> WHERE <user_name> = :user_name AND <age> = :age",
- [
- ":user_name" => "John Smite",
- ":age" => 20
- ]
- );
- $this->assertQuery(
- <<<EOD
- SELECT *
- FROM "account"
- WHERE "user_name" = 'John Smite' AND "age" = 20
- EOD,
- $this->database->queryString
- );
- }
- /**
- * @covers ::query()
- * @covers ::isRaw()
- * @covers ::buildRaw()
- */
- public function testQueryEscape()
- {
- $database = new Medoo([
- 'testMode' => true,
- 'prefix' => 'PREFIX_'
- ]);
- $database->type = "sqlite";
- $database->query("SELECT * FROM <account> WHERE <name> = '<John>'");
- $this->assertQuery(
- <<<EOD
- SELECT *
- FROM "PREFIX_account"
- WHERE "name" = '<John>'
- EOD,
- $database->queryString
- );
- }
- }
|