错误:表不存在(显然它确实存在)

时间:2016-10-04 23:33:57

标签: android android-sqlite

我在我的数据库中有这个表Cast,其中包含ID列和Actor

ID  | Actor
----+------
123 | Michael Douglas
123 | Robert Duval

我想在光标中返回列IDCast以获取特定ID

public Cursor getCastCursor(String ID){

        SQLiteDatabase db = getReadableDatabase();
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        String[] sqlSelect = new String[]{"ID","Actor"};
        String[] selectionArg = new String[]{ID};

        qb.setTables("Cast");
        Cursor c = qb.query(
                db,           //SQLiteDatabase db
                sqlSelect,    //String[] projectionIn
                "ID=?",       //String selection
                selectionArg, //String[] selectionArgs
                null,         //String groupBy
                null,         //String having
                null);        //String sortOrder
        c.moveToFirst();

        return c;
}

我一直收到这个错误,确定原因

  

没有这样的表:Cast(代码1):,编译时:SELECT ID,Actor FROM Cast WHERE(ID =?)

修改

这是我的数据库的图片。表格显然存在。

enter image description here

我使用Python

创建数据库
#Add countries, genres, directors, and actors tables 
def createTables(source):
    with sqlite3.connect(source) as connection:
        c = connection.cursor()
        c.execute("""Select * from Movies""")
        all_data = c.fetchall()
        c.execute("""CREATE TABLE IF NOT EXISTS Countries(ID TEXT,Country TEXT)""")
        c.execute("""CREATE TABLE IF NOT EXISTS Actors(ID TEXT, Actor TEXT)""")
        c.execute("""CREATE TABLE IF NOT EXISTS Genres(ID TEXT,Genre TEXT)""")
        c.execute("""CREATE TABLE IF NOT EXISTS Directors(ID TEXT,Director TEXT)""")

        for single_data in all_data:
            countries = returnCommaDelimitedList(single_data[18])
            directors = returnCommaDelimitedList(single_data[8])
            genres = returnCommaDelimitedList(single_data[6])
            actors = returnCommaDelimitedList(single_data[10])
            for single_actor in actors:
                c.execute("INSERT INTO Actors VALUES(?,?);",(single_data[0],single_actor))
            for single_country in countries:
                c.execute("INSERT INTO Countries VALUES(?,?);",(single_data[0],single_country))
            for single_director in directors:
                c.execute("INSERT INTO Directors VALUES(?,?);",(single_data[0],single_director))
            for single_genre in genres:
                c.execute("INSERT INTO Genres VALUES(?,?);",(single_data[0],single_genre))

1 个答案:

答案 0 :(得分:-1)

所以我清理,重建并重新制作了我的项目,然后卸载并重新安装了应用程序,这就是诀窍。