![]() |
update the data into the database - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: update the data into the database (/thread-549.html) |
update the data into the database - chris0147 - Oct-18-2016 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_nameI 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 RE: update the data into the database - Yoriz - Oct-18-2016 Use update with where. RE: update the data into the database - chris0147 - Oct-18-2016 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? RE: update the data into the database - Yoriz - Oct-19-2016 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. |