Skip to content

Commit 38fb5b2

Browse files
committed
test: add test for updateBatch() with constrants DATE
1 parent 1bffa76 commit 38fb5b2

1 file changed

Lines changed: 77 additions & 1 deletion

File tree

tests/system/Database/Live/UpdateTest.php

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testUpdateWithWhereAndLimit(): void
111111
}
112112
}
113113

114-
public function testUpdateBatch(): void
114+
public function testUpdateBatchConstraintsVarchar(): void
115115
{
116116
$table = 'type_test';
117117

@@ -189,6 +189,82 @@ public function testUpdateBatch(): void
189189
}
190190
}
191191

192+
public function testUpdateBatchConstraintsDate(): void
193+
{
194+
$table = 'type_test';
195+
196+
// Prepares test data.
197+
$builder = $this->db->table($table);
198+
$builder->truncate();
199+
200+
for ($i = 1; $i < 4; $i++) {
201+
$builder->insert([
202+
'type_varchar' => 'test' . $i,
203+
'type_char' => 'char',
204+
'type_text' => 'text',
205+
'type_smallint' => 32767,
206+
'type_integer' => 2_147_483_647,
207+
'type_bigint' => 9_223_372_036_854_775_807,
208+
'type_float' => 10.1,
209+
'type_numeric' => 123.23,
210+
'type_date' => '2023-12-0' . $i,
211+
'type_datetime' => '2023-12-21 12:00:00',
212+
]);
213+
}
214+
215+
$data = [
216+
[
217+
'type_text' => 'updated',
218+
'type_bigint' => 9_999_999,
219+
'type_date' => '2023-12-01', // Key
220+
'type_datetime' => '2024-01-01 09:00:00',
221+
],
222+
[
223+
'type_text' => 'updated',
224+
'type_bigint' => 9_999_999,
225+
'type_date' => '2023-12-02', // Key
226+
'type_datetime' => '2024-01-01 09:00:00',
227+
],
228+
];
229+
$this->db->table($table)->updateBatch($data, 'type_date');
230+
231+
if ($this->db->DBDriver === 'SQLSRV') {
232+
// We cannot compare `text` and `varchar` with `=`. It causes the error:
233+
// [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The data types text and varchar are incompatible in the equal to operator.
234+
// And data type `text`, `ntext`, `image` are deprecated in SQL Server 2016
235+
// See https://github.com/codeigniter4/CodeIgniter4/pull/8439#issuecomment-1902535909
236+
$this->seeInDatabase($table, [
237+
'type_varchar' => 'test1',
238+
// 'type_text' => 'updated',
239+
'type_bigint' => 9_999_999,
240+
'type_date' => '2023-12-01',
241+
'type_datetime' => '2024-01-01 09:00:00',
242+
]);
243+
$this->seeInDatabase($table, [
244+
'type_varchar' => 'test2',
245+
// 'type_text' => 'updated',
246+
'type_bigint' => 9_999_999,
247+
'type_date' => '2023-12-02',
248+
'type_datetime' => '2024-01-01 09:00:00',
249+
]);
250+
} else {
251+
$this->seeInDatabase($table, [
252+
'type_varchar' => 'test1',
253+
'type_text' => 'updated',
254+
'type_bigint' => 9_999_999,
255+
'type_date' => '2023-12-01',
256+
'type_datetime' => '2024-01-01 09:00:00',
257+
]);
258+
$this->seeInDatabase($table, [
259+
'type_varchar' => 'test2',
260+
'type_text' => 'updated',
261+
'type_bigint' => 9_999_999,
262+
'type_date' => '2023-12-02',
263+
'type_datetime' => '2024-01-01 09:00:00',
264+
]);
265+
}
266+
}
267+
192268
public function testUpdateWithWhereSameColumn(): void
193269
{
194270
$this->db->table('user')->update(['country' => 'CA'], ['country' => 'US']);

0 commit comments

Comments
 (0)