Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Robin Haswell
On Fri, 27 Jan 2006 00:03:30 -0800, Derick van Niekerk wrote: I have found many posts that deal with writing a dictionary to MySQL in a blob field - which I can't imagine why anybody would want to do it. I want to write each element of a dictionary onto a db table. The keys would match the

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Robin Haswell
On Fri, 27 Jan 2006 00:03:30 -0800, Derick van Niekerk wrote: I have found many posts that deal with writing a dictionary to MySQL in a blob field - which I can't imagine why anybody would want to do it. I want to write each element of a dictionary onto a db table. The keys would match the

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Fredrik Lundh
Derick van Niekerk wrote: I have found many posts that deal with writing a dictionary to MySQL in a blob field - which I can't imagine why anybody would want to do it. it might be useful if you have a bunch of unknown properties (e.g. configuration parameters for some external parameters), and

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Derick van Niekerk
[quote] d = {spam: 1, egg: 2} cols = d.keys() vals = d.values() stmt = INSERT INTO table (%s) VALUES(%s) % ( ,.join(cols), ,.join([?]*len(vals)) ) cursor.execute(stmt, tuple(vals)) [/quote] I will be using the python-mysql API. This looks like what I am looking for. I just have a

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Gerhard Häring
Derick van Niekerk wrote: [quote] d = {spam: 1, egg: 2} cols = d.keys() vals = d.values() stmt = INSERT INTO table (%s) VALUES(%s) % ( ,.join(cols), ,.join([?]*len(vals)) ) cursor.execute(stmt, tuple(vals)) [/quote] I will be using the python-mysql API. This looks like

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Fredrik Lundh
Derick van Niekerk wrote: [quote] d = {spam: 1, egg: 2} cols = d.keys() vals = d.values() stmt = INSERT INTO table (%s) VALUES(%s) % ( ,.join(cols), ,.join([?]*len(vals)) ) cursor.execute(stmt, tuple(vals)) [/quote] I will be using the python-mysql API. This looks like what

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Derick van Niekerk
[quote] (just curious, but from where do people get the idea that arbitrary data just have to be inserted into the the SQL statement text all the time? is this some PHP misfeature?) [/quote] I've never seen it done in this way before, but I do come from a PHP point of view. I've only started

Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Carsten Haese
On Fri, 2006-01-27 at 05:47, Fredrik Lundh wrote: (just curious, but from where do people get the idea that arbitrary data just have to be inserted into the the SQL statement text all the time? is this some PHP misfeature?) Yes, the need to roll queries by inserting parameters directly into