Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commands out of sync error #222

Copy link
Copy link
Closed
Closed
Copy link
@ghost

Description

Hi

Run this SQL command using mysqlclient:

CREATE TABLE IF NOT EXISTS `test`
(
    `id` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY
)
ENGINE=InnoDB;

for the first call it will run properly, but from the second call, it will rise Commands out of sync; you can't run this command now error.

I run it like this:

db = MySQLdb.connect([...])
db.cursor().execute(command)

NOTE: calling with cursor.close(), db.commit() or etc, also have the same result.

OK, now try this command:

SELECT 1; -- this line will solve the error!

CREATE TABLE IF NOT EXISTS `test`
(
    `id` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY
)
ENGINE=InnoDB;

As you see the problem solved!
I've tested this also on other drivers like mysqljs/mysql, this only happens on your driver.
It seems it is cause we use IF NOT EXISTS clause and MySQL from second call cause of existence of the table, doesn't do anything and mysqlclient doesn't fetch any result so MySQL rises this error.

el1s7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.