0

I'm trying to learn to use react-native-sqlite-storage as described on this page here:

https://github.com/andpor/react-native-sqlite-storage

I am working on a windows machine trying to build an android app. I have the following code:

import SQLite from 'react-native-sqlite-storage';

function errorCB(err) {
  console.log("SQL Error: " + err);
}

function successCB() {
  console.log("SQL executed fine");
}

function openCB() {
  console.log("Database OPENED");
}

var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.transaction((tx) => {
  tx.executeSql('SELECT * FROM Employees a, Departments b WHERE a.department = b.department_id', [], (tx, results) => {
      console.log("Query completed");

    });
});

export default 1;

When I run this, I get the error

undefined is not an object (evaluating 'NativeModules["SQLite"][method]')

The error is happening on the line var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);

I suspect the reason the error is happening is because SQLite expects the existence of a database before you can actually open it. However, I do not see any instructions in the link above on how to create a database with react-native-sqlite-storage, so I'm not sure if my assumption is correct. Additionally, I assume I'd need to have a table for Employees, but again, the link above didn't explicitly state examples on how to create one. SO I don't know if my assumption is correct.

So how do I get SQLite.openDatabase() command to work?

More information

I deleted my project. Then I tried to re-install everything again, this time closely following the installation instructions for sqlite storage for android as mentioned on the andpor's github instructions (ie, modifying gradle files, updating MainApplication class etc...). Once I did that, running the command react-native run-android from the CLI causes this build error:

ERROR EPERM: operation not permitted, lstat 'C:\Users\John Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar' {"errno":-4048,"code":"EPERM","syscall":"lstat","path":"C:\Users\John Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar"} Error: EPERM: operation not permitted, lstat 'C:\Users\John Lai\Projects\ReactNative\myapp\android\app\build\intermediates\exploded-aar\myapp\realm\unspecified\jars\classes.jar' at Error (native)

I tried running this command as a regular user and as an administrator, and still the same issue.

More Information 2

I deleted my project. Then I did npm install for all my projects. Then I tried the commands rnpm link and react-native link react-native-sqlite-storage, both of which gave this error:

ERR! It seems something went wrong while linking. Error: spawn UNKNOWN Please file an issue here: https://github.com/rnpm/rnpm/issues

So now the project won't even build. Any ideas?

6
  • From the error, this looks more like a problem with the way the module is being imported, rather than the function being successfully invoked and misbehaving subsequently. Which is to say, I suspect Mohamed has the right of it. Commented Sep 29, 2017 at 0:53
  • 1
    So, lstat is a request to get metadata for a symlink. Windows doesn't have proper symlinks, so I'm not surprised this fails. Do you have a proper UNIX box you can work on? Commented Sep 29, 2017 at 15:03
  • 1
    (You might also report a Windows portability bug to whichever product provided the build-process code running that lstat). Commented Sep 29, 2017 at 15:04
  • ah man, that's irritating....all my linux machines are headless since I use them mostly for web dev. Ok, i'll spend time to spin off an ubuntu or something... Commented Sep 29, 2017 at 16:14
  • are you sure that the error came from react-native-sqlite-storage not realm i can see realm in your path also you can use bash for windows instead of cmd Commented Sep 29, 2017 at 18:13

3 Answers 3

0

the problem is the library is not linked to link they suggest two ways

  • with pod (advanced)
  • with rnpm link (easy) but this command is deprecated

so to link the library you should use the

react-native link react-native-sqlite-storage

this command is equal to rnpm link but not deprecated

if automatic build failing try with manual linking for iOS manually linking ios and android manually linking android

Sign up to request clarification or add additional context in comments.

19 Comments

Thanks Mohamed, I ran the react-native link react-native-sqlite-storage command and got this error rnpm-install ERR! Something went wrong while linking. Error: spawn UNKNOWN . I tried looking through google for this issue and see it is a generic issue. And no one has yet commented on this issue happening to sqlite storage. Any ideas?
I also added more information to my question because I just tried to reset and re-build the project.
are you using windows?
when the link failed did you try manual linking i'll update my answer
and for android github.com/andpor/…
|
0

lstat command error is generating on windows due to permission issues or npm version issues.

You can do 2 things to pass this. 1.Open terminal in admin mode . 2.upgrade/degrade npm version

For plugin installation, configure manually

Comments

0

You need change MainApplication.java with:

import org.pgsqlite.SQLitePluginPackage;

and

in getPackages:

new SQLitePluginPackage()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.