How structure a SQLite database for offline support?How to list the tables in a SQLite database file that was opened with ATTACH?How do save an Android Activity state using save instance state?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I check in SQLite whether a table exists?Is it possible to insert multiple rows at a time in an SQLite database?Improve INSERT-per-second performance of SQLite?What are the best practices for SQLite on Android?How do I fix android.os.NetworkOnMainThreadException?Search in SQLite databaseSqlite or shared preference is better for data fetching with MPAndroid Library on the basis of daily ,Weekly,Monthly basis?

There is only s̶i̶x̶t̶y one place he can be

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

Why is `const int& k = i; ++i; ` possible?

Your magic is very sketchy

What would be the benefits of having both a state and local currencies?

Can I use my Chinese passport to enter China after I acquired another citizenship?

What would happen if the UK refused to take part in EU Parliamentary elections?

Should my PhD thesis be submitted under my legal name?

How do I keep an essay about "feeling flat" from feeling flat?

How could Frankenstein get the parts for his _second_ creature?

Greatest common substring

Understanding "audieritis" in Psalm 94

What is difference between behavior and behaviour

Dot above capital letter not centred

Personal Teleportation as a Weapon

Can I Retrieve Email Addresses from BCC?

Is a roofing delivery truck likely to crack my driveway slab?

Do there exist finite commutative rings with identity that are not Bézout rings?

Can criminal fraud exist without damages?

Was Spock the First Vulcan in Starfleet?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?



How structure a SQLite database for offline support?


How to list the tables in a SQLite database file that was opened with ATTACH?How do save an Android Activity state using save instance state?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I check in SQLite whether a table exists?Is it possible to insert multiple rows at a time in an SQLite database?Improve INSERT-per-second performance of SQLite?What are the best practices for SQLite on Android?How do I fix android.os.NetworkOnMainThreadException?Search in SQLite databaseSqlite or shared preference is better for data fetching with MPAndroid Library on the basis of daily ,Weekly,Monthly basis?













-2















I'm trying to give the offline support in my app, so user can read the information without the internet also. I'm creating an app to show some packages from different companies. I have created my API and following database in the remote server.



companies -- id, name
duration-- id, type (type could be, monthly, weekly, yearly)
packages -- id, name, company_id, duration_id


My API is returning result as



 
"id":3,
"package":"premimum",
"company_id":6,
"duration_id": 5,



Now I want to store all information fetched from the API to the local database SQLite. Now I want to know how I should structure my local database? should I structure same as the remote database? should I create the three tables in the local database SQLite same as?



companies -- id, name
duration-- id, type (type mean package duration, monthly, yearly, daily)
packages -- id, name, company_id, duration_id


If yes then id will be different in local database and in the remote database, because both databases will generate own primary key how I can handle this? or something you can suggest me to keep the same ID? or should I keep the id different?










share|improve this question




























    -2















    I'm trying to give the offline support in my app, so user can read the information without the internet also. I'm creating an app to show some packages from different companies. I have created my API and following database in the remote server.



    companies -- id, name
    duration-- id, type (type could be, monthly, weekly, yearly)
    packages -- id, name, company_id, duration_id


    My API is returning result as



     
    "id":3,
    "package":"premimum",
    "company_id":6,
    "duration_id": 5,



    Now I want to store all information fetched from the API to the local database SQLite. Now I want to know how I should structure my local database? should I structure same as the remote database? should I create the three tables in the local database SQLite same as?



    companies -- id, name
    duration-- id, type (type mean package duration, monthly, yearly, daily)
    packages -- id, name, company_id, duration_id


    If yes then id will be different in local database and in the remote database, because both databases will generate own primary key how I can handle this? or something you can suggest me to keep the same ID? or should I keep the id different?










    share|improve this question


























      -2












      -2








      -2








      I'm trying to give the offline support in my app, so user can read the information without the internet also. I'm creating an app to show some packages from different companies. I have created my API and following database in the remote server.



      companies -- id, name
      duration-- id, type (type could be, monthly, weekly, yearly)
      packages -- id, name, company_id, duration_id


      My API is returning result as



       
      "id":3,
      "package":"premimum",
      "company_id":6,
      "duration_id": 5,



      Now I want to store all information fetched from the API to the local database SQLite. Now I want to know how I should structure my local database? should I structure same as the remote database? should I create the three tables in the local database SQLite same as?



      companies -- id, name
      duration-- id, type (type mean package duration, monthly, yearly, daily)
      packages -- id, name, company_id, duration_id


      If yes then id will be different in local database and in the remote database, because both databases will generate own primary key how I can handle this? or something you can suggest me to keep the same ID? or should I keep the id different?










      share|improve this question
















      I'm trying to give the offline support in my app, so user can read the information without the internet also. I'm creating an app to show some packages from different companies. I have created my API and following database in the remote server.



      companies -- id, name
      duration-- id, type (type could be, monthly, weekly, yearly)
      packages -- id, name, company_id, duration_id


      My API is returning result as



       
      "id":3,
      "package":"premimum",
      "company_id":6,
      "duration_id": 5,



      Now I want to store all information fetched from the API to the local database SQLite. Now I want to know how I should structure my local database? should I structure same as the remote database? should I create the three tables in the local database SQLite same as?



      companies -- id, name
      duration-- id, type (type mean package duration, monthly, yearly, daily)
      packages -- id, name, company_id, duration_id


      If yes then id will be different in local database and in the remote database, because both databases will generate own primary key how I can handle this? or something you can suggest me to keep the same ID? or should I keep the id different?







      android sqlite android-room






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 15:26









      Fantômas

      32.8k156490




      32.8k156490










      asked Mar 21 at 14:07









      Asif MushtaqAsif Mushtaq

      1,4401737




      1,4401737






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You don't necessarly need the internal Ids on your local database to match those of your cloud server database. For instance, if you use Parse as cloud server, Parse will generate its own internal object ID. Your app does not need to know them.



          Having said that, I strongly suggest you have a common key attribute between your local object and cloud object, so that you can keep them synced.



          For example you could add a package_id attribute on both your local and cloud object. This package_id will be the same on both side, so that you can update your local object when the remote object is updated and vice-versa.



          For example, here is the code to create an object on the Parse server:



          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();


          You can them retrieve this object from the app as follows:



          ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
          query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>()
          public void done(ParseObject object, ParseException e)
          if (e == null)
          // object will be your game score
          int score = object.getInt("score");
          String playerName = object.getString("playerName");
          boolean cheatMode = object.getBoolean("cheatMode");
          else
          // something went wrong


          );


          I suggest you read the documentation for more infos on storing object on a Parse server:
          https://docs.parseplatform.org/android/guide/



          Also, this lib could help you to sync data between local database and a Parse server:
          https://github.com/ntoskrnl/DataSync






          share|improve this answer

























          • Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

            – Asif Mushtaq
            Mar 21 at 14:58










          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%2f55282307%2fhow-structure-a-sqlite-database-for-offline-support%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














          You don't necessarly need the internal Ids on your local database to match those of your cloud server database. For instance, if you use Parse as cloud server, Parse will generate its own internal object ID. Your app does not need to know them.



          Having said that, I strongly suggest you have a common key attribute between your local object and cloud object, so that you can keep them synced.



          For example you could add a package_id attribute on both your local and cloud object. This package_id will be the same on both side, so that you can update your local object when the remote object is updated and vice-versa.



          For example, here is the code to create an object on the Parse server:



          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();


          You can them retrieve this object from the app as follows:



          ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
          query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>()
          public void done(ParseObject object, ParseException e)
          if (e == null)
          // object will be your game score
          int score = object.getInt("score");
          String playerName = object.getString("playerName");
          boolean cheatMode = object.getBoolean("cheatMode");
          else
          // something went wrong


          );


          I suggest you read the documentation for more infos on storing object on a Parse server:
          https://docs.parseplatform.org/android/guide/



          Also, this lib could help you to sync data between local database and a Parse server:
          https://github.com/ntoskrnl/DataSync






          share|improve this answer

























          • Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

            – Asif Mushtaq
            Mar 21 at 14:58















          0














          You don't necessarly need the internal Ids on your local database to match those of your cloud server database. For instance, if you use Parse as cloud server, Parse will generate its own internal object ID. Your app does not need to know them.



          Having said that, I strongly suggest you have a common key attribute between your local object and cloud object, so that you can keep them synced.



          For example you could add a package_id attribute on both your local and cloud object. This package_id will be the same on both side, so that you can update your local object when the remote object is updated and vice-versa.



          For example, here is the code to create an object on the Parse server:



          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();


          You can them retrieve this object from the app as follows:



          ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
          query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>()
          public void done(ParseObject object, ParseException e)
          if (e == null)
          // object will be your game score
          int score = object.getInt("score");
          String playerName = object.getString("playerName");
          boolean cheatMode = object.getBoolean("cheatMode");
          else
          // something went wrong


          );


          I suggest you read the documentation for more infos on storing object on a Parse server:
          https://docs.parseplatform.org/android/guide/



          Also, this lib could help you to sync data between local database and a Parse server:
          https://github.com/ntoskrnl/DataSync






          share|improve this answer

























          • Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

            – Asif Mushtaq
            Mar 21 at 14:58













          0












          0








          0







          You don't necessarly need the internal Ids on your local database to match those of your cloud server database. For instance, if you use Parse as cloud server, Parse will generate its own internal object ID. Your app does not need to know them.



          Having said that, I strongly suggest you have a common key attribute between your local object and cloud object, so that you can keep them synced.



          For example you could add a package_id attribute on both your local and cloud object. This package_id will be the same on both side, so that you can update your local object when the remote object is updated and vice-versa.



          For example, here is the code to create an object on the Parse server:



          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();


          You can them retrieve this object from the app as follows:



          ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
          query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>()
          public void done(ParseObject object, ParseException e)
          if (e == null)
          // object will be your game score
          int score = object.getInt("score");
          String playerName = object.getString("playerName");
          boolean cheatMode = object.getBoolean("cheatMode");
          else
          // something went wrong


          );


          I suggest you read the documentation for more infos on storing object on a Parse server:
          https://docs.parseplatform.org/android/guide/



          Also, this lib could help you to sync data between local database and a Parse server:
          https://github.com/ntoskrnl/DataSync






          share|improve this answer















          You don't necessarly need the internal Ids on your local database to match those of your cloud server database. For instance, if you use Parse as cloud server, Parse will generate its own internal object ID. Your app does not need to know them.



          Having said that, I strongly suggest you have a common key attribute between your local object and cloud object, so that you can keep them synced.



          For example you could add a package_id attribute on both your local and cloud object. This package_id will be the same on both side, so that you can update your local object when the remote object is updated and vice-versa.



          For example, here is the code to create an object on the Parse server:



          ParseObject gameScore = new ParseObject("GameScore");
          gameScore.put("score", 1337);
          gameScore.put("playerName", "Sean Plott");
          gameScore.put("cheatMode", false);
          gameScore.saveInBackground();


          You can them retrieve this object from the app as follows:



          ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
          query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>()
          public void done(ParseObject object, ParseException e)
          if (e == null)
          // object will be your game score
          int score = object.getInt("score");
          String playerName = object.getString("playerName");
          boolean cheatMode = object.getBoolean("cheatMode");
          else
          // something went wrong


          );


          I suggest you read the documentation for more infos on storing object on a Parse server:
          https://docs.parseplatform.org/android/guide/



          Also, this lib could help you to sync data between local database and a Parse server:
          https://github.com/ntoskrnl/DataSync







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 at 16:34

























          answered Mar 21 at 14:25









          matdevmatdev

          1,00031332




          1,00031332












          • Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

            – Asif Mushtaq
            Mar 21 at 14:58

















          • Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

            – Asif Mushtaq
            Mar 21 at 14:58
















          Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

          – Asif Mushtaq
          Mar 21 at 14:58





          Common key attribute? can you share any example? how I can sync them? I'm trying this first time so I don't know how to implement, what is best practices and so on. It is totally first time.

          – Asif Mushtaq
          Mar 21 at 14:58



















          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%2f55282307%2fhow-structure-a-sqlite-database-for-offline-support%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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript