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

Regression in ImportCommand #3237

Closed
morozov opened this issue Aug 3, 2018 · 6 comments
Closed

Regression in ImportCommand #3237

morozov opened this issue Aug 3, 2018 · 6 comments

Comments

@morozov
Copy link
Member

morozov commented Aug 3, 2018

Q A
BC Break no
Version 3.0.0-dev

On develop, the following issue is reported by PHPStan:

------ ----------------------------------------------------------- 
 Line   lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php  
------ ----------------------------------------------------------- 
 95     Call to an undefined method                                
        Doctrine\DBAL\Driver\PDOStatement::nextRowset().           
------ ----------------------------------------------------------- 

The issue looks legit. In order to fix the PHPStan job on Travis, I'm going to white-list this issue but it will have to be fixed properly before the release.

@morozov
Copy link
Member Author

morozov commented Aug 5, 2018

Anyone knows how doctrine-dbal dbal:import is supposed to work? According to the help message, it will "Import SQL file(s) directly to Database", however judging by the implementation, it cannot handle
files which have more than one statements. Here's what I'm trying to do:

  1. mysql << 'EOF'
    CREATE TABLE `test` (
      `id` int NOT NULL,
      PRIMARY KEY (`id`)
    )
    EOF
  2. cat > data.sql << 'EOF'
    INSERT INTO test (`id`) VALUES (1);
    INSERT INTO test (`id`) VALUES (2);
    EOF
  3. bin/doctrine-dbal dbal:import data.sql

The above results into:

An exception occurred while executing 'INSERT INTO test (id) VALUES (1);
INSERT INTO test (id) VALUES (2);
':

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO test (id) VALUES (2)' at line 2

Other import implementations I saw in PHP would parse the file into multiple statements and execute them one by one but this just passes the file contents to the driver as is.

/cc @Ocramius @Majkl578

@Ocramius
Copy link
Member

Ocramius commented Aug 5, 2018

Never used it, also unaware of its purpose 😰

@morozov
Copy link
Member Author

morozov commented Aug 5, 2018

Linking existing related issue #2700.

@morozov
Copy link
Member Author

morozov commented Aug 7, 2018

I spent some more time researching and figured out two more things:

  1. Looks like the command relies on a non-documented PDO feature where it can execute multiple queries at once given the prepared statement emulation is enabled (source). Therefore, it doesn't work with non-PDO drivers (mysqli, oci8, sqlsrv produce an expected syntax error, ibm_db2 silently does nothing).

  2. In its current state, the condition:

    if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {

    always evaluates to false since $conn is a wrapper connection:

    // replace with the mechanism to retrieve DBAL connection in your app
    $connection = getDBALConnection();
    , therefore, the offending code can at least be removed as dead.

This command cannot be fixed across platforms (see, #2700 (comment)), therefore, unless there's a reason to keep is as is, I'd remove it entirely. For the end-user, it can be almost transparently replaced with something like mysql < data.sql.

Any objections?

@Ocramius
Copy link
Member

Ocramius commented Aug 7, 2018 via email

@morozov morozov closed this as completed Aug 9, 2018
@Ocramius Ocramius modified the milestones: 3.0.0, 2.9.0 Aug 9, 2018
@morozov morozov removed this from the 2.9.0 milestone Dec 2, 2018
@github-actions
Copy link

github-actions bot commented Aug 1, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2022
@morozov morozov closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants