データを作成および挿入するためのデータベース テーブルを作成しました。全文検索用に作った「仮想テーブル」です。しかし、アプリを実行すると、「そのようなテーブルが見つかりません」という警告が表示されます..
私を助けてください。データベースファイルを投稿しています。前もって感謝します...
package com.search.wordfinder;
import java.util.ArrayList;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.ContentValues;
import android.util.*;
public class DatabaseCreation extends SQLiteOpenHelper {
String sString;
SQLiteDatabase mDatabase;
String query;
public static final String DATABASE_NAME = "wor.db";
public static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME = "cpy_fts";
public static final String DATABASE_CREATE = "CREATE VIRTUAL TABLE " + TABLE_NAME + " USING FTS3" + "(" + "title TEXT, " + "author TEXT, " + "publisher TEXT, " + "edition TEXT, " + "content TEXT" + ")";
public DatabaseCreation(Context context) {
super(context, DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try{
db.delete(TABLE_NAME, null, null);
db.execSQL(DATABASE_CREATE);
insertData("Operating System", "PeterGalvin", "Willey", "Eight", "An operating System (OS) is a collection of software that manages computer hardware resources and provides common services for computer programs.");
insertData("Database Management System", "Korth", "McGraw-Hill", "Fourth", "A DataBase Management System (DBMS) is a software system that manages execution of users applications to access and modify database.");
} catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DatabaseCreation.class.getName(),"Upgrading database from version " +
oldVersion + " to " + newVersion + ",which will destroy all old data");
db.execSQL("Drop table if exists" + TABLE_NAME);
onCreate(db);
}
public void insertData(String ttl, String athr, String pub, String ed, String cnt) {
mDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("title", ttl);
values.put("author", athr);
values.put("publisher", pub);
values.put("edition", ed);
values.put("content", cnt);
mDatabase.insert(TABLE_NAME, null, values);
mDatabase.close();
}
public ArrayList<String> queryDatabase(String id){
sString=id;
ArrayList<String> data = new ArrayList<String>();
try{
query = "SELECT title,author,publisher,edition FROM " + TABLE_NAME + " WHERE content MATCH '"+sString+"'";
Cursor c = this.getReadableDatabase().rawQuery(query, null);
c.moveToFirst();
while(c.isAfterLast()==false){
String str = "Title: " + c.getString(0) +"\n"+ "Author: " + c.getString(1)+ "\n" + "Publisher: " + c.getString(2) + "\n" +
"Edition: " + c.getString(3);
data.add(str);
c.moveToNext();
}
c.close();
} catch(Exception e) {
e.printStackTrace();
}
return data;
}
}