123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?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()
- * @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
- );
- }
- }
|