我实现了之前问题中提到的 Phonegap 插件。
我收到一个错误,因为查询中没有给出这样的表。而该名称中有一个表。
代码
<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
我错过了任何初始化或声明吗?