Was hoping to use Django / db-api's built in string excaping, but it looks like it doesn't work for create database
commands?
希望使用Django / db-api的内置字符串重写,但看起来它对create database命令不起作用?
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.
虽然直接的,无参数化的创建数据库foo工作得很好。
That looks like a bug to me, right? drop database
has a similar problem...
对我来说这看起来像个错误,对吧? drop database有类似的问题......
1 个解决方案
#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.
您不能使用表格或数据库名称等元数据的参数。这是底层C库的限制,而不是DB-API的限制。
#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.
您不能使用表格或数据库名称等元数据的参数。这是底层C库的限制,而不是DB-API的限制。