Skip to content

Commit 22feedb

Browse files
committed
refactor: remove deprecations in Database
1 parent f048e06 commit 22feedb

File tree

21 files changed

+44
-300
lines changed

21 files changed

+44
-300
lines changed

system/Database/BaseBuilder.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,24 +2260,6 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
22602260
return str_replace('{:_table_:}', $data, $sql);
22612261
}
22622262

2263-
/**
2264-
* Allows key/value pairs to be set for batch inserts
2265-
*
2266-
* @param mixed $key
2267-
*
2268-
* @return $this|null
2269-
*
2270-
* @deprecated
2271-
*/
2272-
public function setInsertBatch($key, string $value = '', ?bool $escape = null)
2273-
{
2274-
if (! is_array($key)) {
2275-
$key = [[$key => $value]];
2276-
}
2277-
2278-
return $this->setData($key, $escape);
2279-
}
2280-
22812263
/**
22822264
* Compiles an insert query and returns the sql
22832265
*
@@ -2709,28 +2691,6 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
27092691
return str_replace('{:_table_:}', $data, $sql);
27102692
}
27112693

2712-
/**
2713-
* Allows key/value pairs to be set for batch updating
2714-
*
2715-
* @param array|object $key
2716-
*
2717-
* @return $this
2718-
*
2719-
* @throws DatabaseException
2720-
*
2721-
* @deprecated
2722-
*/
2723-
public function setUpdateBatch($key, string $index = '', ?bool $escape = null)
2724-
{
2725-
if ($index !== '') {
2726-
$this->onConstraint($index);
2727-
}
2728-
2729-
$this->setData($key, $escape);
2730-
2731-
return $this;
2732-
}
2733-
27342694
/**
27352695
* Compiles a delete string and runs "DELETE FROM table"
27362696
*
@@ -3550,18 +3510,6 @@ protected function setBind(string $key, $value = null, bool $escape = true): str
35503510
return $key . '.' . $count;
35513511
}
35523512

3553-
/**
3554-
* Returns a clone of a Base Builder with reset query builder values.
3555-
*
3556-
* @return $this
3557-
*
3558-
* @deprecated
3559-
*/
3560-
protected function cleanClone()
3561-
{
3562-
return (clone $this)->from([], true)->resetQuery();
3563-
}
3564-
35653513
/**
35663514
* @param mixed $value
35673515
*/

system/Database/BaseConnection.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
* @property-read bool $pretend
4646
* @property-read string $queryClass
4747
* @property-read array $reservedIdentifiers
48-
* @property-read bool $strictOn
4948
* @property-read string $subdriver
5049
* @property-read string $swapPre
5150
* @property-read int $transDepth
@@ -193,17 +192,6 @@ abstract class BaseConnection implements ConnectionInterface
193192
*/
194193
protected $compress = false;
195194

196-
/**
197-
* Strict ON flag
198-
*
199-
* Whether we're running in strict SQL mode.
200-
*
201-
* @var bool|null
202-
*
203-
* @deprecated 4.5.0 Will move to MySQLi\Connection.
204-
*/
205-
protected $strictOn;
206-
207195
/**
208196
* Settings for a failover connection.
209197
*

system/Database/Forge.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ class Forge
108108
*/
109109
protected $createTableStr = "%s %s (%s\n)";
110110

111-
/**
112-
* CREATE TABLE IF statement
113-
*
114-
* @var bool|string
115-
*
116-
* @deprecated This is no longer used.
117-
*/
118-
protected $createTableIfStr = 'CREATE TABLE IF NOT EXISTS';
119-
120111
/**
121112
* CREATE TABLE keys flag
122113
*
@@ -565,7 +556,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
565556
return true;
566557
}
567558

568-
$sql = $this->_createTable($table, false, $attributes);
559+
$sql = $this->_createTable($table, $attributes);
569560

570561
if (($result = $this->db->query($sql)) !== false) {
571562
if (isset($this->db->dataCache['table_names']) && ! in_array($table, $this->db->dataCache['table_names'], true)) {
@@ -586,13 +577,11 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
586577
}
587578

588579
/**
589-
* @param array $attributes Table attributes
580+
* @param array<string, mixed> $attributes Table attributes
590581
*
591582
* @return string SQL string
592-
*
593-
* @deprecated $ifNotExists is no longer used, and will be removed.
594583
*/
595-
protected function _createTable(string $table, bool $ifNotExists, array $attributes)
584+
protected function _createTable(string $table, array $attributes)
596585
{
597586
$processedFields = $this->_processFields(true);
598587

system/Database/MySQLi/Connection.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class Connection extends BaseConnection
9393
*/
9494
public $foundRows = false;
9595

96+
/**
97+
* Strict SQL mode
98+
*/
99+
protected bool $strictOn = false;
100+
96101
/**
97102
* Connect to the database.
98103
*
@@ -124,22 +129,19 @@ public function connect(bool $persistent = false)
124129
$this->mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
125130
}
126131

127-
// Build init command for strictOn and timezone
128132
$initCommands = [];
129133

130-
if ($this->strictOn !== null) {
131-
if ($this->strictOn) {
132-
$initCommands[] = "sql_mode = CONCAT(@@sql_mode, ',', 'STRICT_ALL_TABLES')";
133-
} else {
134-
$initCommands[] = "sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
135-
@@sql_mode,
136-
'STRICT_ALL_TABLES,', ''),
137-
',STRICT_ALL_TABLES', ''),
138-
'STRICT_ALL_TABLES', ''),
139-
'STRICT_TRANS_TABLES,', ''),
140-
',STRICT_TRANS_TABLES', ''),
141-
'STRICT_TRANS_TABLES', '')";
142-
}
134+
if ($this->strictOn) {
135+
$initCommands[] = "sql_mode = CONCAT(@@sql_mode, ',', 'STRICT_ALL_TABLES')";
136+
} else {
137+
$initCommands[] = "sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
138+
@@sql_mode,
139+
'STRICT_ALL_TABLES,', ''),
140+
',STRICT_ALL_TABLES', ''),
141+
'STRICT_ALL_TABLES', ''),
142+
'STRICT_TRANS_TABLES,', ''),
143+
',STRICT_TRANS_TABLES', ''),
144+
'STRICT_TRANS_TABLES', '')";
143145
}
144146

145147
// Set session timezone if configured
@@ -148,13 +150,10 @@ public function connect(bool $persistent = false)
148150
$initCommands[] = "time_zone = '{$timezoneOffset}'";
149151
}
150152

151-
// Set init command if we have any commands
152-
if ($initCommands !== []) {
153-
$this->mysqli->options(
154-
MYSQLI_INIT_COMMAND,
155-
'SET SESSION ' . implode(', ', $initCommands),
156-
);
157-
}
153+
$this->mysqli->options(
154+
MYSQLI_INIT_COMMAND,
155+
'SET SESSION ' . implode(', ', $initCommands),
156+
);
158157

159158
if (is_array($this->encrypt)) {
160159
$ssl = [];

system/Database/OCI8/Forge.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ class Forge extends BaseForge
3434
*/
3535
protected $createDatabaseStr = false;
3636

37-
/**
38-
* CREATE TABLE IF statement
39-
*
40-
* @var false
41-
*
42-
* @deprecated This is no longer used.
43-
*/
44-
protected $createTableIfStr = false;
45-
4637
/**
4738
* DROP TABLE IF EXISTS statement
4839
*

system/Database/SQLSRV/Connection.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -565,40 +565,6 @@ private function isUniqueConstraintViolation(): bool
565565
return false;
566566
}
567567

568-
/**
569-
* Returns the last error encountered by this connection.
570-
*
571-
* @return array<string, int|string>
572-
*
573-
* @deprecated Use `error()` instead.
574-
*/
575-
public function getError()
576-
{
577-
$error = [
578-
'code' => '00000',
579-
'message' => '',
580-
];
581-
582-
$sqlsrvErrors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
583-
584-
if (! is_array($sqlsrvErrors)) {
585-
return $error;
586-
}
587-
588-
$sqlsrvError = array_shift($sqlsrvErrors);
589-
if (isset($sqlsrvError['SQLSTATE'])) {
590-
$error['code'] = isset($sqlsrvError['code']) ? $sqlsrvError['SQLSTATE'] . '/' . $sqlsrvError['code'] : $sqlsrvError['SQLSTATE'];
591-
} elseif (isset($sqlsrvError['code'])) {
592-
$error['code'] = $sqlsrvError['code'];
593-
}
594-
595-
if (isset($sqlsrvError['message'])) {
596-
$error['message'] = $sqlsrvError['message'];
597-
}
598-
599-
return $error;
600-
}
601-
602568
/**
603569
* The name of the platform in use (MySQLi, mssql, etc)
604570
*/

system/Database/SQLSRV/Forge.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,6 @@ class Forge extends BaseForge
9494
*/
9595
protected $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT'];
9696

97-
/**
98-
* CREATE TABLE IF statement
99-
*
100-
* @var string
101-
*
102-
* @deprecated This is no longer used.
103-
*/
104-
protected $createTableIfStr;
105-
10697
/**
10798
* CREATE TABLE statement
10899
*

system/Database/Seeder.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use CodeIgniter\CLI\CLI;
1717
use CodeIgniter\Exceptions\InvalidArgumentException;
1818
use Config\Database;
19-
use Faker\Factory;
20-
use Faker\Generator;
2119

2220
/**
2321
* Class Seeder
@@ -66,13 +64,6 @@ class Seeder
6664
*/
6765
protected $silent = false;
6866

69-
/**
70-
* Faker Generator instance.
71-
*
72-
* @deprecated
73-
*/
74-
private static ?Generator $faker = null;
75-
7667
/**
7768
* Seeder constructor.
7869
*/
@@ -104,20 +95,6 @@ public function __construct(Database $config, ?BaseConnection $db = null)
10495
}
10596
}
10697

107-
/**
108-
* Gets the Faker Generator instance.
109-
*
110-
* @deprecated
111-
*/
112-
public static function faker(): ?Generator
113-
{
114-
if (! self::$faker instanceof Generator && class_exists(Factory::class)) {
115-
self::$faker = Factory::create();
116-
}
117-
118-
return self::$faker;
119-
}
120-
12198
/**
12299
* Loads the specified seeder and runs it.
123100
*

tests/_support/Config/Registrar.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Registrar
6060
'swapPre' => '',
6161
'encrypt' => false,
6262
'compress' => false,
63-
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
6463
'failover' => [],
6564
'port' => 5432,
6665
],
@@ -79,7 +78,6 @@ class Registrar
7978
'swapPre' => '',
8079
'encrypt' => false,
8180
'compress' => false,
82-
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
8381
'failover' => [],
8482
'port' => 3306,
8583
'foreignKeys' => true,
@@ -100,7 +98,6 @@ class Registrar
10098
'swapPre' => '',
10199
'encrypt' => false,
102100
'compress' => false,
103-
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
104101
'failover' => [],
105102
'port' => 1433,
106103
],
@@ -119,7 +116,6 @@ class Registrar
119116
'swapPre' => '',
120117
'encrypt' => false,
121118
'compress' => false,
122-
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
123119
'failover' => [],
124120
],
125121
];

tests/system/Database/BaseConnectionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ final class BaseConnectionTest extends CIUnitTestCase
4141
'swapPre' => '',
4242
'encrypt' => false,
4343
'compress' => false,
44-
'strictOn' => true,
4544
'failover' => [],
4645
'dateFormat' => [
4746
'date' => 'Y-m-d',
@@ -64,7 +63,6 @@ final class BaseConnectionTest extends CIUnitTestCase
6463
'swapPre' => '',
6564
'encrypt' => false,
6665
'compress' => false,
67-
'strictOn' => true,
6866
'failover' => [],
6967
];
7068

@@ -84,7 +82,6 @@ public function testSavesConfigOptions(): void
8482
$this->assertSame('', $db->swapPre);
8583
$this->assertFalse($db->encrypt);
8684
$this->assertFalse($db->compress);
87-
$this->assertTrue($db->strictOn);
8885
$this->assertSame([], $db->failover);
8986
$this->assertSame([
9087
'date' => 'Y-m-d',

0 commit comments

Comments
 (0)