Skip to content

Commit 65505ee

Browse files
authored
Merge branch 'codeigniter4:develop' into patch-10
2 parents 6056e30 + 759344e commit 65505ee

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

system/Database/SQLSRV/Builder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ private function getFullName(string $table): string
297297
}
298298

299299
if ($this->db->escapeChar === '"') {
300+
if (str_contains($table, '.') && ! str_starts_with($table, '.') && ! str_ends_with($table, '.')) {
301+
$dbInfo = explode('.', $table);
302+
$database = $this->db->getDatabase();
303+
$table = $dbInfo[0];
304+
305+
if (count($dbInfo) === 3) {
306+
$database = str_replace('"', '', $dbInfo[0]);
307+
$schema = str_replace('"', '', $dbInfo[1]);
308+
$tableName = str_replace('"', '', $dbInfo[2]);
309+
} else {
310+
$schema = str_replace('"', '', $dbInfo[0]);
311+
$tableName = str_replace('"', '', $dbInfo[1]);
312+
}
313+
314+
return '"' . $database . '"."' . $schema . '"."' . str_replace('"', '', $tableName) . '"' . $alias;
315+
}
316+
300317
return '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '"."' . str_replace('"', '', $table) . '"' . $alias;
301318
}
302319

system/Test/Mock/MockCache.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ public function remember(string $key, int $ttl, Closure $callback)
9292
* @param string $key Cache item name
9393
* @param mixed $value the data to save
9494
* @param int $ttl Time To Live, in seconds (default 60)
95-
* @param bool $raw Whether to store the raw value.
9695
*
9796
* @return bool
9897
*/
99-
public function save(string $key, $value, int $ttl = 60, bool $raw = false)
98+
public function save(string $key, $value, int $ttl = 60)
10099
{
101100
if ($this->bypass) {
102101
return false;

tests/system/Database/Builder/FromTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,32 @@ public function testFromSubqueryWithSQLSRV(): void
153153

154154
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
155155
}
156+
157+
/**
158+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8697
159+
*/
160+
public function testConstructorWithMultipleSegmentTableWithSQLSRV(): void
161+
{
162+
$this->db = new MockConnection(['DBDriver' => 'SQLSRV', 'database' => 'test', 'schema' => 'dbo']);
163+
164+
$builder = new SQLSRVBuilder('database.dbo.table', $this->db);
165+
166+
$expectedSQL = 'SELECT * FROM "database"."dbo"."table"';
167+
168+
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
169+
}
170+
171+
/**
172+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8697
173+
*/
174+
public function testConstructorWithMultipleSegmentTableWithoutDatabaseWithSQLSRV(): void
175+
{
176+
$this->db = new MockConnection(['DBDriver' => 'SQLSRV', 'database' => 'test', 'schema' => 'dbo']);
177+
178+
$builder = new SQLSRVBuilder('dbo.table', $this->db);
179+
180+
$expectedSQL = 'SELECT * FROM "test"."dbo"."table"';
181+
182+
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
183+
}
156184
}

user_guide_src/source/dbmgmt/forge.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Returns true/false based on success or failure:
4141
.. literalinclude:: forge/003.php
4242

4343
An optional second parameter set to true will add ``IF EXISTS`` statement
44-
or will check if a database exists before create it (depending on DBMS).
44+
or will check if a database exists before creating it (depending on DBMS).
4545

4646
.. literalinclude:: forge/004.php
4747

user_guide_src/source/dbmgmt/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CodeIgniter comes with tools to restructure or seed your database.
77
.. toctree::
88
:titlesonly:
99

10-
Database Manipulation with Database Forge <forge>
10+
Database Forge <forge>
1111
Database Migrations <migration>
1212
Database Seeding <seeds>
1313
db_commands

user_guide_src/source/dbmgmt/migration.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Migrates a database group with all available migrations:
121121
122122
php spark migrate
123123
124-
You can use (migrate) with the following options:
124+
You can use ``migrate`` with the following options:
125125

126126
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be run. If not specified, all migrations will be run.
127127
- ``-n`` - to choose namespace, otherwise ``App`` namespace will be used.
@@ -145,38 +145,38 @@ When using the ``--all`` option, it will scan through all namespaces attempting
145145
not been run. These will all be collected and then sorted as a group by date created. This should help
146146
to minimize any potential conflicts between the main application and any modules.
147147

148-
rollback
149-
========
148+
migrate:rollback
149+
================
150150

151151
Rolls back all migrations to a blank slate, effectively migration 0:
152152

153153
.. code-block:: console
154154
155155
php spark migrate:rollback
156156
157-
You can use (rollback) with the following options:
157+
You can use ``migrate:rollback`` with the following options:
158158

159159
- ``-b`` - to choose a batch: natural numbers specify the batch.
160160
- ``-f`` - to force a bypass confirmation question, it is only asked in a production environment.
161161

162-
refresh
163-
=======
162+
migrate:refresh
163+
===============
164164

165165
Refreshes the database state by first rolling back all migrations, and then migrating all:
166166

167167
.. code-block:: console
168168
169169
php spark migrate:refresh
170170
171-
You can use (refresh) with the following options:
171+
You can use ``migrate:refresh`` with the following options:
172172

173173
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be run. If not specified, all migrations will be run.
174174
- ``-n`` - to choose namespace, otherwise ``App`` namespace will be used.
175175
- ``--all`` - to refresh all namespaces.
176176
- ``-f`` - to force a bypass confirmation question, it is only asked in a production environment.
177177

178-
status
179-
======
178+
migrate:status
179+
==============
180180

181181
Displays a list of all migrations and the date and time they ran, or '--' if they have not been run:
182182

@@ -194,7 +194,7 @@ Displays a list of all migrations and the date and time they ran, or '--' if the
194194
| CodeIgniter\Settings | 2021-11-14-143905 | AddContextColumn | default | 2022-04-06 01:23:08 | 1 |
195195
+----------------------+-------------------+-----------------------+---------+---------------------+-------+
196196
197-
You can use (status) with the following options:
197+
You can use ``migrate:status`` with the following options:
198198

199199
- ``-g`` - to specify database group. If specified, only migrations for the specified database group will be checked. If not specified, all migrations will be checked.
200200

@@ -209,7 +209,7 @@ creates is the Pascal case version of the filename.
209209
210210
php spark make:migration <class> [options]
211211
212-
You can use (``make:migration``) with the following options:
212+
You can use ``make:migration`` with the following options:
213213

214214
- ``--namespace`` - Set root namespace. Default: ``APP_NAMESPACE``.
215215
- ``--suffix`` - Append the component title to the class name.

0 commit comments

Comments
 (0)