Ich probiere gerade einzelne Zeilen in eine MySQL-Tabelle einzufügen, stoße dabei aber auf einige Probleme
Code: Alles auswählen
import cmd
import MySQLdb
import getpass
db = MySQLdb.connect("localhost", "benutzername", "password", "datenbank")
c = db.cursor()
class ManagementKonsole(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
self.prompt = ">>> "
def do_adduser(self, prm):
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
c.execute('''
INSERT INTO login (id, username, password)
VALUES (%(id)s, %(username)s), %(password)s
''', {
'id': None,
'username': username,
'password': password
})
def do_showuser(self, prm):
weitere Anweisungen
def do_exit(self, prm):
return True
def do_quit(self, prm):
return True
konsole = ManagementKonsole()
konsole.cmdloop()
Ich verwende ein Debian lenny mit MySQLdb in jeweils aktuellem Stand.gerald@lisa:~/verwaltung$ python console.py
>>> adduser
Username: gerald
Password: verdeckt eingegebenes Kennwort dank getpass
Traceback (most recent call last):
File "console.py", line 39, in <module>
konsole.cmdloop()
File "/usr/lib/python2.5/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python2.5/cmd.py", line 219, in onecmd
return func(arg)
File "console.py", line 24, in do_adduser
'password': password
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (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 ''test'' at line 2")
Weiß einer bei meinem Problem weiter?
Schönen Abend noch,
gerald