I am trying to read a pre-existing database generated in Python for a React Native app using Expo's SQLite library, expo-sqlite
.
However, I am experiencing very weird behavior. Reading the database returns completely mixed up values for the columns - values that normally belong to another column.
For example, there is a column for the age class a product has been made for in the table products
:
let db = SQLite.openDatabaseSync("@/data/products.db");
let foundRows = db.getAllSync('SELECT age FROM products;');
foundRows.forEach(element => {
console.log(typeof element);
});
Counterintuitively, this prints the name column to the console:
{"age": "Felt Trailorpark 2.35\" front and rear"}
It gets even worse when I try to run a SELECT * FROM PRODUCTS;
- it then mixes up all the columns and seems to be sorting the keys of the object alphabetically?
{"additional_image_urls": "aluminium", "age": "700x40cc City Wheel", "art_name": "10083050", "art_number": "http://...", "availability": "", "bicycle_rack_name": "EUR", ...}
I then suspected the DB was just messed up, but no. Reading it in Python works correctly, reading it with the SQLite CLI works correctly, reading it with an online SQLite reader shows the correct values. I am quite puzzled at this point.
sqlite > SELECT age FROM products;
adult,child
adult
adult
child
...
SELECT * FROM products;
works perfectly fine, too.
What am I doing wrong here?
Okay, it worked out of nowhere now. What I guess what happened is that the emulated device had an old, faulty database file from earlier cached of some sort, so a reinstall (you can also try to just clear the cache) fixed the problem immediately. I cannot explain this in another way, because it just happened out of the blue and now everything's fine. Very annoying, wasted 8+ hours on this.