It's been a while since I've touched anything databases related but I've made a number of changes to the database structure so that now it includes the following tables.
Brand- Brand ID - primary key
- Brand Name
- Model ID - primary key
- Brand ID - foreign key
- Model name
- Car ID - primary key
- Model ID - foreign key
- Mileage
- Car Picture
I'm eventually going to add more columns to the Model table for some of the specifications for each model. I'll need to make a number of changes to the database adapter in order to store transactions with the new schema, so that when data is added to the database it adds it to conform with the new foreign keys.
In updating the database, the previous database was wiped and as a result I discovered that when viewing the stats tab when there was nothing in the database it would cause a null pointer exception. I amended the method for formatting the database results in to a Androidplot compatible data structure to only do so if there was data being returned.
The fact that the database wiped on an update to the schematics of the database got me thinking that I really need to look in to a way of converting the data that's currently in the database to form what ever the new schema is during an app update if the original schema is changed. There could well be an easy solution for all of this but as I stated above, it's been a while since I've got in to some solid database design.
Currently nothing is being done with these new tables, but I'm going to work on modifying the existing classes and their methods to fit the new schema this week, and I want to change up the car tab so that the main tab displays a list of the user's cars that he's added to their app (i.e. what will be stored in the UserCars table). The user can select which car the app uses which can be saved as part of the app's settings. This will link in to the transactions so that the mileage being displayed is for the selected car's mileage and the stats being displayed will have a relationship with individual cars in the user cars table too. I just need to change the user_id column in the transactions table to be a foreign key from the UserCars table.
No comments:
Post a Comment