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

Generate Relations from Current Schema exception #186

Closed
sukvojte opened this issue Aug 29, 2016 · 8 comments
Closed

Generate Relations from Current Schema exception #186

sukvojte opened this issue Aug 29, 2016 · 8 comments
Labels
Milestone

Comments

@sukvojte
Copy link

What steps will reproduce the problem?

Open Gii and try generate model from a MySQL5.7 table with 'Generate Relations from Current Schema' set to TRUE.

What's expected?

Generated model or correct error warning when is defaultSchema empty, or automatically set schema from connection.

What do you get instead?

Exception:

Database Exception – yii\db\Exception
SQLSTATE[42000]: Syntax error or access violation: 1102 Incorrect database name ''
The SQL being executed was: SHOW TABLES FROM ``

Error Info: Array
(
[0] => 42000
[1] => 1102
[2] => Incorrect database name ''
)

Additional info

This hapends when Yii::$app->db->schema->defaultSchema is empty. But MySQL does not use default schema for user.
This bug bring commit fb52694 with new 'Generate Relations from Current Schema' option.

Q A
Yii version 2.0.10-dev
PHP version PHP 7.0.9
Operating system Win 8.1 64bit
@samdark
Copy link
Member

samdark commented Aug 29, 2016

That's code from master branch, right?

@samdark samdark added this to the 2.0.6 milestone Aug 29, 2016
@uldisn
Copy link
Contributor

uldisn commented Aug 29, 2016

I fixed change in yii2-gii\generators\model\Generator.php row 455 :

$schemaNames = ($this->generateRelationsFromCurrentSchema) ? [$db->schema->defaultSchema] : $this->getSchemaNames();
$schemaNames = $this->getSchemaNames();

@samdark
Copy link
Member

samdark commented Aug 29, 2016

Great. Could you send a pull request?

@uldisn uldisn mentioned this issue Aug 29, 2016
@samdark
Copy link
Member

samdark commented Aug 29, 2016

Oh. Looking at diff I see that it has a configurable feature removed.

@uldisn
Copy link
Contributor

uldisn commented Aug 29, 2016

$db->schema->defaultSchema must get actual table, but $this->getSchemaNames() do same.

@samdark
Copy link
Member

samdark commented Aug 29, 2016

@zlakomanoff any comments?

@zlakomanoff
Copy link
Contributor

@samdark i will check and fix tomorrow

@zlakomanoff
Copy link
Contributor

zlakomanoff commented Aug 30, 2016

@samdark @uldisn @cornernote @nergal @cebe

MySQL $defaultSchema always is empty

$defaultSchema string The default schema name used for the current session.

I think mysql $defaultSchema must contain current database name.
http://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_database

sqlite - the same issue, but this db have no schemas or db names (?)
oracle - fine, all users have schema with the same name as user
mssql - always 'dbo', need setup current schema (?)
pgsql - always 'public', need setup current schema (?)
cubrid - always empty, like a mysql

https://en.wikipedia.org/wiki/Database_schema

I will setup empty checking for cshema names, byt i think we need discuss about this isuue.
Another one solution - add $currentSchema option for schemas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants