Droppiing table and recreating seems to hold old structure.
Posted: Mon 03 Aug 2015 16:39
Hello
I'm working on an app that needs to create statistics from differing sets of columns in a table. In my code, I drop the existing STATS table then create new version with the desired columns. There are 10 different sets of stats that need to be calculated from two different tables (which is set in TMPtable string) and between 5 and 12 columns (in SQLselect string).
The problem seems to be that the structure of the existing table is "cached" and used even after the table is re-created. So when re-created table contains new column, such as "scSIZE1", accessing using STATS.FieldByName("scSIZE1").asInteger returns error indicating column does not exist. When I check db using "SQLite Expert Pro" the column is in fact there.
I've tried opening and closing, changing active state, and ApplyUpdates but problem still exists. I'm sure I'm missing something obvious but just not seeing the solution so any insights would be appreciated
I'm working on an app that needs to create statistics from differing sets of columns in a table. In my code, I drop the existing STATS table then create new version with the desired columns. There are 10 different sets of stats that need to be calculated from two different tables (which is set in TMPtable string) and between 5 and 12 columns (in SQLselect string).
Code: Select all
DBM.LiteSQL1.SQL.Clear;
DBM.LiteSQL1.SQL.Add('DROP TABLE IF EXISTS '+TMPtable+'STATS');
DBM.LiteSQL1.Execute;
DBM.LiteSQL1.SQL.Clear;
DBM.LiteSQL1.SQL.Add('CREATE TABLE '+TMPtable+'STATS AS ' + SQLselect);
DBM.LiteSQL1.SQL.Add(' WHERE '+SQLwhere);
DBM.LiteSQL1.Execute;
I've tried opening and closing, changing active state, and ApplyUpdates but problem still exists. I'm sure I'm missing something obvious but just not seeing the solution so any insights would be appreciated