1
import Expo, { SQLite } from 'expo';
const db = SQLite.openDatabase('db.db');
export function create(){
    db.transaction(tx => {
      tx.executeSql(
        'CREATE TABLE if not exists material_mg (ID INT PRIMARY KEY ,order_number VARCHAR(10) ,truck_number VARCHAR(10) ,enter_mine_date  TEXT ,vehicle_owner_name VARCHAR(50) ,driver_address TEXT ,driver_mobile_number BIGINT ,weigh_bridge FLOAT,in_time TEXT ,out_time  TEXT ,drop_off_point  TEXT ,transporter_name VARCHAR(50) ,loaded_from VARCHAR(50) ,mines_name VARCHAR(50) ,material  VARCHAR(20) ,total_number_of_seats SMALLINT ,loading_in_timestamp  TEXT,loading_out_timestamp TEXT,unloading_company_name VARCHAR(50) ,unloading_company_address VARCHAR(100),type_of_trip VARCHAR(5)  ,loading_supervisor_name VARCHAR(50) ,weight FLOAT ,challan_date TEXT,challan_number VARCHAR(10) ,t_h CHAR ,party_name VARCHAR(50) ,sil_number VARCHAR(10) ,diesel INT,advance INT,booking_name VARCHAR(50) ,colliery_name VARCHAR(50) ,lifter_name VARCHAR(50) ,coalnet_weight FLOAT ,gross_weight FLOAT ,tare_weight FLOAT ,net_weight FLOAT ,remarks TEXT  ,ccl_bill_number INT ,cash INT ,destination  VARCHAR(50) ,broker_name  VARCHAR(50) ,broker_mobile_number  BIGINT )',null,(tx,resultset)=>{console.log(resultset)},(tx,resultset)=>{console.log(resultset)}
      );
    });
  }

The above code is my database file. when i execute this create query i get attempt to write a readonly database (code 1032) error. I am using the expo client with React Native. Not sure about where to configure the access control. Can't find anything on the expo sqlite docs as well. Any help is appreciated. The other solutions mentioned don't apply here because i am using the CRNA approach.

Yash Sharma
  • 811
  • 1
  • 9
  • 27
  • Have you considered that the file is indeed write-protected? Have you tried with the SQLite CLI? – Murphy Jan 24 '18 at 09:54
  • which file are you talking about ? @Murphy – Yash Sharma Jan 24 '18 at 10:12
  • The database file you try to write to, `db.db`. If it doesn't exist yet, it could also be the working directory you don't have write permissions for. Check that. – Murphy Jan 24 '18 at 10:15
  • Possible duplicate of [Change SQLite database mode to read-write](https://stackoverflow.com/questions/1518729/change-sqlite-database-mode-to-read-write) – Murphy Jan 24 '18 at 12:05
  • @Murphy Couldn't figure out a solution yet. I am using the CRNA approach for react native . I don't have any gradle or build files . – Yash Sharma Feb 05 '18 at 14:01
  • @Murphy this is not a duplicate of the question you linked. This is specific to React-Native and its Sqlite library. The question you linked is about file permissions on an unspecified OS. – Andrew Koster Mar 19 '19 at 21:48
  • File definitely exists in my case, and I don't have control over file permissions in iOS. – Andrew Koster Mar 19 '19 at 21:48

1 Answers1

0

That may happen when the DB file is removed or renamed. See 1032 error code explanation - https://www.sqlite.org/rescode.html#readonly_dbmoved

matreshkin
  • 2,199
  • 18
  • 28