-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [SQLSRV] Query Builder always sets "<database>"."<schema>".
to the table name.
#8786
Conversation
@codeigniter4/database-team Then I am not sure why only SQLSRV generates table names with database and schema names. |
Do we have this problem with postgre too? I know it uses schema sometimes as well.. |
@sclubricants No. Only SQLSRV has the
This test passes. --- a/tests/system/Database/Builder/FromTest.php
+++ b/tests/system/Database/Builder/FromTest.php
@@ -15,6 +15,7 @@ namespace CodeIgniter\Database\Builder;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Database\SQLSRV\Builder as SQLSRVBuilder;
+use CodeIgniter\Database\Postgre\Builder as PostgreBuilder;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockConnection;
@@ -153,4 +154,15 @@ final class FromTest extends CIUnitTestCase
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
}
+
+ public function testConstructorWithMultipleSegmentTable(): void
+ {
+ $this->db = new MockConnection(['DBDriver' => 'Postgre', 'database' => 'test', 'schema' => 'dbo']);
+
+ $builder = new PostgreBuilder('database.dbo.table', $this->db);
+
+ $expectedSQL = 'SELECT * FROM "database"."dbo"."table"';
+
+ $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
+ }
} |
It was related to some reported issue, but I can't find it now. I believe it was something related to using non-default AFAIR in SQLSRV you can't declare something like |
@michalsn This? #4246 It seems SQLSRV was added in #3714, and it uses
/**
* Get full name of the table
*
* @param string $table
*
* @return string
*/
private function getFullName(string $table): string
{
if ($this->db->escapeChar === '"')
{
return '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '"."' . str_replace('"', '', $table) . '"';
}
return '[' . $this->db->getDatabase() . '].[' . $this->db->schema . '].[' . str_replace('"', '', $table) . ']';
} |
I googled, but yes, there seems no way to set schema in a connection. |
Yes, that was the issue/PR I had in mind. The |
Okay, in summary, it looks like this?
|
Yes. |
@ping-yee Thank you! |
"<database>"."<schema>".
to the table name.
Description
See #8697
Checklist: