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
  Copy xml content from webpage and save to locally without special characters Nik1811 14 596 Mar-26-2024, 09:28 AM
Last Post: Nik1811
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 704 Sep-22-2023, 02:33 PM
Last Post: carecavoador
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 702 Aug-09-2023, 05:51 PM
Last Post: Calab
  Compare fields from two csv files georgebijum 3 1,335 Apr-25-2022, 11:16 PM
Last Post: Pedroski55
  Display table field on multiple lines, 'wordwrap' 3python 0 1,747 Aug-06-2021, 08:17 PM
Last Post: 3python
  How to update values in a pyarrow table? xraphael75 1 3,625 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 2,626 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Bug ? when dataclass field name == field type Cyril 0 1,525 Oct-22-2020, 03:26 AM
Last Post: Cyril
  Unable to Update SQLite Table sambanerjee 5 2,865 Sep-30-2020, 12:21 PM
Last Post: Larz60+
  Json fields not being retrieved mrcurious2020 4 1,988 Sep-14-2020, 06:24 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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