• 7
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Using PrePopulated SQlite database in android

I have tried to open Sqlite database using react-native for android application but couldn't open using prepopulated database stored inside assets directory of the project.

I have removed location and createfromLocation from the openDataBase code databae was created in android device which would be empty without schema and data. I can populate data from the code but this doesn't make any sense. So What might be the mistake that I am making.Am I missing something here?

Code(App.js file):

 const db = SQLite.openDatabase(
      {
        name: 'Recipe.db',
        location: 'default',
        createFromLocation: '~Recipe.db',
      }

Log:

 OPEN database: Recipe.db
05-20 09:22:23.620  5975  6009 I ReactNativeJS: new transaction is waiting for open operation
05-20 09:22:23.629  5975  6009 I ReactNativeJS: OPEN database: Recipe.db failed, aborting any pending transactions
05-20 09:22:23.632  5975  6009 I ReactNativeJS: { [Error: Could not open database]
05-20 09:22:23.632  5975  6009 I ReactNativeJS:   code: 0,
05-20 09:22:23.632  5975  6009 I ReactNativeJS:   line: 100047,
05-20 09:22:23.632  5975  6009 I ReactNativeJS:   column: 27,

You can't open a SQLite DB for writing if it is stored in the Assets folder. Typically, on startup, an app will check to see if it has a SQLite database in its own /data/data/database folder. If not, it copies the database from the Assets folder to the /data/data/database folder, then opens that copy for writing.

Changes made to the database while in the /data/data/database folder will persist, even if the app is updated. But, it will be deleted if the user deletes the app. Then the app will have to do the database copy again.

  • 1
Reply Report
    • I am trying to use database for write operation only. So Do the above code copy the Recipe.db from assets directory to the /data/data/database so that I can perform read operation on Recipe database? I have deleted the databases from /data/data/database location and start the app but still got an issue.
      • 2
    • You need to add code in your app, which before you execute any code to read or write to the database, you call a method to see if the database exists in the /data/data/database folder, and if so, Open it. If it does not exist, then copy the database from the Assets folder to the /data/data/database folder then Open it from there.