Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

Hope all of you are doing well and safe.

I have a curious issue related to a sequence of sql statments using sqlite.

I have a table [geometries] and a table view [FlagsGeometries].

When I do the following sequence:

1.
CREATE TABLE "newGeometries" ( columns definition)

2.
insert into newGeometries select * from Geometries

3.
drop table if exists Geometries

4.
alter table newGeometries rename to Geometries

The last statement generates an exception:
SQL logic error - error in view FlagsGeometries: no such table: main.Geometries


This batch is running fine on some computer but failing on other one using the same set of sqlite files version.

What I have tried:

To cover the issue, I have modified the code like the following:

1.
1. <pre> CREATE TABLE "newGeometries" ( columns definition) 

2.
insert into newGeometries select * from Geometries

2.5 ****
drop view if exists FlagsGeometries
****
3.
drop table if exists Geometries

4.
alter table newGeometries rename to Geometries

5.
**** 
CREATE VIEW [FlagsGeometries] AS select xxxxx from Geometries 
****

This modification will cover the issue but why is it not working on all computers ?

Feel free to share if you have an explanation.
Thank you very much in advance.
Best regards.
MiQi
Posted
Updated 23-Oct-20 4:35am
Comments
Richard MacCutchan 23-Oct-20 9:36am    
Are all the systems using exactly the same version of SQLite? Alternatively it could just be a timing issue.

1 solution

A view is stored as a precompiled SQL statement that relates to a specific table source - when you deleted it, that source no longer exists, and the view develops a fault.

In order to delete the underlying table, you have to delete the view first, remove the table, recreate the table, and then recreate the view.

But why are you doing all that? You are copying all the elements of the old table to the new, so you will end up with the same table, and probably a bigger DB file as a result ...
 
Share this answer
 
Comments
SuperMiQi 23-Oct-20 11:12am    
Hello OriginalGriff,

Thank you for your reply. I have the impression it was done to recreate the table with possible newly added columns as it starts from a dummy database but I cannot get the answer as the colleagure retired and the issue just comes out recently.
I have done exactly how you described and that fixes the issue but I was wondering why it has worked happily in the past without that pre-view deletion. It is just to be sure I do not miss something.

The modification sounds logical but wonder why this was not introduce at first instance.

Thanks again.
Best regards.
MiQi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900