Room not retaining data in one table










0















My application works fine upon opening. It is able to prepopulate the database from a text file in the raw folder. When I open the fragment that displays the list of exercises, the query runs fine and one can see the whole list. If I press the back button to exit the app completely and then reenter, no problem, the list populates again. The problem is when I press the recents button and hit close all. When I reenter the application, the query for all of the exercises yields nothing and the list is empty. I have searched high and low and have found nothing. Attached is hopefully enough code to diagnose issue. The AppDatabase class is based off the Google Architecture BasicSample app.



@Database(entities = BodySectionEntity.class, CardioEntity.class, ExerciseEntity.class, GoalEntity.class, SetRecordEntity.class, WorkoutEntity.class, WorkoutLibraryEntity.class, version = 1, exportSchema = false)
@TypeConverters(Converter.class)
public abstract class AppDatabase extends RoomDatabase

private static final String TAG = "AppDatabase";

private static AppDatabase sInstance;

@VisibleForTesting
public static final String DATABASE_NAME = "ig_db";

public abstract BodySectionDao bodySectionDao();
public abstract ExerciseDao exerciseDao();
public abstract WorkoutDao workoutDao();
public abstract SetRecordDao setRecordDao();

private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>();


public static AppDatabase getInstance(final Context context)
Log.d(TAG, "getInstance()");
if (sInstance == null)
synchronized (AppDatabase.class)
if (sInstance == null)
sInstance = buildDatabase(context.getApplicationContext());
sInstance.updateDatabaseCreated(context.getApplicationContext());



return sInstance;


private static AppDatabase buildDatabase(final Context appContext)
Log.d(TAG, "build database");
return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME)
.addCallback(new Callback()
@Override
public void onCreate(@NonNull SupportSQLiteDatabase db)
super.onCreate(db);
Executors.newSingleThreadScheduledExecutor().execute(new Runnable()
@Override
public void run()
try
AppDatabase database = AppDatabase.getInstance(appContext);
List<String> groups = Arrays.asList(appContext.getResources().getStringArray(R.array.groups));
populateDatabase(appContext, database, groups);
database.setDatabaseCreated();
catch (IOException e)
Log.d(TAG, e.toString());


);


@Override
public void onOpen(@NonNull SupportSQLiteDatabase db)
super.onOpen(db);

).build();


/**
* Check whether the database already exists and expose it via @link #getDatabaseCreated()
*/
private void updateDatabaseCreated(final Context context)
Log.d(TAG, "updatedatabasecreated");
if (context.getDatabasePath(DATABASE_NAME).exists())
setDatabaseCreated();



private void setDatabaseCreated()
Log.d(TAG, "setdatabasecreated");
mIsDatabaseCreated.postValue(true);


public LiveData<Boolean> getDatabaseCreated()
Log.d(TAG, "getdatabasecreated");
return mIsDatabaseCreated;


private static void populateDatabase(final Context context, final AppDatabase db, final List<String> groups) throws IOException
//insert the body parts
Log.d(TAG, "populateDatabase");
List<BodySectionEntity> list = new ArrayList<>();
for (String section : groups)
list.add(new BodySectionEntity(section));

db.bodySectionDao().insertAll(list);

//insert the exercise data
InputStream inputStream = context.getResources().openRawResource(R.raw.exercise_data);
List<ExerciseEntity> exerciseEntities = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)))
String line;
while ((line = reader.readLine()) != null)
Log.i("IGv2", "inside while");
String strings = TextUtils.split(line, ",");
exerciseEntities.add(new ExerciseEntity(
strings[0].trim(),
findBodySectionKey(strings[1], groups),
strings[2].trim(),
strings[3].trim(),
strings[4].trim(),
strings[5].trim()));

Log.i("IGv2", "size: " + exerciseEntities.size());
db.exerciseDao().insertAll(exerciseEntities);
Log.i("IGv2", "exercises entered");



//grabs the correct id for the COL_BODY_SECTION_ID column and returns it
private static int findBodySectionKey(String part, final List<String> groups)
Log.d("IGv2", "findboydsectionkey");
int index = groups.indexOf(part);
return ++index;




ExerciseDao



@Dao
public interface ExerciseDao

@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<ExerciseEntity> exercises);

@Query("Select * From exercise Order By body_section_id, exercise ASC")
LiveData<List<ExerciseEntity>> getAllExercises();



WorkoutFragment




@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this).get(WorkoutViewModel.class);
mViewModel.getAllExercises().observe(this, new Observer<List<ExerciseEntity>>()
@Override
public void onChanged(List<ExerciseEntity> exerciseEntities)
if (exerciseEntities != null)
Toast.makeText(getContext(), "Size: " + exerciseEntities.size(), Toast.LENGTH_SHORT).show();
mExerAdapter.setExerciseList(exerciseEntities);


);
mWorkoutAdapter.setWorkout(mViewModel.getWorkout());



If more is needed, please advise. Thanks in advance










share|improve this question


























    0















    My application works fine upon opening. It is able to prepopulate the database from a text file in the raw folder. When I open the fragment that displays the list of exercises, the query runs fine and one can see the whole list. If I press the back button to exit the app completely and then reenter, no problem, the list populates again. The problem is when I press the recents button and hit close all. When I reenter the application, the query for all of the exercises yields nothing and the list is empty. I have searched high and low and have found nothing. Attached is hopefully enough code to diagnose issue. The AppDatabase class is based off the Google Architecture BasicSample app.



    @Database(entities = BodySectionEntity.class, CardioEntity.class, ExerciseEntity.class, GoalEntity.class, SetRecordEntity.class, WorkoutEntity.class, WorkoutLibraryEntity.class, version = 1, exportSchema = false)
    @TypeConverters(Converter.class)
    public abstract class AppDatabase extends RoomDatabase

    private static final String TAG = "AppDatabase";

    private static AppDatabase sInstance;

    @VisibleForTesting
    public static final String DATABASE_NAME = "ig_db";

    public abstract BodySectionDao bodySectionDao();
    public abstract ExerciseDao exerciseDao();
    public abstract WorkoutDao workoutDao();
    public abstract SetRecordDao setRecordDao();

    private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>();


    public static AppDatabase getInstance(final Context context)
    Log.d(TAG, "getInstance()");
    if (sInstance == null)
    synchronized (AppDatabase.class)
    if (sInstance == null)
    sInstance = buildDatabase(context.getApplicationContext());
    sInstance.updateDatabaseCreated(context.getApplicationContext());



    return sInstance;


    private static AppDatabase buildDatabase(final Context appContext)
    Log.d(TAG, "build database");
    return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME)
    .addCallback(new Callback()
    @Override
    public void onCreate(@NonNull SupportSQLiteDatabase db)
    super.onCreate(db);
    Executors.newSingleThreadScheduledExecutor().execute(new Runnable()
    @Override
    public void run()
    try
    AppDatabase database = AppDatabase.getInstance(appContext);
    List<String> groups = Arrays.asList(appContext.getResources().getStringArray(R.array.groups));
    populateDatabase(appContext, database, groups);
    database.setDatabaseCreated();
    catch (IOException e)
    Log.d(TAG, e.toString());


    );


    @Override
    public void onOpen(@NonNull SupportSQLiteDatabase db)
    super.onOpen(db);

    ).build();


    /**
    * Check whether the database already exists and expose it via @link #getDatabaseCreated()
    */
    private void updateDatabaseCreated(final Context context)
    Log.d(TAG, "updatedatabasecreated");
    if (context.getDatabasePath(DATABASE_NAME).exists())
    setDatabaseCreated();



    private void setDatabaseCreated()
    Log.d(TAG, "setdatabasecreated");
    mIsDatabaseCreated.postValue(true);


    public LiveData<Boolean> getDatabaseCreated()
    Log.d(TAG, "getdatabasecreated");
    return mIsDatabaseCreated;


    private static void populateDatabase(final Context context, final AppDatabase db, final List<String> groups) throws IOException
    //insert the body parts
    Log.d(TAG, "populateDatabase");
    List<BodySectionEntity> list = new ArrayList<>();
    for (String section : groups)
    list.add(new BodySectionEntity(section));

    db.bodySectionDao().insertAll(list);

    //insert the exercise data
    InputStream inputStream = context.getResources().openRawResource(R.raw.exercise_data);
    List<ExerciseEntity> exerciseEntities = new ArrayList<>();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)))
    String line;
    while ((line = reader.readLine()) != null)
    Log.i("IGv2", "inside while");
    String strings = TextUtils.split(line, ",");
    exerciseEntities.add(new ExerciseEntity(
    strings[0].trim(),
    findBodySectionKey(strings[1], groups),
    strings[2].trim(),
    strings[3].trim(),
    strings[4].trim(),
    strings[5].trim()));

    Log.i("IGv2", "size: " + exerciseEntities.size());
    db.exerciseDao().insertAll(exerciseEntities);
    Log.i("IGv2", "exercises entered");



    //grabs the correct id for the COL_BODY_SECTION_ID column and returns it
    private static int findBodySectionKey(String part, final List<String> groups)
    Log.d("IGv2", "findboydsectionkey");
    int index = groups.indexOf(part);
    return ++index;




    ExerciseDao



    @Dao
    public interface ExerciseDao

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<ExerciseEntity> exercises);

    @Query("Select * From exercise Order By body_section_id, exercise ASC")
    LiveData<List<ExerciseEntity>> getAllExercises();



    WorkoutFragment




    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState)
    super.onActivityCreated(savedInstanceState);
    mViewModel = ViewModelProviders.of(this).get(WorkoutViewModel.class);
    mViewModel.getAllExercises().observe(this, new Observer<List<ExerciseEntity>>()
    @Override
    public void onChanged(List<ExerciseEntity> exerciseEntities)
    if (exerciseEntities != null)
    Toast.makeText(getContext(), "Size: " + exerciseEntities.size(), Toast.LENGTH_SHORT).show();
    mExerAdapter.setExerciseList(exerciseEntities);


    );
    mWorkoutAdapter.setWorkout(mViewModel.getWorkout());



    If more is needed, please advise. Thanks in advance










    share|improve this question
























      0












      0








      0








      My application works fine upon opening. It is able to prepopulate the database from a text file in the raw folder. When I open the fragment that displays the list of exercises, the query runs fine and one can see the whole list. If I press the back button to exit the app completely and then reenter, no problem, the list populates again. The problem is when I press the recents button and hit close all. When I reenter the application, the query for all of the exercises yields nothing and the list is empty. I have searched high and low and have found nothing. Attached is hopefully enough code to diagnose issue. The AppDatabase class is based off the Google Architecture BasicSample app.



      @Database(entities = BodySectionEntity.class, CardioEntity.class, ExerciseEntity.class, GoalEntity.class, SetRecordEntity.class, WorkoutEntity.class, WorkoutLibraryEntity.class, version = 1, exportSchema = false)
      @TypeConverters(Converter.class)
      public abstract class AppDatabase extends RoomDatabase

      private static final String TAG = "AppDatabase";

      private static AppDatabase sInstance;

      @VisibleForTesting
      public static final String DATABASE_NAME = "ig_db";

      public abstract BodySectionDao bodySectionDao();
      public abstract ExerciseDao exerciseDao();
      public abstract WorkoutDao workoutDao();
      public abstract SetRecordDao setRecordDao();

      private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>();


      public static AppDatabase getInstance(final Context context)
      Log.d(TAG, "getInstance()");
      if (sInstance == null)
      synchronized (AppDatabase.class)
      if (sInstance == null)
      sInstance = buildDatabase(context.getApplicationContext());
      sInstance.updateDatabaseCreated(context.getApplicationContext());



      return sInstance;


      private static AppDatabase buildDatabase(final Context appContext)
      Log.d(TAG, "build database");
      return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME)
      .addCallback(new Callback()
      @Override
      public void onCreate(@NonNull SupportSQLiteDatabase db)
      super.onCreate(db);
      Executors.newSingleThreadScheduledExecutor().execute(new Runnable()
      @Override
      public void run()
      try
      AppDatabase database = AppDatabase.getInstance(appContext);
      List<String> groups = Arrays.asList(appContext.getResources().getStringArray(R.array.groups));
      populateDatabase(appContext, database, groups);
      database.setDatabaseCreated();
      catch (IOException e)
      Log.d(TAG, e.toString());


      );


      @Override
      public void onOpen(@NonNull SupportSQLiteDatabase db)
      super.onOpen(db);

      ).build();


      /**
      * Check whether the database already exists and expose it via @link #getDatabaseCreated()
      */
      private void updateDatabaseCreated(final Context context)
      Log.d(TAG, "updatedatabasecreated");
      if (context.getDatabasePath(DATABASE_NAME).exists())
      setDatabaseCreated();



      private void setDatabaseCreated()
      Log.d(TAG, "setdatabasecreated");
      mIsDatabaseCreated.postValue(true);


      public LiveData<Boolean> getDatabaseCreated()
      Log.d(TAG, "getdatabasecreated");
      return mIsDatabaseCreated;


      private static void populateDatabase(final Context context, final AppDatabase db, final List<String> groups) throws IOException
      //insert the body parts
      Log.d(TAG, "populateDatabase");
      List<BodySectionEntity> list = new ArrayList<>();
      for (String section : groups)
      list.add(new BodySectionEntity(section));

      db.bodySectionDao().insertAll(list);

      //insert the exercise data
      InputStream inputStream = context.getResources().openRawResource(R.raw.exercise_data);
      List<ExerciseEntity> exerciseEntities = new ArrayList<>();
      try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)))
      String line;
      while ((line = reader.readLine()) != null)
      Log.i("IGv2", "inside while");
      String strings = TextUtils.split(line, ",");
      exerciseEntities.add(new ExerciseEntity(
      strings[0].trim(),
      findBodySectionKey(strings[1], groups),
      strings[2].trim(),
      strings[3].trim(),
      strings[4].trim(),
      strings[5].trim()));

      Log.i("IGv2", "size: " + exerciseEntities.size());
      db.exerciseDao().insertAll(exerciseEntities);
      Log.i("IGv2", "exercises entered");



      //grabs the correct id for the COL_BODY_SECTION_ID column and returns it
      private static int findBodySectionKey(String part, final List<String> groups)
      Log.d("IGv2", "findboydsectionkey");
      int index = groups.indexOf(part);
      return ++index;




      ExerciseDao



      @Dao
      public interface ExerciseDao

      @Insert(onConflict = OnConflictStrategy.REPLACE)
      void insertAll(List<ExerciseEntity> exercises);

      @Query("Select * From exercise Order By body_section_id, exercise ASC")
      LiveData<List<ExerciseEntity>> getAllExercises();



      WorkoutFragment




      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      super.onActivityCreated(savedInstanceState);
      mViewModel = ViewModelProviders.of(this).get(WorkoutViewModel.class);
      mViewModel.getAllExercises().observe(this, new Observer<List<ExerciseEntity>>()
      @Override
      public void onChanged(List<ExerciseEntity> exerciseEntities)
      if (exerciseEntities != null)
      Toast.makeText(getContext(), "Size: " + exerciseEntities.size(), Toast.LENGTH_SHORT).show();
      mExerAdapter.setExerciseList(exerciseEntities);


      );
      mWorkoutAdapter.setWorkout(mViewModel.getWorkout());



      If more is needed, please advise. Thanks in advance










      share|improve this question














      My application works fine upon opening. It is able to prepopulate the database from a text file in the raw folder. When I open the fragment that displays the list of exercises, the query runs fine and one can see the whole list. If I press the back button to exit the app completely and then reenter, no problem, the list populates again. The problem is when I press the recents button and hit close all. When I reenter the application, the query for all of the exercises yields nothing and the list is empty. I have searched high and low and have found nothing. Attached is hopefully enough code to diagnose issue. The AppDatabase class is based off the Google Architecture BasicSample app.



      @Database(entities = BodySectionEntity.class, CardioEntity.class, ExerciseEntity.class, GoalEntity.class, SetRecordEntity.class, WorkoutEntity.class, WorkoutLibraryEntity.class, version = 1, exportSchema = false)
      @TypeConverters(Converter.class)
      public abstract class AppDatabase extends RoomDatabase

      private static final String TAG = "AppDatabase";

      private static AppDatabase sInstance;

      @VisibleForTesting
      public static final String DATABASE_NAME = "ig_db";

      public abstract BodySectionDao bodySectionDao();
      public abstract ExerciseDao exerciseDao();
      public abstract WorkoutDao workoutDao();
      public abstract SetRecordDao setRecordDao();

      private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>();


      public static AppDatabase getInstance(final Context context)
      Log.d(TAG, "getInstance()");
      if (sInstance == null)
      synchronized (AppDatabase.class)
      if (sInstance == null)
      sInstance = buildDatabase(context.getApplicationContext());
      sInstance.updateDatabaseCreated(context.getApplicationContext());



      return sInstance;


      private static AppDatabase buildDatabase(final Context appContext)
      Log.d(TAG, "build database");
      return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME)
      .addCallback(new Callback()
      @Override
      public void onCreate(@NonNull SupportSQLiteDatabase db)
      super.onCreate(db);
      Executors.newSingleThreadScheduledExecutor().execute(new Runnable()
      @Override
      public void run()
      try
      AppDatabase database = AppDatabase.getInstance(appContext);
      List<String> groups = Arrays.asList(appContext.getResources().getStringArray(R.array.groups));
      populateDatabase(appContext, database, groups);
      database.setDatabaseCreated();
      catch (IOException e)
      Log.d(TAG, e.toString());


      );


      @Override
      public void onOpen(@NonNull SupportSQLiteDatabase db)
      super.onOpen(db);

      ).build();


      /**
      * Check whether the database already exists and expose it via @link #getDatabaseCreated()
      */
      private void updateDatabaseCreated(final Context context)
      Log.d(TAG, "updatedatabasecreated");
      if (context.getDatabasePath(DATABASE_NAME).exists())
      setDatabaseCreated();



      private void setDatabaseCreated()
      Log.d(TAG, "setdatabasecreated");
      mIsDatabaseCreated.postValue(true);


      public LiveData<Boolean> getDatabaseCreated()
      Log.d(TAG, "getdatabasecreated");
      return mIsDatabaseCreated;


      private static void populateDatabase(final Context context, final AppDatabase db, final List<String> groups) throws IOException
      //insert the body parts
      Log.d(TAG, "populateDatabase");
      List<BodySectionEntity> list = new ArrayList<>();
      for (String section : groups)
      list.add(new BodySectionEntity(section));

      db.bodySectionDao().insertAll(list);

      //insert the exercise data
      InputStream inputStream = context.getResources().openRawResource(R.raw.exercise_data);
      List<ExerciseEntity> exerciseEntities = new ArrayList<>();
      try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)))
      String line;
      while ((line = reader.readLine()) != null)
      Log.i("IGv2", "inside while");
      String strings = TextUtils.split(line, ",");
      exerciseEntities.add(new ExerciseEntity(
      strings[0].trim(),
      findBodySectionKey(strings[1], groups),
      strings[2].trim(),
      strings[3].trim(),
      strings[4].trim(),
      strings[5].trim()));

      Log.i("IGv2", "size: " + exerciseEntities.size());
      db.exerciseDao().insertAll(exerciseEntities);
      Log.i("IGv2", "exercises entered");



      //grabs the correct id for the COL_BODY_SECTION_ID column and returns it
      private static int findBodySectionKey(String part, final List<String> groups)
      Log.d("IGv2", "findboydsectionkey");
      int index = groups.indexOf(part);
      return ++index;




      ExerciseDao



      @Dao
      public interface ExerciseDao

      @Insert(onConflict = OnConflictStrategy.REPLACE)
      void insertAll(List<ExerciseEntity> exercises);

      @Query("Select * From exercise Order By body_section_id, exercise ASC")
      LiveData<List<ExerciseEntity>> getAllExercises();



      WorkoutFragment




      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      super.onActivityCreated(savedInstanceState);
      mViewModel = ViewModelProviders.of(this).get(WorkoutViewModel.class);
      mViewModel.getAllExercises().observe(this, new Observer<List<ExerciseEntity>>()
      @Override
      public void onChanged(List<ExerciseEntity> exerciseEntities)
      if (exerciseEntities != null)
      Toast.makeText(getContext(), "Size: " + exerciseEntities.size(), Toast.LENGTH_SHORT).show();
      mExerAdapter.setExerciseList(exerciseEntities);


      );
      mWorkoutAdapter.setWorkout(mViewModel.getWorkout());



      If more is needed, please advise. Thanks in advance







      android android-room android-livedata






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 1:43









      b.Dotb.Dot

      13




      13






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I found the fix to be in the creation of the AppDatabase where at the very bottom through db.exerciseDao().insertAll(exerciseEntities); I tried to do an insert with over 500 records. When I put a for statement around it and did each one individually, it worked with no issues. I found other sources online that said using a SQLite transaction works better for that large number of inserts at once and also that SQLite can only handle 500 inserts at once. Either way the for statement solved the issue






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291994%2froom-not-retaining-data-in-one-table%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I found the fix to be in the creation of the AppDatabase where at the very bottom through db.exerciseDao().insertAll(exerciseEntities); I tried to do an insert with over 500 records. When I put a for statement around it and did each one individually, it worked with no issues. I found other sources online that said using a SQLite transaction works better for that large number of inserts at once and also that SQLite can only handle 500 inserts at once. Either way the for statement solved the issue






            share|improve this answer



























              0














              I found the fix to be in the creation of the AppDatabase where at the very bottom through db.exerciseDao().insertAll(exerciseEntities); I tried to do an insert with over 500 records. When I put a for statement around it and did each one individually, it worked with no issues. I found other sources online that said using a SQLite transaction works better for that large number of inserts at once and also that SQLite can only handle 500 inserts at once. Either way the for statement solved the issue






              share|improve this answer

























                0












                0








                0







                I found the fix to be in the creation of the AppDatabase where at the very bottom through db.exerciseDao().insertAll(exerciseEntities); I tried to do an insert with over 500 records. When I put a for statement around it and did each one individually, it worked with no issues. I found other sources online that said using a SQLite transaction works better for that large number of inserts at once and also that SQLite can only handle 500 inserts at once. Either way the for statement solved the issue






                share|improve this answer













                I found the fix to be in the creation of the AppDatabase where at the very bottom through db.exerciseDao().insertAll(exerciseEntities); I tried to do an insert with over 500 records. When I put a for statement around it and did each one individually, it worked with no issues. I found other sources online that said using a SQLite transaction works better for that large number of inserts at once and also that SQLite can only handle 500 inserts at once. Either way the for statement solved the issue







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 13:14









                b.Dotb.Dot

                13




                13



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291994%2froom-not-retaining-data-in-one-table%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3