Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2011-10-23
6
Medium Priority
?
370 Views
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):
       
        try:
            con = lite.connect('specialeventms2011a.sqlite')
            cur = con.cursor()
            Incident_number=self.data1.GetValue()
            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))
                         
            con.commit()
            cur.close()
            con.close()
          
        except lite.Error, error:
            dlg = wx.MessageDialog(self, str(error), 'Error occured')
            dlg.ShowModal()

Open in new window

0
Comment
Question by:dolamitejenkins
  • 3
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
johanntagle earned 2000 total points
ID: 37015654
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 http://dev.mysql.com/doc/refman/5.1/en/replace.html

Think you can also do INSERT ON DUPLICATE (http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html), but it seems to me REPLACE INTO is more straightforward here.
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 37015658
Hmmm didn't realize you mentioned sqlite - so why did you include MySQL server?  Not sure if sqlite supports this.
0
 

Author Comment

by:dolamitejenkins
ID: 37015662
orry but there is no sqlite area and ive gotten great advice in the past from this area
0
 

Author Comment

by:dolamitejenkins
ID: 37015682
Thank so much sqlite does have the feature
0
 

Author Closing Comment

by:dolamitejenkins
ID: 37015701
perfect thanks
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Exchange database can often fail to mount thereby halting the work of all users connected to it. Finding out why database isn’t mounting is crucial and getting the server back online. Stellar Phoenix Mailbox Exchange Recovery is a champion product t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

581 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