У меня проблема, когда эта таблица вообще не создается в android.
Вот вся MyDBHandler:Android SQLite Создать оператор таблицы
package com.example.plrardiakao;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "MudeDB.db";
public static final String TABLE_ITEMS = "Items";
//helper for types
public static final String VARCHAR_TYPE = " VARCHAR(50)";
public static final String BOOL_TYPE = " BOOLEAN";
public static final String INT_TYPE = " INTEGER";
//helper for column names
public static final String COLUMN_ENTRY_ID = "id"; //integer
public static final String COLUMN_TITLE = "itemtitle"; //varchar(50)
public static final String COLUMN_AUTHOR = "author"; //varchar(50)
public static final String COLUMN_CATEGORY = "category"; //varchar(50)
public static final String COLUMN_DATE = "date"; //int
public static final String COLUMN_TYPE = "type"; //varchar(50)
public static final String COLUMN_COUNTRY = "country"; //varchar(50)
public static final String COLUMN_COLOUR = "colour"; //varchar(50)
public static final String COLUMN_MATERIAL = "material"; //varchar(50)
public static final String COLUMN_FAVOURITE = "is_favourite"; //boolean
public static final String COLUMN_IMGRES = "imgres"; //varchar(50)
public static final String COLUMN_NUMBER_OF_PICS = "nr_of_pics"; // integer
public MyDBHandler(Context context, String name,
CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_ITEMS_TABLE = "CREATE TABLE " + TABLE_ITEMS +
"("
+ COLUMN_ENTRY_ID + INT_TYPE +" PRIMARY KEY AUTOINCREMENT,"
+ COLUMN_TITLE + VARCHAR_TYPE + ","
+ COLUMN_AUTHOR + VARCHAR_TYPE + ","
+ COLUMN_CATEGORY + VARCHAR_TYPE + ","
+ COLUMN_DATE + INT_TYPE + ","
+ COLUMN_TYPE + VARCHAR_TYPE + ","
+ COLUMN_COUNTRY + VARCHAR_TYPE + ","
+ COLUMN_COLOUR + VARCHAR_TYPE + ","
+ COLUMN_MATERIAL + VARCHAR_TYPE + ","
+ COLUMN_FAVOURITE + BOOL_TYPE + ","
+ COLUMN_IMGRES + VARCHAR_TYPE + ","
+ COLUMN_NUMBER_OF_PICS + INT_TYPE +
")";
db.execSQL(CREATE_ITEMS_TABLE);
}
//CREATE TABLE Items(id INTEGER PRIMARY KEY AUTOINCREMENT, itemtitle VARCHAR(50),author)
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ITEMS);
onCreate(db);
}
public void addItem(Item item) {
ContentValues values = new ContentValues();
values.put(COLUMN_TITLE, item.getItemTitle());
values.put(COLUMN_AUTHOR, item.getAuthor());
values.put(COLUMN_CATEGORY, item.getCategory());
values.put(COLUMN_DATE, item.getDate());
values.put(COLUMN_TYPE, item.getType());
values.put(COLUMN_COUNTRY, item.getCountry());
values.put(COLUMN_COLOUR, item.getColour());
values.put(COLUMN_MATERIAL, item.getMaterial());
values.put(COLUMN_FAVOURITE, item.getFavourite());
values.put(COLUMN_IMGRES, item.getImgres());
values.put(COLUMN_NUMBER_OF_PICS, item.getNumberOfPics());
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_ITEMS, null, values);
db.close();
}
public int findPictureNumber(String itemtitle) {
String query = "SELECT nr_of_pics FROM " + TABLE_ITEMS + " WHERE " +COLUMN_TITLE + "=" + "'"+itemtitle+"'" ;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
int PicsNumber=0;
if (cursor.moveToFirst()) {
cursor.moveToFirst();
PicsNumber=Integer.parseInt(cursor.getString(0));
cursor.close();
return PicsNumber;
} else {
//wtf?
}
db.close();
return 0;
}
public void changeFavourite(String itemtitle, boolean isFavourite)
{
SQLiteDatabase db = this.getWritableDatabase();
String strSQL = "UPDATE "+TABLE_ITEMS+" SET "+COLUMN_FAVOURITE +"="+ isFavourite +" WHERE columnId = "+ "'"+itemtitle+"'";
db.execSQL(strSQL);
}
public String AuthorName(String itemtitle) {
String query = "SELECT " +COLUMN_AUTHOR+ " FROM " + TABLE_ITEMS + " WHERE " +COLUMN_TITLE + "=" + "'"+itemtitle+"'" ;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
String authorname="error1";
if (cursor.moveToFirst()) {
cursor.moveToFirst();
authorname=cursor.getString(0);
cursor.close();
} else {
//wtf?
}
db.close();
return authorname;
}
}
Существует ошибка, вероятно, где-то в create_table, но я понятия не имею, где. Я знаю, что таблица не создана, есть таблица прежних таблиц-заполнителей, и после выполнения она показывает ошибку, что некоторые из столбцов не существуют. Что не так?
Версия DB! Вот что! СПАСИБО БОЛЬШОЕ! – Sheenah