I carved your data up using Excel, sorted by statement number, and got this: ``` Stmt Command SQL 1 Prepare PRAGMA cache_size = 10000 1 Execute prepared 1 Prepare PRAGMA show_datatypes = ON 1 Execute prepared 1 Prepare PRAGMA foreign_keys = 1 1 Execute prepared 2 Prepare select * from variables order by orden 2 Execute prepared 3 Prepare PRAGMA table_info('variables') 3 Execute prepared 4 Prepare select * from variables 4 Execute prepared 5 Prepare select * from tipocampo 5 Execute prepared 6 Prepare PRAGMA table_info('tipocampo') 6 Execute prepared 7 Prepare select * from campos order by id 7 Execute prepared 8 Prepare PRAGMA table_info('campos') 8 Execute prepared 9 Prepare select * from valores where campo=? order by orden 9 Bind prepared 9 Execute prepared 9 Bind prepared 9 Execute prepared 10 Prepare PRAGMA table_info('valores') 10 Execute prepared 11 Prepare select * from campos 11 Execute prepared 12 Prepare select * from plcs 12 Execute prepared 13 Prepare PRAGMA table_info('plcs') 13 Execute prepared 14 Prepare select numero,color_fondo, color_letra from casillas where pantalla=? and numero>0 and numero<=? order by numero 14 Bind prepared 14 Execute prepared 14 Bind prepared 14 Execute prepared 14 Bind prepared 14 Execute prepared 14 Bind prepared 14 Execute prepared 15 Prepare PRAGMA table_info('casillas') 15 Execute prepared 16 Prepare select * from plcs 16 Execute prepared 17 Prepare select * from pantallas order by numero 17 Execute prepared 18 Prepare PRAGMA table_info('pantallas') 18 Execute prepared 19 Prepare select * from casillas where pantalla=? and numero>0 and numero<=? order by numero 19 Bind prepared 19 Execute prepared 19 Bind prepared 19 Execute prepared 20 Prepare select * from casillas where pantalla=? and numero=0 20 Bind prepared 20 Execute prepared 20 Bind prepared 20 Execute prepared 21 Prepare BEGIN 21 Execute prepared 22 Prepare PRAGMA defer_foreign_keys = on 22 Execute prepared 23 Prepare UPDATE TriggerControl set enabled=0 23 Execute prepared 24 Prepare DROP TABLE IF EXISTS x 24 Execute prepared 25 Prepare CREATE TEMP TABLE x AS SELECT * FROM variables WHERE orden>=? 25 Bind prepared 25 Execute prepared 26 Prepare UPDATE x SET orden=orden+1 26 Execute prepared 27 Prepare DELETE FROM variables WHERE orden>=? 27 Bind prepared 27 Execute prepared 28 Prepare INSERT INTO variables SELECT * FROM x 28 Execute prepared 29 Prepare DROP TABLE x ?? Execute prepared ``` It helped me see what you are doing a little more clearly, but I didn't see a reason for the locked table. (It would be nice to know which table is locked.) When I examined the sequence, statement 14 caught my eye. It has 2 bind parameters in the SQL, and you call Bind 4 times. That's weird. That should have surfaced an error, I think. Are you checking for errors on each call?