forked from nette/database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultSet.normalizeRow.sqlite.phpt
More file actions
128 lines (113 loc) · 2.7 KB
/
ResultSet.normalizeRow.sqlite.phpt
File metadata and controls
128 lines (113 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Test: Nette\Database\ResultSet::normalizeRow()
* @dataProvider? databases.ini sqlite
*/
declare(strict_types=1);
use Nette\Database\DateTime;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$connection = connectToDB();
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql');
$res = $connection->query('SELECT * FROM types');
Assert::equal([
'int' => 1,
'integer' => 1,
'tinyint' => 1,
'smallint' => 1,
'mediumint' => 1,
'bigint' => 1,
'unsigned_big_int' => 1,
'int2' => 1,
'int8' => 1,
'character_20' => 'a',
'varchar_255' => 'a',
'varying_character_255' => 'a',
'nchar_55' => 'a',
'native_character_70' => 'a',
'nvarchar_100' => 'a',
'text' => 'a',
'clob' => 'a',
'blob' => 'a',
'real' => 1.1,
'double' => 1.1,
'double precision' => 1.1,
'float' => 1.1,
'numeric' => 1.1,
'decimal_10_5' => 1.1,
'boolean' => true,
'date' => new DateTime('2012-10-13'),
'datetime' => new DateTime('2012-10-13 10:10:10'),
'omitted' => 'a',
], (array) $res->fetch());
Assert::equal([
'int' => 0,
'integer' => 0,
'tinyint' => 0,
'smallint' => 0,
'mediumint' => 0,
'bigint' => 0,
'unsigned_big_int' => 0,
'int2' => 0,
'int8' => 0,
'character_20' => '',
'varchar_255' => '',
'varying_character_255' => '',
'nchar_55' => '',
'native_character_70' => '',
'nvarchar_100' => '',
'text' => '',
'clob' => '',
'blob' => '',
'real' => 0.5,
'double' => 0.5,
'double precision' => 0.5,
'float' => 0.5,
'numeric' => 0.5,
'decimal_10_5' => 0.5,
'boolean' => false,
'date' => new DateTime('1970-01-01'),
'datetime' => new DateTime('1970-01-01 00:00:00'),
'omitted' => '',
], (array) $res->fetch());
Assert::same([
'int' => null,
'integer' => null,
'tinyint' => null,
'smallint' => null,
'mediumint' => null,
'bigint' => null,
'unsigned_big_int' => null,
'int2' => null,
'int8' => null,
'character_20' => null,
'varchar_255' => null,
'varying_character_255' => null,
'nchar_55' => null,
'native_character_70' => null,
'nvarchar_100' => null,
'text' => null,
'clob' => null,
'blob' => null,
'real' => null,
'double' => null,
'double precision' => null,
'float' => null,
'numeric' => null,
'decimal_10_5' => null,
'boolean' => null,
'date' => null,
'datetime' => null,
'omitted' => null,
], (array) $res->fetch());
$res = $connection->query('SELECT [int] AS a, [text] AS a FROM types');
Assert::same([
'a' => 'a',
], (array) @$res->fetch());
$res = $connection->query('SELECT SUM([int]) AS int_sum, AVG([int]) AS int_avg, SUM([double]) AS float_sum, AVG([double]) AS float_avg FROM types WHERE [int] = 1 GROUP BY [int]');
Assert::same([
'int_sum' => 1,
'int_avg' => 1.0,
'float_sum' => 1.1,
'float_avg' => 1.1,
], (array) $res->fetch());