[Tutor] MySQLdb error while inserting records

Victor Bouffier apple_py at biz-experts.net
Mon Mar 7 01:09:53 CET 2005


Yes! That did it.

I got confused since Programming Python mentions the '?' for arguments, 
although I failed to notice it was just used as an example. Actual 
identifiers could vary depending on the database.

Thanks a lot Kent.


Kent Johnson wrote:

> Victor Bouffier wrote:
>
>>
>> Hi all,
>>
>> I consider myself fairly proficient with SQL, but I'm still getting 
>> the hang of the MySQL API. I am working through the examples in "Open 
>> Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, 
>> and PHP" by James Lee and Brent Ware, and trying to make the third 
>> "P" to be Python. :)
>>
>> There is an example in the book which is written in Perl, used to 
>> insert new records to MySQL. I tried it as it is written and it works 
>> fine. I have migrated to Python another example that gets all of the 
>> records in the age_information table (SELECT query), and it is 
>> getting the data successfully. However, I am having problems with the 
>> program to insert records.
>
>
> According to this page
> http://sourceforge.net/docman/display_doc.php?docid=26238&group_id=22307
> MySQLdb uses the 'format' style of passing parameters to SQL, not the 
> questionmark style you have used below. So change query to
> >    32  query = '''
> >    33  INSERT INTO age_information
> >    34      (lastname, firstname, age)
> >    35      VALUES (%s, %s, %s)
> >    36  '''
>
> Kent
>

-- 
Victor Bouffier
Finance Manager
www.grupoandersons.com



More information about the Tutor mailing list