我有一个JSONStore用于客户列表,用户可以使用该应用程序向这些客户添加文档。
cusotmer及其数据列表(也包括附件)必须与后端同步。
当我将一个ppt文档774KB(这是二进制的大小,我将其转换为base64)添加到json存储并执行push()时,它失败并显示错误:
E/CursorWindow(32705): need to grow: mSize = 1048576, size = 1056310, freeSpace() = 1048464, numRows = 1
E/CursorWindow(32705): Attempting to grow window beyond max size (1048576)
E/Cursor(32705): Failed allocating 1056310 bytes for text/blob at 0,1
D/Cursor(32705): finish_program_and_get_row_count row 0
E/CursorWindow(32705): need to grow: mSize = 1048576, size = 1056310, freeSpace() = 1048464, numRows = 1
E/CursorWindow(32705): Attempting to grow window beyond max size (1048576)
E/Cursor(32705): Failed allocating 1056310 bytes for text/blob at 0,1
D/Cursor(32705): finish_program_and_get_row_count row 0
E/CursorWindow(32705): Bad request for field slot 0,0. numRows = 0, numColumns = 4
E/jsonstore-core(32705): error while dispatching action "allDirty"
E/jsonstore-core(32705): java.lang.IllegalStateException: get field slot from row 0 col 0 failed
E/jsonstore-core(32705): at net.sqlcipher.CursorWindow.getLong_native(Native Method)
E/jsonstore-core(32705): at net.sqlcipher.CursorWindow.getLong(CursorWindow.java:381)
E/jsonstore-core(32705): at net.sqlcipher.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:110)
E/jsonstore-core(32705): at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:195)
E/jsonstore-core(32705): at net.sqlcipher.AbstractCursor.moveToNext(AbstractCursor.java:257)
E/jsonstore-core(32705): at android.database.CursorWrapper.moveToNext(CursorWrapper.java:166)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher$AllDirtyAction.performAction(AllDirtyActionDispatcher.java:148)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher$AllDirtyAction.performAction(AllDirtyActionDispatcher.java:119)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.DatabaseActionDispatcher$Context.performReadableDatabaseAction(DatabaseActionDispatcher.java:141)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.AllDirtyActionDispatcher.dispatch(AllDirtyActionDispatcher.java:64)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.DatabaseActionDispatcher.dispatch(DatabaseActionDispatcher.java:56)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.BaseActionDispatcher.dispatch(BaseActionDispatcher.java:87)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.DispatchingPlugin$ActionDispatcherRunnable.run(DispatchingPlugin.java:113)
E/jsonstore-core(32705): at com.worklight.androidgap.plugin.storage.DispatchingPlugin$SerialExecutor$1.run(DispatchingPlugin.java:147)
E/jsonstore-core(32705): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/jsonstore-core(32705): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/jsonstore-core(32705): at java.lang.Thread.run(Thread.java:856)
E/myApp (32705): [wl.jsonstore] {"src":"push","err":8,"msg":"FAILED_TO_GET_UNPUSHED_DOCUMENTS_FROM_DB","col":"Documentos","usr":"jsonstore","doc":{},"res":{}}
我可以添加文档,错误是执行push()方法。
我在stackoverflow和infocenter中看到的关于JSONStore的所有信息都是没有大小限制。我的手机里有足够的可用空间。
有什么想法吗?
谢谢。
答案 0 :(得分:3)
“不要在数据库中存储blob [...]。将标识符存储在数据库中,并将blob作为文件放到存储上。” - Source
Cordova有File API你可以使用。
这是一个简单的例子:
//Code to write customer-1-file1.ppt and customer-1-file2.ppt to disk.
//See Cordova's File API.
//Pseudocode to get the blobsCollection and add metadata to be able to find the files.
//This would be inside the success callback for writing the files.
WL.JSONStore.get('blobsCollection')
.add([{fileName: 'customer-1-file1.ppt'}, {fileName: 'customer-1-file2.ppt'}]);
//Some time has passed...
//Pseudocode to get %customer-1% from disk
//% are wildcards characters and match any string
WL.JSONStore.get('blobsCollection')
.find({fileName: 'customer-1'}, {exact: false})
.then(function (listOfFiles) {
//listOfFiles => [{_id: 1, json: { fileName: 'customer-1-file1.ppt'} },
// {_id: 2, json: { {fileName: 'customer-1-file2.ppt'} }]
var firstFile = listOfFiles[0].json.fileName;
//Code to read firstFile. See Cordova's File API.
});
JSONStore由SQLite支持(技术上SQLCipher,它是添加数据加密的SQLite的包装器)。阅读Internal Versus External BLOBs in SQLite。外卖是“对于小于100KB的BLOB,当BLOB直接存储在数据库文件中时读取速度更快。对于大于100KB的BLOB,从单独的文件读取更快”。< / em>的
如果你需要存储大于默认SQLite游标大小(1048576字节)的blob,我建议feature request here。
我会确保在文档中提到这一点。
请注意,您可以使用getPushRequired API来获取push
API尝试发送到Worklight Adapter的文档列表。您需要使用WL.Client.invokeProcedure
自行将文件更改发送到Worklight Adapter,或使用jQuery.ajax
之类的内容直接发送到后端。