数据库不会被删除

时间:2018-04-20 15:03:04

标签: java android database sqlite

我有一个数据库,但在我想添加数据之前,我想清除它:

private Cursor getAllPlayers(){


    try {
        playerDatabase.beginTransaction();
        playerDatabase.delete (PlayerDetails.PlayerTableEntry.TABLE_NAME,null,null);
    }
    catch (SQLException e){
        //Something
    }
    finally {
        playerDatabase.endTransaction();
    }
    playerDatabase = ComposeMessage.addPlayerToTheDatabase(playerDatabase, playerDataSet);
    return playerDatabase.query(PlayerDetails.PlayerTableEntry.TABLE_NAME,
            null,null,null,
            null,null, PlayerDetails.PlayerTableEntry.COLUMN_PLAYER_NAME);
}

但表格不会被清除,我通过仿真器上的shell通过终端上的sqlite3进行检查,可以看到数据一直在增加,行号也在增加。

表格:

public static final class PlayerTableEntry implements BaseColumns{
    public static final String TABLE_NAME = "playerTable";
    public static final String COLUMN_PLAYER_NAME = "playerName";
    public static final String COLUMN_PLAYER_NUMBER = "playerNumber";
    public static final String COLUMN_IS_PLAYING = "isPlaying";
}

不确定我在这里错过了什么或做错了什么?

1 个答案:

答案 0 :(得分:0)

我无法理解为什么它不起作用。你可以试试下面的代码。

int main(int argc, char *argv[]) {

    MPI_Init(&argc, &argv);
    int rank , n_spawns = 4;
    int *msg = malloc(sizeof(int)* n_spawns*4);
    int *recvbuf = malloc(sizeof(int) * n_spawns);

    MPI_Comm intercomm;
    MPI_Comm_get_parent(&intercomm);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    printf("the rank : %d \n",rank);
    for(int i=0;i<n_spawns;i++) {
        printf("%d ", recvbuf[i]);
        recvbuf[i] = recvbuf[i] + 1;
    }
    printf("\n");
    MPI_Finalize();
    return 0;
}