我实现了我的previous question中提到的Phonegap插件。
我收到错误,因为查询中没有给出这样的表。其中有一个表名。
CODE
<script type="text/javascript" charset="utf=8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<script type="text/javascript" charset="utf-8" src="SQLitePlugin.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
var db = window.sqlitePlugin.openDatabase("abc.db", "1.0", "test", 20000);
db.transaction(function(tx)
{
tx.executeSql("SELECT column_name FROM table_name;", [], function(tx)
{
console.log("column_name length: " + column_name.length);
});
},
function(e)
{
console.log("ERROR: " + e.message);
});
}
</script>
**Error and Warnings**
04-12 18:11:58.271: D/dalvikvm(400): VFY: dead code 0x0047-0067 in Lcom/phonegap/plugin/sqlitePlugin/SQLitePlugin;.results2string (Landroid/database/Cursor;)Ljava/lang/String;
04-12 18:11:58.281: V/info(400): Open sqlite db: /data/data/com.a.android.b/databases/abc.db.db
04-12 18:11:58.351: D/CordovaLog(400): SQLitePluginTransaction - this.trans_id:1365770518342000
04-12 18:11:58.351: I/Web Console(400): SQLitePluginTransaction - this.trans_id:1365770518342000 at file:///android_asset/www/SQLitePlugin.js:83
04-12 18:11:58.351: D/CordovaLog(400): SQLitePluginTransaction.prototype.executeSql
04-12 18:11:58.362: I/Web Console(400): SQLitePluginTransaction.prototype.executeSql at file:///android_asset/www/SQLitePlugin.js:164
04-12 18:11:58.362: D/CordovaLog(400): success not null:SELECT column_name FROM table_name;
04-12 18:11:58.362: I/Web Console(400): success not null:SELECT type FROM tpl_category; at file:///android_asset/www/SQLitePlugin.js:171
04-12 18:11:58.362: D/CordovaLog(400): executeSql - add_to_transactionSELECT column_name FROM table_name;
04-12 18:11:58.362: I/Web Console(400): executeSql - add_to_transactionSELECT column_name FROM table_name; at file:///android_asset/www/SQLitePlugin.js:199
04-12 18:11:58.383: D/CordovaLog(400): SQLitePluginTransaction.prototype.complete
04-12 18:11:58.383: I/Web Console(400): SQLitePluginTransaction.prototype.complete at file:///android_asset/www/SQLitePlugin.js:204
04-12 18:11:58.391: I/Database(400): sqlite returned: error code = 1, msg = no such table: tpl_category
04-12 18:11:58.391: W/System.err(400): android.database.sqlite.SQLiteException: no such table: table_name: , while compiling: SELECT column_name FROM table_name;
04-12 18:11:58.391: W/System.err(400): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-12 18:11:58.391: W/System.err(400): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
04-12 18:11:58.391: W/System.err(400): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
04-12 18:11:58.391: W/System.err(400): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
04-12 18:11:58.401: W/System.err(400): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
04-12 18:11:58.401: W/System.err(400): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
04-12 18:11:58.401: W/System.err(400): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
04-12 18:11:58.401: W/System.err(400): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
04-12 18:11:58.401: W/System.err(400): at com.phonegap.plugin.sqlitePlugin.SQLitePlugin.executeSqlBatch(SQLitePlugin.java:263)
04-12 18:11:58.401: W/System.err(400): at com.phonegap.plugin.sqlitePlugin.SQLitePlugin.execute(SQLitePlugin.java:109)
04-12 18:11:58.401: W/System.err(400): at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)
04-12 18:11:58.401: W/System.err(400): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:220)
04-12 18:11:58.401: W/System.err(400): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:44)
04-12 18:11:58.401: W/System.err(400): at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:221)
04-12 18:11:58.401: W/System.err(400): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
04-12 18:11:58.401: W/System.err(400): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 18:11:58.401: W/System.err(400): at android.os.Looper.loop(Looper.java:123)
04-12 18:11:58.412: W/System.err(400): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-12 18:11:58.412: W/System.err(400): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 18:11:58.412: W/System.err(400): at java.lang.reflect.Method.invoke(Method.java:521)
04-12 18:11:58.412: W/System.err(400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-12 18:11:58.412: W/System.err(400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-12 18:11:58.412: W/System.err(400): at dalvik.system.NativeStart.main(Native Method)
04-12 18:11:58.412: V/executeSqlBatch(400): SQLitePlugin.executeSql(): Error=no such table: table_name: , while compiling: SELECT column_name FROM table_name;
04-12 18:11:58.412: V/executeSqlBatch(400): 1365770518342000
04-12 18:11:58.432: D/CordovaLog(400): SQLitePluginTransaction.txErrorCallback---transId:1365770518342000
04-12 18:11:58.432: I/Web Console(400): SQLitePluginTransaction.txErrorCallback---transId:1365770518342000 at file:///android_asset/www/SQLitePlugin.js:132
04-12 18:11:58.444: D/CordovaLog(400): ERROR: undefined
04-12 18:11:58.444: I/Web Console(400): ERROR: undefined at file:///android_asset/www/view all.html:27
我是否错过了任何初始化或声明?
答案 0 :(得分:1)
我找到了这篇文章的答案。但这让我陷入了一个新问题。
我做出的假设......
我把.sqlite放在assets / www文件夹中。所以我假设eclipse正在打开那个特定的sqlite文件夹。
<强>代码:强>
var db = window.sqlitePlugin.openDatabase("abc.db", "1.0", "test", 20000);
数据库的形成是abc.db.db.这是我的另一个错误。所以,当我通过命令命令访问表时
tx.executeSql("SELECT column_name FROM table_name;", [], function(tx)
{
console.log("column_name length: " + column_name.length);
});
},
function(e)
{
console.log("ERROR: " + e.message);
});
它显示错误,因为没有这样的table_name。
实际上,它创建了一个新的.DB文件(根据我的代码),它没有这样的内容。
这完全是我的错误。
但是,这让我进一步思考如何让eclipse访问我的.sqlite文件,将它集成到我的Phonegap应用程序中?
任何建议和解决方案请让我知道..
答案 1 :(得分:1)
我认为Cordova 2.6中存在一个错误,我今天刚刚从2.5升级而且我的所有sqlite代码似乎都已破坏,但我确实做了一些其他更改。我一直得到同样的错误但是90%肯定它的cordova相关。
04-17 02:21:08.722:E / Web Console(1698):“没有这样的表:api(代码1):,编译时:SELECT * FROM api WHERE md5 =?LIMIT 1”at file:/ //android_asset/www/js/app.js:9249
但是当我创建数据库和表时我没有遇到任何错误。我可以使用文件资源管理器直接在eclipse中浏览数据库,并且看到不仅数据库存在,而且表也在那里。
我报告我发现的任何解决方案。
编辑:我回到了cordova 2.5,现在一切似乎都在为我工作。在跟踪问题之前,这可能会作为临时修复。答案 2 :(得分:1)
选中此项并按照此its working!
进行操作拥有 2.1.0版本的手机屏幕 android OF 2.2 Jquery OF 1.8.2min (如果你使用的话)我没有使用Jquery。
我与最近版本的PHONEGAP 2.5.0 ,ANDROID 4.1.2 &amp;新的SQLITE插件更新了7个月......它没有工作....
几乎在4-5天之后我找到了解决方案!!
YIPEE !!
答案 3 :(得分:0)