Reputation: 1396
I have the following Problem: Every time I want to access the table "Stores" in Logcat I can see this error message:
10-24 15:09:06.955: E/SQLiteLog(20264): (1) no such table: Stores
But when I delete the database, and create all the tables again, I don´t see any error while creating in Logcat. When I try to access or write into the table "Categories" I don´t have any error, only "Stores". When I later browse the SQLite Database in sqlitestudio, I only see the table categories with the values I insertet, nut no other, turns out also "OpeningHours" missing. Is it possible that I try to access these table while its not yet created?
Thats my code for creating:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(context.getString(R.string.sql_create));
}
and thats the SQL-Code
<string name="sql_create">
CREATE TABLE IF NOT EXISTS `Categories` (
`idCategories` INTEGER NOT NULL ,
`name` TEXT,
PRIMARY KEY (`idCategories`) );
CREATE TABLE IF NOT EXISTS `Stores` (
`idStores` INTEGER NOT NULL ,
`name` TEXT NOT NULL ,
`locationAdress` TEXT ,
`locationLongitude` INTEGER ,
`locationLatitude` INTEGER ,
`category` INTEGER NOT NULL ,
`telephoneNumerber` TEXT ,
PRIMARY KEY (`idStores`) );
CREATE TABLE IF NOT EXISTS `OpeningHours` (
`idOpeningHours` INTEGER NOT NULL ,
`store` INTEGER NOT NULL ,
`day` INTEGER ,
`forenoon` TEXT ,
`afternoon` TEXT ,
PRIMARY KEY (`idOpeningHours`) );
</string>
Upvotes: 1
Views: 607
Reputation: 3169
Try to use only one instance of SQLiteDatabase from all of your threads. This way you avoid many problems with accessing SQLite databases.
Upvotes: 0
Reputation: 17095
Android execSQL
executes a single statement: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL(java.lang.String)
Meaning you're only creating one table - OpeningHours
- which is the last statement in your SQL script. You need to separate each create in one execSQL
call.
Upvotes: 4