123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace Medoo\Tests;
- /**
- * @coversDefaultClass \Medoo\Medoo
- */
- class GetTest extends MedooTestCase
- {
- /**
- * @covers ::get()
- * @dataProvider typesProvider
- */
- public function testGet($type)
- {
- $this->setType($type);
- $this->database->get("account", "email", [
- "user_id" => 1234
- ]);
- $this->assertQuery([
- 'default' => <<<EOD
- SELECT "email"
- FROM "account"
- WHERE "user_id" = 1234
- LIMIT 1
- EOD,
- 'mssql' => <<<EOD
- SELECT [email]
- FROM [account]
- WHERE [user_id] = 1234
- ORDER BY (SELECT 0)
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- 'oracle' => <<<EOD
- SELECT "email"
- FROM "account"
- WHERE "user_id" = 1234
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- ], $this->database->queryString);
- }
- /**
- * @covers ::get()
- * @dataProvider typesProvider
- */
- public function testGetWithColumns($type)
- {
- $this->setType($type);
- $this->database->get("account", [
- "email",
- "location"
- ], [
- "user_id" => 1234
- ]);
- $this->assertQuery([
- 'default' => <<<EOD
- SELECT "email","location"
- FROM "account"
- WHERE "user_id" = 1234
- LIMIT 1
- EOD,
- 'mssql' => <<<EOD
- SELECT [email],[location]
- FROM [account]
- WHERE [user_id] = 1234
- ORDER BY (SELECT 0)
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- 'oracle' => <<<EOD
- SELECT "email","location"
- FROM "account"
- WHERE "user_id" = 1234
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- ], $this->database->queryString);
- }
- /**
- * @covers ::get()
- * @dataProvider typesProvider
- */
- public function testGetWithJoin($type)
- {
- $this->setType($type);
- $this->database->get("post", [
- "[>]account" => "user_id"
- ], [
- "post.content",
- "account.user_name"
- ]);
- $this->assertQuery([
- 'default' => <<<EOD
- SELECT "post"."content","account"."user_name"
- FROM "post"
- LEFT JOIN "account" USING ("user_id")
- LIMIT 1
- EOD,
- 'mssql' => <<<EOD
- SELECT [post].[content],[account].[user_name]
- FROM [post]
- LEFT JOIN [account] USING ([user_id])
- ORDER BY (SELECT 0)
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- 'oracle' => <<<EOD
- SELECT "post"."content","account"."user_name"
- FROM "post"
- LEFT JOIN "account" USING ("user_id")
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- ], $this->database->queryString);
- }
- /**
- * @covers ::get()
- * @dataProvider typesProvider
- */
- public function testGetWithJoinAndWhere($type)
- {
- $this->setType($type);
- $this->database->get("post", [
- "[>]account" => "user_id"
- ], [
- "post.content",
- "account.user_name"
- ], [
- 'account.age[>]' => 18
- ]);
- $this->assertQuery([
- 'default' => <<<EOD
- SELECT "post"."content","account"."user_name"
- FROM "post"
- LEFT JOIN "account" USING ("user_id")
- WHERE "account"."age" > 18
- LIMIT 1
- EOD,
- 'mssql' => <<<EOD
- SELECT [post].[content],[account].[user_name]
- FROM [post]
- LEFT JOIN [account] USING ([user_id])
- WHERE [account].[age] > 18
- ORDER BY (SELECT 0)
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- 'oracle' => <<<EOD
- SELECT "post"."content","account"."user_name"
- FROM "post"
- LEFT JOIN "account" USING ("user_id")
- WHERE "account"."age" > 18
- OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
- EOD,
- ], $this->database->queryString);
- }
- }
|