[Tutor] Create new MySQL database from user input.
Decibels
decibelshelp@charter.net
Sun Jun 15 23:12:02 2003
Sorry to keep bring MySQL issues up guys, but I will get quite far
than hit a stumbling block.
I am at the point of allowing the user to put in the option to Create a
different name for the Database. Use input with command-line option
seems to be working fine. But I have tried quite a few ideas and cannot
get the syntax correct it appears.
Here are a few of my more 'closer' attempts. Is it syntax or am I way off
bat.
Actually I have the command line option working, just put this in to
facilitate things. And see if it was actually working. Results same.
1)
DBName = "test" # also tried ('test'), ("test")
cursor.execute ("CREATE DATABASE %s" (DBName))
Results:
DB doesn't exist. Going to Create it.
Traceback (most recent call last):
File "stockpicker6.py", line 101, in ?
cursor.execute ("CREATE DATABASE %s" (DBName))
TypeError: 'str' object is not callable
2)
DBName = "test"
cursor.execute ("""CREATE DATABASE SET db = %s
WHERE db = %s
""", (None, DBName))
Results:
DB doesn't exist. Going to Create it.
Traceback (most recent call last):
File "stockpicker6.py", line 101, in ?
cursor.execute ("""CREATE DATABASE SET db = %s
File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 95, in execute
return self._execute(query, args)
File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 114, in _execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax near 'SET db = NULL \n\t\t WHERE db = 'test'\n\t\t' at line 1")
3)
DBName = "test"
cursor.execute ("""CREATE DATABASE (%s)
""", (DBName))
Results:
DB doesn't exist. Going to Create it.
Traceback (most recent call last):
File "stockpicker6.py", line 101, in ?
cursor.execute ("""CREATE DATABASE (%s)
File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 95, in execute
return self._execute(query, args)
File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 114, in _execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax near '('tests') \n\t\t' at line 1")
Any ideas? Thanks Dave