atk4 / schema

Few classes built on top of Agile Data that can take care of your SQL database schema
https://agiletoolkit.org/
MIT License
4 stars 5 forks source link

Getting exceptions with Migration object #58

Closed acicovic closed 4 years ago

acicovic commented 4 years ago

Hi,

$app = new App();
$migrator = new Migration($app->db);
$migrator->table('test')
    ->id()
    ->create();

This code (and similar operations) gives me exceptions.

error:"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\"test\" (\"id\" bigint unsigned not null primary key autoincrement)' at line 1"

query:"create table \"test\" (\"id\" bigint unsigned not null primary key autoincrement)"

I'm using MariaDB 10.2.31 and PHP 7.4.5, with all ATK packages to latest stable versions.

Can anyone reproduce this?

DarkSide666 commented 4 years ago

I think it's because of wrong escape character? In your query it uses ", but MySQL should probably use ` What's your connection string? Which persistence connection sub-class is it using?

acicovic commented 4 years ago

Calls like the following work normally:

$app->add(MigratorConsole::class)
     ->migrateModels([
         new Address($db),
         new Bank($db)
     ]);

My connection string is mysql://root@localhost/myinvoice (local environment, root without password). I don't have a custom escape character defined and I never had any similar problems with ATK Data.

About your last question, if you still need an answer to this, can you give me a quick indication on where I could put a breakpoint to debug this?

Thanks.

DarkSide666 commented 4 years ago

Are you using $app->dbConnect(...) when connecting ? Try var_dump(get_class($app->db))

acicovic commented 4 years ago

Yes, I use dbConnect var_dump returns atk4\data\Persistence\SQL

DarkSide666 commented 4 years ago

And what about var_dump(get_class($app->db->connection)) and var_dump(get_class($app->db->connection->dsql()))

dsql() should return Query_MySQL class.

acicovic commented 4 years ago

atk4\dsql\Connection atk4\dsql\Query_MySQL

So everything seems normal?

DarkSide666 commented 4 years ago

yes everything seems normal, but strangely it still use " as escape char in sql.

acicovic commented 4 years ago

OK, maybe I will try to debug it.

acicovic commented 4 years ago

This is probably specific to my configuration and I have no time to troubleshoot it for the time being. I will close this issue and re-open if needed.