从应用程序浏览器链接回来时没有发现表:PhoneGap的 [英] table not found when coming back from in app browser link: Phonegap

查看:330
本文介绍了从应用程序浏览器链接回来时没有发现表:PhoneGap的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发Android手机隙的应用程序,数据库保存在文件夹中的资产.db扩展,在应用程序的Java文件我没有复制数据库,以我的应用程序的数据库(code是如下图),现在假设我有两个按钮(一个开放的外部链接等是开放的数据库,并从数据库中读取数据)。在应用启动时,我点击从数据库按钮其成功获取数据充分执行查询,现在当我从我的应用程序的开放在inappbrowser链接点击按钮,打开应用程式内浏览器链接,现在我点击后退按钮,我们是我们的应用程序页面现在如果我点击按钮,从数据库获取数据的发送错误SqliteDatabaseCpp(28065):sqlite的返回:错误code = 1,味精=没有这样的表:tblProduct

所以请任何一个可以建议我在哪里,我错了,我的code来复制数据库,并执行查询是如下:

的Java code来复制数据到数据库:

 公共无效的onCreate(捆绑savedInstanceState){
    尝试{
    this.copy(Databases.db,/数据/数据​​/+ PNAME +/ app_database /);
    this.copy(0000000000000001.db,/数据/数据​​/+ PNAME
            +/ app_database / file__0 /);
    super.onCreate(savedInstanceState);    super.loadUrl(
            文件:///android_asset/www/index.html
            2000年);
    super.appView.setVerticalScrollBarEnabled(真);
    super.appView.setHorizo​​ntalScrollBarEnabled(假);
    super.appView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);}赶上(IOException异常五){
    e.printStackTrace();
}
} //复制粘贴类中的这个功能,你上面部分使用
无效副本(字符串的文件,文件夹的字符串)抛出IOExceptionLog.d(GRT,我们是在数据库的副本);
文件CheckDirectory;
CheckDirectory =新的文件(文件夹);
如果(!CheckDirectory.exists()){
    Log.d(GRT,分贝分贝创建副本);
    CheckDirectory.mkdir();
}其他{
    Log.d(GRT,DATABSE已经存在);
}InputStream的时间= getApplicationContext()getAssets()打开(文件)。;
出的OutputStream =新的FileOutputStream(文件夹+文件);//传输的字节从到了
字节[] buf中=新的字节[1024];
INT LEN;
而((LEN = in.read(BUF))大于0)
    out.write(BUF,0,LEN);
附寄();
out.close();}

HTML按钮(一个用于打开inappbrowser等是数据库查询):

 <数据角色=按钮的onclick =openInapp()>开放的应用程式内浏览器< / A>

 <数据角色=按钮的onclick =queryRecommded()>查看推荐产品< / A>

相应的.js文件code是:

 函数onDeviceReady()
 {   变种DB = window.openDatabase(数据库,1.0,GRTDB,3000000);   db.transaction(queryRecommondedProduct,errorCB2,successCB);
  }  功能queryRecommondedProduct(TX){
    的console.log(TX+ TX)
    尝试{
        //警报(SQL会立即运行);
       VAR progressHud = window.plugins.waitingDialog;
       progressHud.show(加载...请稍候);
       tx.executeSql(选择aa.ProductID,aa.ProductName,aa.Price,aa.Description,aa.Specification,aa.VideoLink,ab.GalleryID,ab.Location,ab.ImageName,ab.LocalFolder,aa.Buy_Now从tblProduct AA内的aa.ProductId = ab.ProductId,其中aa.ProductId =加入tblGallery AB(从tblQuery那里AnswerQ1 ='+联排别墅+'AND AnswerQ2 ='+小+,然后选择RecomProdId AnswerQ3 ='+几个+'AND AnswerQ4 ='+中型+'AND AnswerQ5 ='+每月的+'AND请将isDeleted ='0'ORDER BY ProductAnswerId ASC LIMIT 1) aa.IsDeleted ='0'和ab.IsDeleted ='0'和ab.IsDownLoad ='1',[],功能(德克萨斯州,结果){queryRecommdedSuccess(德克萨斯州,结果,isReccom)},errorCB4);    }
    赶上(E){警报(测试+ E);}
}
 功能queryRecommdedSuccess(德克萨斯州,结果,rflag){    的console.log(第二步+ result.rows.length)
  //警报(第二步 - + result.rows.length);
    如果(result.rows.length大于0){
    }
    }功能errorCB2(ERR){
    警报(误差2是:: ---+ ERR code);
}
功能successCB(){
}
 功能** ** queryRecommded()
 {   document.addEventListener(deviceready,onDeviceReady,FALSE);
 } 功能openInapp(){  iabRef = window.open('http://apache.org','_blank','位置= YES');
  iabRef.addEventListener('loadstart',iabLoadStart);
  iabRef.addEventListener('loadstop',iabLoadStop);
  iabRef.removeEventListener('loaderror',iabLoadError);
  iabRef.addEventListener(退出,iabClos​​e);
 }


解决方案

我的问题在目标使用 _system 解决值。


  

window.open(网址 目标 选项);



  • 网址:要加载的URL(字符串)。就此事致电EN codeURI()如果你在你的网址有统一code字符。

  • 目标:的目标加载(字符串)的URL(可选,默认:_self)

  • 选项:作为InAppBrowser(字符串)选项(可选,默认:位置= YES)

目标值:

否则在InAppBrowser如果打开URL在白名单中的WebView科尔多瓦打开, -

  _self
_blank - 总是在InAppBrowser开放
_system - 总是在系统浏览器中打开

I am developing a phone-gap application for android, save database with .db extension in assets folder , on java file of application i did copy database to my application database (code is below), now suppose i have two buttons (one for open external link and other is for open database and fetching data from db) . upon launching of application when i click for fetching data from db button its success full and execute the query , and now when i click on button for open inapp browser link from my app its open the link in inappbrowser and now i click back button and we are our application page now if i click on button for fetching the data from database its sending error "SqliteDatabaseCpp(28065): sqlite returned: error code = 1, msg = no such table: tblProduct "

so pls any one could suggest me where i am wrong , my code for copy database and execute query are below:

Java code for copy data to database:

public void onCreate(Bundle savedInstanceState) {
    try {
    this.copy("Databases.db", "/data/data/" + pName + "/app_database/");
    this.copy("0000000000000001.db", "/data/data/" + pName
            + "/app_database/file__0/");
    super.onCreate(savedInstanceState);

    super.loadUrl(
            "file:///android_asset/www/index.html",
            2000);
    super.appView.setVerticalScrollBarEnabled(true);
    super.appView.setHorizontalScrollBarEnabled(false);
    super.appView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

} catch (IOException e) {
    e.printStackTrace();
}
}

 // Copy Paste this function in the class where you used above part
void copy(String file, String folder) throws IOException {

Log.d("GRT", "We are in the copy of db");
File CheckDirectory;
CheckDirectory = new File(folder);
if (!CheckDirectory.exists()) {
    Log.d("GRT", "Creating copy of db db");
    CheckDirectory.mkdir();
} else {
    Log.d("GRT", "Databse already exists");
}

InputStream in = getApplicationContext().getAssets().open(file);
OutputStream out = new FileOutputStream(folder + file);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
    out.write(buf, 0, len);
in.close();
out.close();

}

HTML buttons(one for open inappbrowser and other is query for database):

 <a data-role="button" onclick="openInapp()">open inapp browser</a>

 <a  data-role="button" onclick="queryRecommded()">View Recommended Product</a>

corresponding .js file code is :

function onDeviceReady()
 {

   var db = window.openDatabase("Database", "1.0", "GRTDB", 3000000);

   db.transaction(queryRecommondedProduct, errorCB2, successCB);


  }

  function queryRecommondedProduct(tx){
    console.log("tx"+tx)
    try{
        //alert("SQL gonna run now");
       var progressHud =window.plugins.waitingDialog;
       progressHud.show("Loading...Please wait");
       tx.executeSql("Select aa.ProductID,aa.ProductName,aa.Price,aa.Description,aa.Specification,aa.VideoLink,ab.GalleryID,ab.Location,ab.ImageName,ab.LocalFolder,aa.Buy_Now from tblProduct aa inner join tblGallery ab on aa.ProductId=ab.ProductId where aa.ProductId=(select RecomProdId  from tblQuery where AnswerQ1='"+"townhouse"+"' AND  AnswerQ2='"+"small"+"' AND AnswerQ3='"+"several"+"' AND AnswerQ4='"+"medium duty"+"' AND AnswerQ5='"+"monthly"+"' AND IsDeleted='0' ORDER BY ProductAnswerId ASC LIMIT 1  ) and aa.IsDeleted ='0' and ab.IsDeleted ='0' and ab.IsDownLoad ='1'", [],function(tx,result){queryRecommdedSuccess(tx,result,"isReccom")}, errorCB4);   

    }
    catch(e){alert("test"+e);}
}
 function queryRecommdedSuccess(tx,result,rflag){

    console.log("Step2"+result.rows.length)
  // alert("Step2 - "+result.rows.length);
    if(result.rows.length>0){


    }
    }

function errorCB2(err){
    alert("Error2 is::--- "+err.code);
}


function successCB(){
}
 function **queryRecommded**()
 {

   document.addEventListener("deviceready", onDeviceReady, false);
 }

 function openInapp(){

  iabRef = window.open('http://apache.org', '_blank', 'location=yes');
  iabRef.addEventListener('loadstart', iabLoadStart);
  iabRef.addEventListener('loadstop', iabLoadStop);
  iabRef.removeEventListener('loaderror', iabLoadError);
  iabRef.addEventListener('exit', iabClose);
 }

解决方案

my problem solved by using _system at the target value.

window.open(url, target, options);

  • url: the URL to load (String). Call encodeURI() on this if you have Unicode characters in your URL.
  • target: the target to load the URL in (String) (Optional, Default: "_self")
  • options: options for the InAppBrowser (String) (Optional, Default: "location=yes")

target values:

_self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser
_blank - always open in the InAppBrowser
_system - always open in the system web browser

这篇关于从应用程序浏览器链接回来时没有发现表:PhoneGap的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆