Skip to content

Conversation

@ondrej-nemec
Copy link

Switch between sql dialects will be usefull
-> added interface which allow this and two basic implementation - mysql and mssql
especly I need used this tool with MsSql Server


public function selectOneNull($tableName);

public function createTableIfNotExists($tableName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be less general, f.e. createMigrationTable($tableName).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, if I do new instance of this adapter, I will need know what I have to do
This return string which create table ONLY IF table not exists. This is very important


public function createTableIfNotExists($tableName);

public function insertIntoTable($tableName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insertIntoMigrationTable


public function insertIntoTable($tableName);

public function selectNullFromId($tableName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectByIdFromMigrationTable

$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->supportsMultiStatements = in_array($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME), [
"mysql"
$this->adapter->getDbType()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part checks if $this->pdo is capable to run multi statement. You can append another driver name to this array. Your change means that every adapter supports it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I don't undenstand you last sence. If adapter returns string which is not in array that means that multi select are not supporter, isn't it?


namespace PetrKnap\Php\MigrationTool\DbAdapters;

/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this placeholder comment

@petrknap
Copy link
Owner

I have an idea how to do this more systematic way. When do you need this change? I could do it this weekend.

@ondrej-nemec
Copy link
Author

It will be satisfactory, Thank you very much. Btw. How idea you have?

@petrknap
Copy link
Owner

Try this https://github.com/petrknap/php-migrationtool/releases/tag/v3.0.0-alpha it uses DBAL and should works on every SQL database.

@ondrej-nemec
Copy link
Author

Unfortunally, this version (3,0) has still problem on sql server
F.E.: SqlMigrationTool line 147 with {$this->migrationTableName} and TableExistsException is not catched becouse exception is DBAL exception
Sorry, my version works as I need

@petrknap
Copy link
Owner

It's covered by PetrKnap\Php\MigrationTool\Test\SqlMigrationToolTest::testCreateMigrationTableMethodWorks. What exception is it? Can you post it here?

@petrknap
Copy link
Owner

Try https://github.com/petrknap/php-migrationtool/releases/tag/v3.0.0-beta - it's quoted directly by DBAL now

@ondrej-nemec
Copy link
Author

ondrej-nemec commented Apr 25, 2019

sorry for my delay,
today I tried your changes and first test was successful but second ended with exception
there is what my test project throws

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42S01]: [Microsoft][SQL Server Native Client 11.0][SQL Server]There is already an object named 'migrations' in the database.' in C:\xam
pp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:57
Stack trace:
#0 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php(57): PDO->exec('CREATE TABLE mi...')
#1 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php(1012): Doctrine\DBAL\Driver\PDOConnection->exec('CREATE TABLE mi...')
#2 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(1017): Doctrine\DBAL\Connection->executeUpdate('CREATE TABLE mi...')
#3 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(443): Doctrine\DBAL\Schema\AbstractSchemaManager->_execSql(Array)
#4 C:\xampp\htdocs\projects\test\vendor\petrknap\php-migrationtool\src\SqlMigrationTool.php( in C:\xampp\htdocs\projects\test\vendor\petrknap\php-migrationtool\src\SqlMigrationTool.php on line 92

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S01]: [Microsoft][SQL Server Native Client 11.0][SQL Server]There is already an object named 'migrations' in the database.' in C:\xampp\ht
docs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:57
Stack trace:
#0 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php(57): PDO->exec('CREATE TABLE mi...')
#1 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php(1012): Doctrine\DBAL\Driver\PDOConnection->exec('CREATE TABLE mi...')
#2 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(1017): Doctrine\DBAL\Connection->executeUpdate('CREATE TABLE mi...')
#3 C:\xampp\htdocs\projects\test\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(443): Doctrine\DBAL\Schema\AbstractSchemaManager->_execSql(Array)
#4 C:\xampp\htdocs\projects\test\vendor\petrknap\php-migrationtool\src\SqlMigrationTool.php( in C:\xampp\htdocs\projects\test\vendor\petrknap\php-migrationtool\src\SqlMigrationTool.php on line 92

In your source is try-catch block on create table and TableExistsException is ignored, but there is not thrown TableExistException - this is DbalException - and this is answer to your previous question

thanks for your time

@petrknap
Copy link
Owner

petrknap commented May 8, 2019

ondrej-nemec pushed a commit to ondrej-nemec/php-migrationtool that referenced this pull request Dec 7, 2020
RawGit is shutting down, replace it with jsDelivr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants