Re: [sqlite] Inserting Values in Bulk

2006-10-05 Thread Jay Calaus
Ok. Thanks, Dennis. I may look at the pysqlite source one of these days when I have more cycles. In the meantime, I'll do it like the example. In fact, I already have something working. It is also wrapped in a transaction and I've set all those pragma synchronous stuff as well but it is

Re: [sqlite] Inserting Values in Bulk

2006-10-05 Thread Dennis Cote
Jay Calaus wrote: Now I'm investigating using pysqlite for some quick and dirty jobs and I'm trying to understand if there is a need to prepare the statements once, then bind and insert for every record, the same way I did it in C. Your example above seems to do all of these in one shot. Do

Re: [sqlite] Inserting Values in Bulk

2006-10-05 Thread Jay Calaus
Dennis, > # insert the repeated pr fields into the associated pr table > for n in range(28): > cur.execute("insert into pr values(?, ?, ?)", (id, n+1, float(fields[n+3])) > Even if you don't normalize your table this sample > should show how to use parameters (the question marks > in the

Re: [sqlite] Inserting Values in Bulk

2006-09-13 Thread Rich Shepard
On Wed, 13 Sep 2006, Pablo Santacruz wrote: Try this, it may suits you. Thank you, Pablo. I think that it is OK now; I'm in the process of testing the method by working within pycrust. I've made the input data into an array of lists rather than tuples, and that will also work. Rich --

Re: [sqlite] Inserting Values in Bulk

2006-09-13 Thread Pablo Santacruz
Try this, it may suits you. (I'm using pysqlite from trac) from pysqlite2 import dbapi2 as sqlite import csv con = sqlite.connect("mydb") cursor = con.cursor() reader = csv.reader(open("some.csv", "rb")) qmarks = "?," * 30 + "?" #1 for row in reader: #row is a tuple cursor.execute("insert

Re: [sqlite] Inserting Values in Bulk

2006-09-12 Thread Dennis Cote
Rich Shepard wrote: Yes, 'row' is the string of values. Note, you have only got 4 columns in your column list, so you will get an error if you feed in 31 columns of data. I've corrected this already. You may need to extract the relevant columns using split to separate your string at

Re: [sqlite] Inserting Values in Bulk

2006-09-11 Thread Rich Shepard
On Mon, 11 Sep 2006, Dennis Cote wrote: Not as shown, but you could build the insert statement as a string in python and then pass that to the execute method. Assuming row is your string of values: sql = "insert into component(vote_id, cat, pos, pw) values (" + row + ")" self.cur.execute(sql)

Re: [sqlite] Inserting Values in Bulk

2006-09-11 Thread Dennis Cote
Rich Shepard wrote: If I have a string variable with 31 fields (integer, text, text, and 28 floats), and the values are separated by commas (and quotes for the text), can I insert them into the appropriate table with a single statement such as this from a python/pysqlite method I'm writing:

[sqlite] Inserting Values in Bulk

2006-09-11 Thread Rich Shepard
If I have a string variable with 31 fields (integer, text, text, and 28 floats), and the values are separated by commas (and quotes for the text), can I insert them into the appropriate table with a single statement such as this from a python/pysqlite method I'm writing: