Thanks for everyone's responses. I found the problem and it wasn't obvious.
The B4A app had the table defined in the database that was in the Files directory so it gets copied to the Android app just fine. No problem there. If I run the query on this table it works fine.
Here is what caused the problem. The table can also be generated in the app using something like this (I renamed the table and column names):
CREATE TABLE Location_Totals as select Location, length(Location)-length(replace(Location,'/','')) as Pop from Locations group by Location;
-- The Locations table gets summarized into Location_Totals table using a Group By
CREATE TABLE Locations (
ID INTEGER PRIMARY KEY,
Location STRING,
Number INTEGER
);
--This table gets created from the Group By on the table above
CREATE TABLE Location_Totals (
Location NUM,
Pop,
New_Pop INTEGER --I added this column manually and filled it with "Pop"
);
The generated table, Location_Totals has a couple of wrong column types generated. The Location column for some reason is set to "NUM" even though Location values are string, like "/Canada/Toronto" etc.
The Pop column is not Integer even though it is based on an Integer calculation.
I didn't know the table had the wrong column types until I used Android Studio and copied the database to my Windows machine and examined the table structure.
We can ignore the Location column entirely because that is not the problem. The problem is the Pop column.
A simple query like this will fail to return the correct rows. It returns only 1 row:
select * from location_totals where pop <= 2;
[Location] [Pop] [New_Pop]
/Ireland/Belfast 2 2
Here are all the rows in the table "Location_Totals":
[Location] [Pop] [New_Pop]
0 0
/Canada 1 1
/Canada/Calgary 2 2
/Canada/Calgary/Beaumont 3 3
/Canada/Toronto 2 2
/Canada/Toronto/Park 3 3
/Canada/Toronto/Younge 3 3
/Ireland 1 1
/Ireland/Belfast 2 2
/Toronto/Younge/Smith 3 3
In other database that I've used, the table that is created from the Select statement will create the correct column types based on the columns that were selected or tallied. If I tallied an Integer then the receiving table gets an Integer column. Same with Double. But with Sqlite it creates a typeless column. It's not even a string column because if I reference the column as a string, it still won't return the proper rows.
Example:
select * from location_totals where Pop < '2' order by location; --It returns rows with Pop=3 and Pop=2
[Location] [Pop] [New_Pop]
0 0
/Canada 1 1
/Canada/Calgary/Beaumont 3 3
/Canada/Toronto/Park 3 3
/Canada/Toronto/Younge 3 3
/Ireland 1 1
/Ireland/Belfast 2 2
/Toronto/Younge/Smith 3 3
I ran a "pragma integrity_check;" and everything is fine (no errors).
So I guess from now on when I create a table from a Group By, I have to create the table ahead of time with the correct column types (or reuse the existing table if it is there) then Insert the Group By results into the empty table.
BTW, I added the "New_Pop" column as an Integer to the table and updated the rows with the existing Pop values, and the query works fine with this Integer column.
select * from location_totals where New_Pop < 2 order by location;
[Location] [Pop] [New_Pop]
0 0
/Canada 1 1
/Ireland 1 1