On 2005-04-27, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Wed, 27 Apr 2005 08:44:36 +0200, Ola Natvig <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>> sql = "INSERT INTO %s (%s) VALUES (%s)" % (table, ','.params.keys()),
>> ','.join(param.values()))
> That also
On Tue, Apr 26, 2005 at 09:59:29PM -0500, Mike Meyer wrote:
> Jeff Epler <[EMAIL PROTECTED]> writes:
>
> > items = query_param.items()
> > keys = [item[0] for item in items]
> > values = [item[1] for item in items]
>
> Is there some reason not to do:
>
>keys = query_params.keys()
done. thanks
Try another paramstyle (see http://python.org/peps/pep-0249.html), e. g.
",".join(["%s"] * len(keys)) ...
instead of
",".join(["?"] * len(keys)) ...
Peter
--
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
Maxim Kasimov wrote:
> i'm tying to run example, and then get a traceback. am i something missed?
>
> mysql> create table tmp_tmp (id int not null auto_increment primary key,
> sd varchar(255) not null default '', si int not null default 1);
>
import MySQLdb
db = MySQLdb.connect("local
... but not in the case when integers are in a dictionary (please, try to
execute your example by yourself first)
"Ola Natvig" <[EMAIL PROTECTED]> wrote:
news:[EMAIL PROTECTED]
> Maksim Kasimov wrote:
> >
> > in php-scripts, to insert data to database, i'm doing like this:
> >
> > ...
> > $
i'm tying to run example, and then get a traceback. am i something missed?
mysql> create table tmp_tmp (id int not null auto_increment primary key, sd
varchar(255) not null default '', si int not null default 1);
>>> import MySQLdb
>>> db = MySQLdb.connect("localhost", "login", "password", "
Maksim Kasimov wrote:
in php-scripts, to insert data to database, i'm doing like this:
...
$query_param = array(
'field0' => 1,
'field1' => 3,
'field2' => $var2,
'field3' => $var3,
);
...
$sql = "INSERT INTO $table (".implode(", ",
array_keys($query_param)).") VALUES ('
Jeff Epler <[EMAIL PROTECTED]> writes:
> items = query_param.items()
> keys = [item[0] for item in items]
> values = [item[1] for item in items]
Is there some reason not to do:
keys = query_params.keys()
values = query_params.values()
That would seem to be a lot more obvious a
It looks like php's implode(sep, seq) is like sep.join(seq) in Python.
But this is a lousy way to write database queries. You should use the
Python's DB-API interface's execute(statement, parameters) instead.
Assuming that paramstyle is 'qmark', I think it ends up looking
something like this:
in php-scripts, to insert data to database, i'm doing like this:
...
$query_param = array(
'field0' => 1,
'field1' => 3,
'field2' => $var2,
'field3' => $var3,
);
...
$sql = "INSERT INTO $table (".implode(", ", array_keys($query_param)).") VALUES
('".implode("','", $quer
10 matches
Mail list logo