2017-09-28 20 views
0

我想學習使用反應母語-sqlite的存儲,因爲這頁這裏描述:基本陣營本地SQLite的腳本返回undefined這會導致錯誤

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

我在Windows工作試圖建立一個Android應用程序的機器。我有以下代碼:

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; 

當我運行它,我得到的錯誤

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

的錯誤就行發生var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);

我懷疑錯誤發生的原因因爲SQLite在實際打開數據庫之前需要存在一個數據庫。但是,我沒有在上面的鏈接中看到有關如何使用react-native-sqlite-storage創建數據庫的任何說明,所以我不確定我的假設是否正確。此外,我假設我需要爲員工製作一張表格,但上面的鏈接並未明確說明如何創建一個表格。所以我不知道我的假設是否正確。

那麼如何讓SQLite.openDatabase()命令工作?

更多信息

我刪除了我的項目。然後我試着再次重新安裝所有東西,這次緊跟安卓的sqlite存儲安裝說明,就像在onpor的github說明中提到的那樣(即修改gradle文件,更新MainApplication類等等)。一旦我做到了,從CLI運行該命令react-native run-android導致此生成錯誤:

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)

我試圖運行此命令作爲普通用戶和管理員,還是一樣的問題。

更多信息2

我刪除了我的項目。然後我爲我所有的項目做了npm install。然後我嘗試的命令rnpm linkreact-native link react-native-sqlite-storage,這兩者給這個錯誤:

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

所以現在的項目甚至不會建立。有任何想法嗎?

+0

從錯誤中,這看起來更像是與模塊正在方式有問題導入,而不是函數被成功調用,隨後出現異常。也就是說,我懷疑穆罕默德是否有權利。 –

+1

因此,'lstat'是獲取符號鏈接元數據的請求。 Windows沒有正確的符號鏈接,所以我並不感到驚訝,這失敗了。你有沒有合適的UNIX工作箱? –

+1

(您也可能會報告Windows可移植性錯誤,無論哪個產品提供運行'lstat'的生成過程代碼)。 –

回答

0

問題是庫沒有鏈接 鏈接他們建議兩種方式

  • 與吊艙(高級)
  • rnpm link(容易),但這個命令已經廢棄

所以鏈接庫你應該使用

react-native link react-native-sqlite-storage

此命令等於rnpm link但不會被棄用

如果自動構建失敗,手動連接嘗試針對iOS manually linking ios和Android manually linking android

+0

感謝Mohamed,我運行了react-native鏈接'react-native-sqlite-storage'命令並得到了這個錯誤:'rnpm-install ERR!鏈接時出錯。錯誤:產生UNKNOWN'。我試圖通過谷歌尋找這個問題,並看到它是一個普遍的問題。還沒有人評論過這個問題發生在sqlite存儲上。有任何想法嗎? – John

+0

我還爲我的問題添加了更多信息,因爲我只是試圖重置並重新構建項目。 – John

+0

你使用的是Windows嗎? –