Welcome Guest, Not a member yet? Register   Sign In
Problem SQLSRV join another database
#1

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB