Skip to content
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 select queries in SQLSRV when using different schema #4246

Merged
merged 2 commits into from
Feb 12, 2021

Conversation

michalsn
Copy link
Member

@michalsn michalsn commented Feb 7, 2021

Description
This PR fixes SQLSRV Builder class behavior when select queries don't include declared database schema in the query.

Closes #4241

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn mentioned this pull request Feb 7, 2021
5 tasks
@hdrodriguez
Copy link

hdrodriguez commented Feb 7, 2021

I like it because it takes into account the use of aliases, but in the explode it does not take into account the passing of a schema through the model, I would like to handle this issue.

@hdrodriguez
Copy link

hdrodriguez commented Feb 7, 2021

private function getFullName(string $table): string
	{

        $tableExploded = explode('.', $table);

        $alias = '';

        if (count($tableExploded) === 2)
        {
            $this->db->schema = str_replace('"', '', $tableExploded[0]);
            $tableName        = $tableExploded[1];
            
        }
        else
        {
            $tableName = $table;
        }


        if (strpos($tableName, ' ') !== false)
        {
            $alias = explode(' ', $tableName);
            $tableName = array_shift($alias);
            $alias = ' ' . implode(' ', $alias);
        }
        

        if ($this->db->escapeChar === '"')
        {
            return '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '"."' . str_replace('"', '', $tableName) . '"' . $alias;
        }
        return '[' . $this->db->getDatabase() . '].[' . $this->db->schema . '].[' . str_replace('"', '', $tableName) . ']' . str_replace('"', '', $alias);;
	}

@michalsn
Copy link
Member Author

michalsn commented Feb 7, 2021

@hdrodriguez This seems more like a feature request. Please send it in a separate PR after this one will be merged. In this PR we're just fixing a buggy functionality.

@lonnieezell lonnieezell merged commit c9f2954 into codeigniter4:develop Feb 12, 2021
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants