Python Forum
UPDATE SQLITE TABLE - Copy a fields content to another field.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UPDATE SQLITE TABLE - Copy a fields content to another field.
#11
The output is working correctly and shows the sql2 print being populated with the correct string.

It's the test.sqb file that is not updating correctly.
Reply
#12
Created a new sqb from scratch and it's now working, so there appeared to be a problem with the db.

Thanks everyone for your help.
Reply
#13
ibreeden: you suggested the same code that I posted in post 2.
andrewarles: I wanted you to post the results of my post 2, not just commet on them.

Also, as ibreeden pointed out, we need to see the structure of the table you are trying to update.
and take heed to his advise on WHERE clause.
Reply
#14
Here's the code that works ok:

import sqlite3
conn = sqlite3.connect("report.sqb")
cursor = conn.cursor()
 
sql = "SELECT * FROM report WHERE type LIKE 'C%'"
 
cursor.execute(sql)
data = cursor.fetchall()
 
for row in data:
    ms, cs, rg = row[0].split(';')
    fieldid = row[0]
    print (f"row: {row}")
    sql2 = f"UPDATE report SET rg='{rg}', ms='{ms}', cs='{cs}' WHERE fieldid = '{fieldid}'"
    print (f"\rsql2: {sql2}")  
    cursor.execute(sql2)
conn.commit()
cursor.close()
conn.close()
ibreeden likes this post
Reply
#15
(May-08-2021, 04:15 PM)Larz60+ Wrote: ibreeden: you suggested the same code that I posted in post 2
@Larz60+ Yes indeed, your code seemed good to me. I only added a "where" clause.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Display table field on multiple lines, 'wordwrap' 3python 0 358 Aug-06-2021, 08:17 PM
Last Post: 3python
  how to filter two fields in json using python python_student 4 1,089 Mar-15-2021, 05:58 PM
Last Post: python_student
  How to update values in a pyarrow table? xraphael75 1 1,451 Jan-25-2021, 02:14 PM
Last Post: xraphael75
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 818 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Bug ? when dataclass field name == field type Cyril 0 599 Oct-22-2020, 03:26 AM
Last Post: Cyril
  Unable to Update SQLite Table sambanerjee 5 1,245 Sep-30-2020, 12:21 PM
Last Post: Larz60+
  Json fields not being retrieved mrcurious2020 4 897 Sep-14-2020, 06:24 AM
Last Post: bowlofred
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 1,393 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  How to create db table with SQLite and SQLAlchemy?? marcello86 1 1,224 Sep-02-2020, 03:05 PM
Last Post: marcello86
  copy content of text file with three delimiter into excel sheet vinaykumar 0 797 Jul-12-2020, 01:27 PM
Last Post: vinaykumar

Forum Jump:

User Panel Messages

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