app/src/main/java/io/github/ilya_lebedev/popularmovies/data/MoviesDbHelper.java
/**
     * Called when the database is created for the first time.
     *
     * @param sqLiteDatabase The database.
     */
Called when the database is created for the first time.
@param sqLiteDatabase The database.
Called when the database is created for the first time . @param sqLiteDatabase The database .
@Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        final String SQL_BASE_PART =
                MoviesContract.MovieEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        MoviesContract.MovieEntry.COLUMN_MOVIE_ID + " INTEGER NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_TITLE + " TEXT NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_OVERVIEW + " TEXT NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_POSTER_PATH + " TEXT NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_RELEASE_DATE + " INTEGER NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_POPULARITY + " REAL NOT NULL, " +
                        MoviesContract.MovieEntry.COLUMN_VOTE_AVERAGE + " REAL NOT NULL, ";
        final String SQL_CREATE_TOP_RATED_MOVIE_TABLE =
                "CREATE TABLE " + MoviesContract.MovieEntry.TABLE_NAME_TOP_RATED + "(" +
                        SQL_BASE_PART +
                        " UNIQUE (" + MoviesContract.MovieEntry.COLUMN_MOVIE_ID + ") ON CONFLICT REPLACE);";
        final String SQL_CREATE_MOST_POPULAR_MOVIE_TABLE =
                "CREATE TABLE " + MoviesContract.MovieEntry.TABLE_NAME_MOST_POPULAR + "(" +
                        SQL_BASE_PART +
                        " UNIQUE (" + MoviesContract.MovieEntry.COLUMN_MOVIE_ID + ") ON CONFLICT REPLACE);";
        final String SQL_CREATE_FAVORITE_MOVIE_TABLE =
                "CREATE TABLE " + MoviesContract.MovieEntry.TABLE_NAME_FAVORITE + "(" +
                        SQL_BASE_PART +
                        MoviesContract.MovieEntry.COLUMN_LAST_UPDATE_TIME + " INTEGER NOT NULL" +
                        ");";
        final String SQL_CREATE_VIDEO_TABLE =
                "CREATE TABLE " + MoviesContract.VideoEntry.TABLE_NAME + "(" +
                        MoviesContract.VideoEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        MoviesContract.VideoEntry.COLUMN_MOVIE_TMDB_ID + " INTEGER NOT NULL, " +
                        MoviesContract.VideoEntry.COLUMN_TMDB_ID + " TEXT NOT NULL, " +
                        MoviesContract.VideoEntry.COLUMN_KEY + " TEXT NOT NULL, " +
                        MoviesContract.VideoEntry.COLUMN_NAME + " TEXT NOT NULL, " +
                        MoviesContract.VideoEntry.COLUMN_SITE + " TEXT NOT NULL, " +
                        MoviesContract.VideoEntry.COLUMN_TYPE + " TEXT NOT NULL, " +
                        " UNIQUE (" + MoviesContract.VideoEntry.COLUMN_TMDB_ID + ") ON CONFLICT REPLACE);";
        final String SQL_CREATE_REVIEW_TABLE =
                "CREATE TABLE " + MoviesContract.ReviewEntry.TABLE_NAME + "(" +
                        MoviesContract.ReviewEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        MoviesContract.ReviewEntry.COLUMN_MOVIE_TMDB_ID + " INTEGER NOT NULL, " +
                        MoviesContract.ReviewEntry.COLUMN_TMDB_ID + " TEXT NOT NULL, " +
                        MoviesContract.ReviewEntry.COLUMN_AUTHOR + " TEXT NOT NULL, " +
                        MoviesContract.ReviewEntry.COLUMN_CONTENT + " TEXT NOT NULL, " +
                        " UNIQUE (" + MoviesContract.ReviewEntry.COLUMN_TMDB_ID + ") ON CONFLICT REPLACE);";
        sqLiteDatabase.execSQL(SQL_CREATE_TOP_RATED_MOVIE_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_MOST_POPULAR_MOVIE_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_FAVORITE_MOVIE_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_VIDEO_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_REVIEW_TABLE);
    }
@ Override public void onCreate ( SQLiteDatabase sqLiteDatabase ) { final String SQL_BASE_PART = MoviesContract . MovieEntry . _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MoviesContract . MovieEntry . COLUMN_MOVIE_ID + " INTEGER NOT NULL, " + MoviesContract . MovieEntry . COLUMN_TITLE + " TEXT NOT NULL, " + MoviesContract . MovieEntry . COLUMN_OVERVIEW + " TEXT NOT NULL, " + MoviesContract . MovieEntry . COLUMN_POSTER_PATH + " TEXT NOT NULL, " + MoviesContract . MovieEntry . COLUMN_RELEASE_DATE + " INTEGER NOT NULL, " + MoviesContract . MovieEntry . COLUMN_POPULARITY + " REAL NOT NULL, " + MoviesContract . MovieEntry . COLUMN_VOTE_AVERAGE + " REAL NOT NULL, " ; final String SQL_CREATE_TOP_RATED_MOVIE_TABLE = "CREATE TABLE " + MoviesContract . MovieEntry . TABLE_NAME_TOP_RATED + "(" + SQL_BASE_PART + " UNIQUE (" + MoviesContract . MovieEntry . COLUMN_MOVIE_ID + ") ON CONFLICT REPLACE);" ; final String SQL_CREATE_MOST_POPULAR_MOVIE_TABLE = "CREATE TABLE " + MoviesContract . MovieEntry . TABLE_NAME_MOST_POPULAR + "(" + SQL_BASE_PART + " UNIQUE (" + MoviesContract . MovieEntry . COLUMN_MOVIE_ID + ") ON CONFLICT REPLACE);" ; final String SQL_CREATE_FAVORITE_MOVIE_TABLE = "CREATE TABLE " + MoviesContract . MovieEntry . TABLE_NAME_FAVORITE + "(" + SQL_BASE_PART + MoviesContract . MovieEntry . COLUMN_LAST_UPDATE_TIME + " INTEGER NOT NULL" + ");" ; final String SQL_CREATE_VIDEO_TABLE = "CREATE TABLE " + MoviesContract . VideoEntry . TABLE_NAME + "(" + MoviesContract . VideoEntry . _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MoviesContract . VideoEntry . COLUMN_MOVIE_TMDB_ID + " INTEGER NOT NULL, " + MoviesContract . VideoEntry . COLUMN_TMDB_ID + " TEXT NOT NULL, " + MoviesContract . VideoEntry . COLUMN_KEY + " TEXT NOT NULL, " + MoviesContract . VideoEntry . COLUMN_NAME + " TEXT NOT NULL, " + MoviesContract . VideoEntry . COLUMN_SITE + " TEXT NOT NULL, " + MoviesContract . VideoEntry . COLUMN_TYPE + " TEXT NOT NULL, " + " UNIQUE (" + MoviesContract . VideoEntry . COLUMN_TMDB_ID + ") ON CONFLICT REPLACE);" ; final String SQL_CREATE_REVIEW_TABLE = "CREATE TABLE " + MoviesContract . ReviewEntry . TABLE_NAME + "(" + MoviesContract . ReviewEntry . _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MoviesContract . ReviewEntry . COLUMN_MOVIE_TMDB_ID + " INTEGER NOT NULL, " + MoviesContract . ReviewEntry . COLUMN_TMDB_ID + " TEXT NOT NULL, " + MoviesContract . ReviewEntry . COLUMN_AUTHOR + " TEXT NOT NULL, " + MoviesContract . ReviewEntry . COLUMN_CONTENT + " TEXT NOT NULL, " + " UNIQUE (" + MoviesContract . ReviewEntry . COLUMN_TMDB_ID + ") ON CONFLICT REPLACE);" ; sqLiteDatabase . execSQL ( SQL_CREATE_TOP_RATED_MOVIE_TABLE ) ; sqLiteDatabase . execSQL ( SQL_CREATE_MOST_POPULAR_MOVIE_TABLE ) ; sqLiteDatabase . execSQL ( SQL_CREATE_FAVORITE_MOVIE_TABLE ) ; sqLiteDatabase . execSQL ( SQL_CREATE_VIDEO_TABLE ) ; sqLiteDatabase . execSQL ( SQL_CREATE_REVIEW_TABLE ) ; }
Called when the database is created for the first time.
Called when the database is created for the first time .