CodeIgniter Forums
Problem SQLSRV join another database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Problem SQLSRV join another database (/showthread.php?tid=81518)



Problem SQLSRV join another database - climmmm - 03-14-2022

Hello,


We migrate a web application from CodeIgniter 3 to version 4. This application uses different databases on a SQLServer.
We have many sql queries with join methods between 2 different databases. The problem is that in CodeIgniter 4, the default database is added to the join function:

line 153, file system/Database/SQLSRV/Builder.php

Code:
$this->QBJoin[] = $type . 'JOIN ' . $this->getFullName($table) . $cond;


And in the method getFullName function :

Code:
if ($this->db->escapeChar === '"') {
   return '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '"."' . str_replace('"', '', $table) . '"' . $alias;
}

return '[' . $this->db->getDatabase() . '].[' . $this->db->schema . '].[' . str_replace('"', '', $table) . ']' . str_replace('"', '', $alias);


When we use in a Class model a TEST database and the join function on another TEST2 database like this :
Code:
$this->select('.....')->join('TEST2..TABLETEST', '.......') ....

The query is builded like this : 

Code:
SELECT .... FROM TEST
JOIN TEST.dbo.TEST2..TABLETEST


it returns an error but there is no possibility to do otherwise...

Can you have a solution please ?

Thank you