sqlite newbie questions

Carsten Haese carsten at uniqsys.com
Thu Jun 21 21:34:45 CEST 2007


On Thu, 2007-06-21 at 19:24 +0000, kf9150 at gmail.com wrote:
> Hello,
> 
> I have a sqlite database table which has a table named "Transmittal".
> Before inserting a new record into the database, i'd like to perform
> some checking. How do i select all records with certain value (say
> "Smith") for a column (say "Last_Name")? Knowing almost nothing about
> SQL, i just selected everything and process the returned list.
> 
> cur.execute('select * from Transmittal')
> records = cur.fetchall()

Use a where clause not unlike the one you're using in the delete
statement below.

> Also, how do i delete records with certain value for centain column. I
> was thining of something like
> cur.execute('delete * from Transmittal where Last_Name=?', "Smith")
> but the syntax it's not correct.

You're close. Drop the '*' and put your parameter into a singleton tuple
or one-element list:

cur.execute('delete from Transmittal where Last_Name=?', ("Smith",) )

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list