check if a particular row (entry) exist in my database

Posted on 2011-10-23
Last Modified: 2012-05-12
I need to be able to check if a particular row (entry) exist in my sqlite database ...What I want to do is ... if it does exist then go ahead and  update if it doesnt the write the row for the first time... Can someone offer guidenace how to check if  a particular row exist

def PutData(self,event):
            con = lite.connect('specialeventms2011a.sqlite')
            cur = con.cursor()
            Last_Name = self.data2.GetValue()
                      cur.execute('update ptrecords set Last_Name =?,First_Name =?, Age=?,Gender =?, Address =?, City =?,State=?,Zip=?, Ailment =?, Treatment =?,Patient_reprt=? ,Initial_contact =?, Hospital =?, Inservice =?,Provider_1=?,Provider_2 =?,Sys=? ,Dia=?, Pulse=?, Resp=?,Refusal=?, image =? where Incident_number = ?' ,
                        ( Last_Name, First_Name, Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_Contact,Hospital,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Refusal,lines,Incident_number))
        except lite.Error, error:
            dlg = wx.MessageDialog(self, str(error), 'Error occured')

Open in new window

Question by:dolamitejenkins
    LVL 24

    Accepted Solution

    You can use REPLACE INTO syntax.  It's like INSERT INTO but if it detects a record with the same primary or unique key, it updates that row instead.  See

    Think you can also do INSERT ON DUPLICATE (, but it seems to me REPLACE INTO is more straightforward here.
    LVL 24

    Expert Comment

    Hmmm didn't realize you mentioned sqlite - so why did you include MySQL server?  Not sure if sqlite supports this.

    Author Comment

    orry but there is no sqlite area and ive gotten great advice in the past from this area

    Author Comment

    Thank so much sqlite does have the feature

    Author Closing Comment

    perfect thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now