multidimensional array to database in python -
I am trying to remove a way to put a two dimensional array (using a python) in a squatted database . My array:
['hello', 'hello', 'hello'], ['hello', 'hello', 'hello']
I would like to have a new line with each of the 'hello' for each 'hello', which is its specialty of 'Hello', I am not sure what I am trying to do, it is also possible (me Hope this is). I tried to follow some other posts but I get an error:
sqlite3.InterfaceError: error binding parameter 0 - maybe unsupported type
Does anyone know how to insert a multi-dimensional array in the skeleton database? Any help would be appreciated. This is my code:
import sqlite3 array2d = [xrange (3)] for x in xrange (3) x for [['hello'] var_string = ',' .join ('?' * Len (array2d)) conn = sqlite3.connect ('sample.db') c = conn.cursor () c.execute ('' Create table create sample (name text, line 1, text, Line_2 text) '' ') Query_string =' Insert in sample values (% s); ' Use% Var_string c.execute (query_string, array2d) to insert the sequence of
Rows at one time:
query_string = 'Insert in sample values (?,?,?)' C.executemany (query_string, array2d) conn.commit ()
conn.commit ()
Do not forget about transactions.
I have not bothered to format the SQL parameters here for performance parameters; You do not really want to do this here, because the number of your columns is well fixed ( CREATE TABLE
by definition).
Comments
Post a Comment