mardi 3 mai 2016

SQLite update statement fails via Python but works fine via SQLITEstudio

I have a python script, called in a bash script

The python file (parts of):

import sqlite3
....
db_name = f_cluster_name + '_db.sqlite'
db_conn = sqlite3.connect(db_name)
c = db_conn.cursor()
# create all tables
c.execute(''' create table mel_go_terms_hits (melon_1 varchar, go_term varchar)''')
...
c.execute(''' create table mel_pathways (melon_1 varchar, pathway varchar)''')
c.execute(''' create table mel_final_results (melon_1 varchar, melon_2 varchar, mel1_short varchar, mel2_short varchar, cluster_name varchar, go_terms varchar, blast_hit varchar, enzymes varchar, pathway varchar, pathway_common_name varchar)''') #all data combined

... followed by statements to fill the mel_go_terms_hits and mel_pathways tables. They are correctly filled

Then I want to gather all data into one table (mel_final_results), to create an excel sheet

Therefore I execute several statements like:

c.execute('update mel_final_results set go_terms = (select group_concat(bla.go_term,?) from mel_go_terms_hits bla where mel_final_results.melon_1 = bla.melon_1 group by bla.melon_1)', ('@'))
db_conn.commit()
c.execute('update mel_final_results set pathway = (select group_concat(bla.pathway_id,?) from mel_metacyc_enz_pathways bla , mel_enzymes enz where mel_final_results.melon_1 = enz.melon_1  and enz.enzyme = bla.linked_enzyme  group by enz.melon_1)', ('@'))
db_conn.commit()

Here problems start. The "update mel_final_results set go_terms ..." works fine.

The "update mel_final_results set pathway ..." fails (well it simply halts, no error, waiting indefinitely)

Running the statements separately, connecting to the same database, via SQLITEstudio then both run fine, and very fast (less than a second). So the SQL itself seems correct.

What can be the problem?

Any suggestion is greatly appreciated.

Raymond

Aucun commentaire:

Enregistrer un commentaire