|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Tests\CommandTest as AbstractCommandTest; |
|
8
|
|
|
|
|
9
|
|
|
class CommandTest extends AbstractCommandTest |
|
10
|
|
|
{ |
|
11
|
|
|
protected ?string $driverName = 'sqlite'; |
|
12
|
|
|
|
|
13
|
|
|
public function testAutoQuoting(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$db = $this->getConnection(false); |
|
16
|
|
|
|
|
17
|
|
|
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t'; |
|
18
|
|
|
|
|
19
|
|
|
$command = $db->createCommand($sql); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals('SELECT `id`, `t`.`name` FROM `customer` t', $command->getSql()); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @dataProvider upsertProvider |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $firstData |
|
28
|
|
|
* @param array $secondData |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testUpsert(array $firstData, array $secondData) |
|
31
|
|
|
{ |
|
32
|
|
|
if (version_compare($this->getConnection(false)->getServerVersion(), '3.8.3', '<')) { |
|
33
|
|
|
$this->markTestSkipped('SQLite < 3.8.3 does not support "WITH" keyword.'); |
|
34
|
|
|
|
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
parent::testUpsert($firstData, $secondData); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testAddDropPrimaryKey(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->markTestSkipped('SQLite does not support adding/dropping primary keys.'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testAddDropForeignKey(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->markTestSkipped('SQLite does not support adding/dropping foreign keys.'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testAddDropUnique(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->markTestSkipped('SQLite does not support adding/dropping unique constraints.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testAddDropCheck(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->markTestSkipped('SQLite does not support adding/dropping check constraints.'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testMultiStatementSupport() |
|
62
|
|
|
{ |
|
63
|
|
|
$db = $this->getConnection(false, true); |
|
64
|
|
|
|
|
65
|
|
|
$sql = <<<'SQL' |
|
66
|
|
|
DROP TABLE IF EXISTS {{T_multistatement}}; |
|
67
|
|
|
CREATE TABLE {{T_multistatement}} ( |
|
68
|
|
|
[[intcol]] INTEGER, |
|
69
|
|
|
[[textcol]] TEXT |
|
70
|
|
|
); |
|
71
|
|
|
INSERT INTO {{T_multistatement}} VALUES(41, :val1); |
|
72
|
|
|
INSERT INTO {{T_multistatement}} VALUES(42, :val2); |
|
73
|
|
|
SQL; |
|
74
|
|
|
|
|
75
|
|
|
$db->createCommand($sql, [ |
|
76
|
|
|
'val1' => 'foo', |
|
77
|
|
|
'val2' => 'bar', |
|
78
|
|
|
])->execute(); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertSame([ |
|
81
|
|
|
[ |
|
82
|
|
|
'intcol' => '41', |
|
83
|
|
|
'textcol' => 'foo', |
|
84
|
|
|
], |
|
85
|
|
|
[ |
|
86
|
|
|
'intcol' => '42', |
|
87
|
|
|
'textcol' => 'bar', |
|
88
|
|
|
], |
|
89
|
|
|
], $db->createCommand('SELECT * FROM {{T_multistatement}}')->queryAll()); |
|
90
|
|
|
|
|
91
|
|
|
$sql = <<<'SQL' |
|
92
|
|
|
UPDATE {{T_multistatement}} SET [[intcol]] = :newInt WHERE [[textcol]] = :val1; |
|
93
|
|
|
DELETE FROM {{T_multistatement}} WHERE [[textcol]] = :val2; |
|
94
|
|
|
SELECT * FROM {{T_multistatement}} |
|
95
|
|
|
SQL; |
|
96
|
|
|
|
|
97
|
|
|
$this->assertSame([ |
|
98
|
|
|
[ |
|
99
|
|
|
'intcol' => '410', |
|
100
|
|
|
'textcol' => 'foo', |
|
101
|
|
|
], |
|
102
|
|
|
], $db->createCommand($sql, [ |
|
103
|
|
|
'newInt' => 410, |
|
104
|
|
|
'val1' => 'foo', |
|
105
|
|
|
'val2' => 'bar', |
|
106
|
|
|
])->queryAll()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function batchInsertSqlProvider(): array |
|
110
|
|
|
{ |
|
111
|
|
|
$parent = parent::batchInsertSqlProvider(); |
|
112
|
|
|
unset($parent['wrongBehavior']); // Produces SQL syntax error: General error: 1 near ".": syntax error |
|
113
|
|
|
|
|
114
|
|
|
return $parent; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|