1

Was hoping to use Django / db-api's built in string excaping, but it looks like it doesn't work for create database commands?

from django.db import connections
cursor = connections['dbadmin'].cursor()
cursor.execute('create database %s', ['foo']) 

Which fails with

DatabaseError: (1064, "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 ''foo'' at line 1")

Although a straight, unparameterized create database foo works fine.

That looks like a bug to me, right? drop database has a similar problem...

1 Answer 1

1

You cannot use parameters for metadata such as table or database names. This is a limitation of the underlying C library, not of DB-API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.