Python Forum
update the data into the database
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
update the data into the database
#1
Hi folks,

I am writing a code to allow me to input the data into the sqlite database.

Here is what I am using:

#store the id and width of buttons in a database
for title, channel_name, start_time, stop_time, category, prog_width in izip_longest(title_list, channelsList, start_time_list, stop_time_list, categoryList, program_width, fillvalue=''):
    if channel_name != channel_namelast:  # next channel
       countbut = 0  # we will allow for 10 buttons per channel (0 to 9 from button_id list)
       if countbut < 10 and countbc < 70:
          #ie we are adding a button_id here
          buttonadd = program_id[countbc] # get the buttonid from the list
          countbc = countbc + 1
          countbut = countbut + 1
       else:
          buttonadd = "" #put in a blank
          print "you have added no string in a database"
       cur.execute("INSERT INTO programs(channel, title, start_date, stop_date, category, program_id)" + " VALUES(?, ?, ?, ?, ?, ?)", [channel_name, title, start_time, stop_time, category, buttonadd])
        channel_namelast = channel_name
I got the list of button ids when I am adding the list of button objects. I am using the variable called program_id to get the button id, so I could search them in a database to find a matched string.

I have got no idea how I could find the data using with the variable to find a matched string in a database before I could replace with the strings that I want to replace. I want to find the string of 3001 to replace it with a empty string, then find the string 3002 to replace it with 3001, find the string 3003 to replace it with 3004, find the string 3003 to replace it with 3004, find the string 3005 to replace it with 3004 and so on until I insert the 3010 data in a new cell just after the id "3009". 

Just like this:


http://i.imgur.com/ZUK6ATG.jpg


I have not write a code for the update in a database, so I have got no idea how to search for the strings that I want to find them in a database before I could replace them with the strings that I want to replace.

Do you know how I could find the string in a database using the variable program_id to replace them with each of the strings that start from 3002 to 3010 to replace it with 3001 to 3009 and insert 3010 after the 3009 data?? 

Any advice will be greatly appreciated.

Thanks in advance
Reply
#2
Use update with where.
Reply
#3
I have try this:

cur.execute('UPDATE programs SET program_id=? WHERE program_id=?', [program_id])
It say: ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 1 supplied.


I am trying to find the id 3001 to replace it with a empty string then find the next id and replace it with 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009 and 3010 in each cell.

Any idea how I can do that?
Reply
#4
Try to learn what an error is telling you because it clearly states that you have only passed one value when your sql requires two.
In your sql update the code wants to set the program_id to a certain value where the program_id is another value but you have only given first one of those values.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to detect abnormal data in big database python vanphuht91 5 1,128 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  Database that can compress a column, or all data, automatically? Calab 3 1,162 May-22-2023, 03:25 AM
Last Post: Calab
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,360 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  simple html page with update data korenron 3 2,646 Nov-15-2021, 09:31 AM
Last Post: jamesaarr
  Get last row of SQL database and update Turtle 5 3,122 Oct-14-2021, 07:06 PM
Last Post: Turtle
  I need help parsing through data and creating a database using beautiful soup username369 1 1,705 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,154 Jul-02-2021, 02:19 PM
Last Post: xtc14
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,670 Dec-16-2020, 05:26 AM
Last Post: Vokofe
Photo Update database in tkinter shahulvk 3 3,129 Oct-24-2020, 04:48 PM
Last Post: shahulvk
  Looping to read data in database CEC68 1 1,702 Sep-24-2020, 08:54 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020