コードは次のとおりです。
with sqlite3.connect('example.db', detect_types=sqlite3.PARSE_DECLTYPES) as conn:
curr = conn.cursor()
vals = ( surveyname , surveydesc , dictObj ,)
curr.execute("INSERT INTO Surveys(Name, Desc, DictObject) VALUES (?, ?, ?)", vals)
私が得ているエラーは次のとおりです。
C:\Python26\html\xlsxhelper.py in register_survey(surveydict={u'q1': {'n': 3, 'nselect': 1, 'qn': 1, 're': {u'a': {'n': 3, 'text': u'\ud30c\ub791'}}, 'text': u'\uc88b\uc544\ud558\ub294 \uc0c9\uae54\uc740?', 'type': 0}, u'q2': {'n': 3, 'nselect': 2, 'qn': 2, 're': {u'a': {'n': 3, 'text': u'\ub625'}}, 'text': u'\uc88b\uc544\ud558\ub294 \uacfc\uc790\ub294? (2\uac1c\uc120\ud0dd)', 'type': 0}, u'q3': {'n': 1, 'nselect': 1, 'qn': 3, 're': {u'a': {'n': 1, 'type': 0}}, 'text': u'\ubd84\ub958', 'type': 1}, u'q4': {'n': 1, 'nselect': 1, 'qn': 4, 're': {u'a': {'n': 1, 'type': 1}}, 'text': u'\uccb4\ud06c', 'type': 1}, 'qn': 4}, surveyname='qwe', surveyinfo='Survey Description\r\nqwe')
101 with sqlite3.connect('example.db', detect_types=sqlite3.PARSE_DECLTYPES) as conn:
102 curr = conn.cursor()
103 vals = (surveyname , surveydesc , dictObj) <= somehow this line is highlighted
104 curr.execute("INSERT INTO Surveys(Name, Desc, DictObject) VALUES (?, ?, ?)", vals)
105 conn.commit()
vals undefined, surveyname = 'qwe', surveydesc undefined, dictObj = 'eJwLVg8uLSpLrVRwSS1OLsosKMnMz4spiskrLE9V5yow5NIDANCTC5w=\n'
<type 'exceptions.TypeError'>: function takes at most 2 arguments (4 given)
args = ('function takes at most 2 arguments (4 given)',)
message = 'function takes at most 2 arguments (4 given)'
関数は最大で 2 つの引数を取ります とはどういう意味ですか? ここでどの関数を呼び出していますか? curr.execute
実際のクエリとパラメータの 2 つの引数を取ります。103行目が強調表示されているのはなぜですか? これはタプルの単純な代入です。
surveyname と surveyname は単純な文字列です。dictObj は、ピクルされて文字列に圧縮された辞書です。したがって、text/text/blob 列を持つ行に 3 つの文字列が挿入されます。ここで何が間違っているのかわかりません..