SQLite Parameter Substitution Issue
When attempting to query an SQLite database using parameter substitution with Python 2.5, an error might be encountered stating "Incorrect number of bindings supplied." despite only supplying one binding. This issue can arise during database creation, which may involve multiple bindings while inserting data.
To resolve this issue, the correct form for the Cursor.execute() method with parameter substitution should be used. Instead of passing a string representing the binding parameter, a sequence should be provided as the second argument. The corrected code would be:
<code class="python">for item in self.inventory_names: self.cursor.execute("SELECT weight FROM Equipment WHERE name = ?", [item]) self.cursor.close()</code>
By providing the parameter value within a sequence, the Cursor.execute() method will correctly recognize and apply the binding, resolving the error. Reference Python's sqlite3 documentation for more information on Cursor Objects.
The above is the detailed content of Why Do I Get \'Incorrect Number of Bindings Supplied\' Error in SQLite Parameter Substitution?. For more information, please follow other related articles on the PHP Chinese website!