H
H
Hakito2015-11-22 23:32:55
Android
Hakito, 2015-11-22 23:32:55

Why doesn't SQLITE android work?

Hello!
Help, please with a problem. I am working with a database, I created the appropriate class, but I get an error
android.database.sqlite.SQLiteException: no such table: pictures (code 1): , while compiling: SELECT * FROM pictures
.
Tell me what am I doing wrong?
Class code for working with the database

public class DataBaseHelper extends SQLiteOpenHelper {



    public static final String
            CREATE_SCRIPT="BEGIN TRANSACTION; CREATE TABLE 'pictures' (	`id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,	`name`	TEXT NOT NULL,	`description`	TEXT,	`author_id`	INTEGER NOT NULL,	`genre_id`	INTEGER NOT NULL,	`tech_id`	INTEGER NOT NULL,	`room_id`	INTEGER NOT NULL,`notice`	TEXT,	`tags`	TEXT,	`photo`	BLOB);COMMIT;",
            DATABASE_NAME="paintings.db";

    public static final int VERSION=1;

    public DataBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_SCRIPT);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

Call request
DataBaseHelper h = new DataBaseHelper(this);
        SQLiteDatabase d = h.getReadableDatabase();
        d.query("pictures", null, null, null, null, null, null); //тут вылетает исключение
        h.close();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hakito, 2015-11-23
@Hakito

All figured out. The reason was in quotes around the field names. Removed them and everything worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question