简体   繁体   English

iOS数据库应用程序(phonegap)-在模拟器上运行,但在设备上不运行

[英]IOS database app(phonegap)- working on simulator but not working on device

I build an iphone app using phonegap. 我使用phonegap构建了一个iPhone应用程序。 I am using sqlite3 db to store the data locally. 我正在使用sqlite3 db在本地存储数据。 The app is working perfectly on simulator but gives error on actual ios device. 该应用程序可以在模拟器上完美运行,但在实际的ios设备上会出现错误。 It is throwing " Could not prepare statement (1 no such table: table_name) " error code for the same is Code=5. 它抛出“ Could not prepare statement (1 no such table: table_name) ”的错误代码,同样是Code = 5。

Do i have to install sqlite plugin on ios device? 我必须在iOS设备上安装sqlite插件吗? The app is in a testing stage. 该应用程序处于测试阶段。 I followed steps provided in this , to install the app on ios device. 我也跟着在提供的步骤 ,安装iOS设备上的应用程序。

What am I missing here? 我在这里想念什么?

Update: This is the piece of code I'am using. 更新:这是我正在使用的代码。 My db resides at location 我的数据库位于该位置

/Users/imac/Library/Application Support/iPhone Simulator/7.0.3/Applications/4C7CC11A-8938-479F-B810-86121D3311B7/Library/WebKit/Local Storage/File_0 / Users / imac / Library / Application Support / iPhone Simulator / 7.0.3 / Applications / 4C7CC11A-8938-479F-B810-86121D3311B7 / Library / WebKit / Local Storage / File_0

And on the device it resides at 在设备上,它位于

AppData/Library/WebKit/Local Storage/File_0 AppData /库/ WebKit /本地存储/文件_0

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>


        <title>Books | Categories</title>

        <link href="css/bootstrap.css" rel="stylesheet" type="text/css">
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" charset="utf-8" src="js/jquery.min.js"></script>
        <script type="text/javascript" charset="utf-8">

          var db;
          var shortName = 'Books';
          var version = '1.0';
          var displayName = 'BooksDB';
          var maxSize = 200000;
          function errorHandler(transaction, error) {
          alert('Error: ' + error.message + ' code: ' + error.code);
          }

          function successCallBack() {
              alert("DEBUGGING: success");

          }

          function nullHandler(){
              alert('null handler');
          };

          function onBodyLoad(){

              if (!window.openDatabase) {
                  alert('Databases are not supported in this browser.');
                  return;
              }
              db = window.openDatabase(shortName, version, displayName, maxSize);
              alert('db open');
              ListDBValues();
          }

          function ListDBValues() {
            var ArrayAlphabet=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
            $('.container').empty();

            for (var i = 0; i < ArrayAlphabet.length; i++) {

            data='<div class="order" id="'+ArrayAlphabet[i]+'"></div>';

            load_books(ArrayAlphabet[i]);
            $('.container').append(data);
            data="";
            }
            return;
         }

          function load_books(bookTitleAlphabet)
          {

              if (!window.openDatabase) {
                  alert('Databases are not supported in this browser.');
                  return;
              }

            db.transaction(function(transaction) {
            transaction.executeSql('SELECT * FROM books where book_title like "'+bookTitleAlphabet+'%" order by book_title desc;', [],
            function(transaction, result) {if (result != null && result.rows != null) {
            $('#'+bookTitleAlphabet).html(bookTitleAlphabet);

            for (var i = 0; i < result.rows.length; i++) {
            var data;
            var row = result.rows.item(i);
            data="<a href='details.html?id="+row.book_id+"'> <div class='book'>";        
            data +="<div class='book_img'><img src="+row.book_thumb_location+"></div>";          
            data +="<div class='book_detail'>";
            data +="<div class='title'>"+row.book_title+"</div>";
            data +="<div class='author'>"+row.book_author+"</div>";
            data +="</div>";
            data +="<div class='clear'>";
            data +="</div>";
            data +="</div>";
            data +="</a>";       
            var tempId='#'+bookTitleAlphabet;    
            $(tempId).append(data);

            tempId="";

            }}
            if (result.rows.length==0)
            {
            var tempId='#'+bookTitleAlphabet;

            $(tempId).hide();
            }

            },errorHandler);},errorHandler,nullHandler);

            return;

        }
       </script>

</head>    
<body onload="onBodyLoad()">                 
  <div id="wrapper">            
    <div class="overflow_hide">
    </div>                         
    <div class="menu">                                 
      <div class="header">                    
        <div class="back">
          <a href="index.html">
            <input class="gobutton" type="button" value="Back" ></a>
        </div>                    
        <div class="list_book">BOOKS
        </div>                    
        <div class="settings">
          <a href="index.html">
            <input class="gobutton" type="button" value="Home" ></a>
        </div>                                   
      </div>                                 
      <div class="container">                                                                                
        <div class="clear">
        </div>                
      </div>                                                          
    </div>                         
    <div class="opac">                
      <a href="about.html">
        <div class="opac1">About Us
        </div></a>                               
      <a href="search.html">
        <div class="opac1">Search
        </div></a>                            
    </div>                         
    <div class="clear">
    </div>        
  </div>            
</body>
</html>

Is this because the app cannot find the db? 这是因为应用程序找不到数据库吗?

EDITED/NEW ANSWER: 编辑/新答案:
As the article here points out, you will likely have to do some work in XCode itself. 正如本文所指出的那样,您可能必须在XCode本身中做一些工作。 As you correctly noted, the pathing to the database is different for pre-populated versus runtime-created databases. 正如您正确指出的那样,预填充数据库和运行时创建的数据库的数据库路径是不同的。 In short, your modifications will look for the pre-populated database and move it to the expected location/folder when it is detected. 简而言之,您的修改将查找预填充的数据库,并在检测到该数据库时将其移动到预期的位置/文件夹。 The nice thing: this will happen before your code begins to execute (javascript) so your existing code won't be "aware" that this even happened. 妙处:这将在您的代码开始执行(javascript)之前发生,因此您现有的代码将不会“意识到”甚至发生这种情况。

It is worth noting that the post I am referring you to goes past this and excludes the item from backup to iCloud. 值得一提的是,我指给您的帖子已超出此范围,并且将该项目排除在备份到iCloud之外。 You will have to make a judgment call on whether you want to do that or not. 您将不得不做出是否要这样做的判断。 It is pre-populated does not mean you wish to NOT back up that database nor does it make the leap (as the author does) that the pre-populated database is likely "large". 预先填充的数据库并不意味着您不希望不备份该数据库,也不意味着(正如作者所做的那样)使预先填充的数据库可能“很大”。

OLD ANSWER: 旧答案:
The error does not seem to indicate that it is having difficulty with SQLite itself, but a problem with a specific table not existing. 该错误似乎并不表示它在使用SQLite本身时遇到困难,而是特定表不存在的问题。

This typically happens when you are testing (via simulator) and at some point hit the appropriate code that performs the CREATE statement for the table. 这通常在您进行测试(通过模拟器)并且在某些时候点击执行该表的CREATE语句的适当代码时发生。 Then, later on, you get accustomed to that table being there and accidentally disconnect the schema-checking or table-existance-checking code. 然后,以后,您习惯了该表在那里,并意外断开了模式检查或表存在性检查代码的连接。 Since the table exists already, your simulator continues on about and never tries to re-create that table. 由于该表已经存在,因此您的模拟器会继续运行,并且不会尝试重新创建该表。 When you go to run it on the actual device, however, that CREATE code never executes and falls into an area where you expect the table to exist - which causes the error. 但是,当您在实际设备上运行它时,该CREATE代码将永远不会执行,并且会落入您希望该表存在的区域中-这会导致错误。

Since you haven't posted any code, this is all conjecture on my part. 由于您尚未发布任何代码,因此这完全是我的猜测。 If you want me to take a look, I would be happy to. 如果您想让我看看,我将很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 phonegap iOS应用程序可在模拟器上运行,但不能在设备上运行。 如何调试 - phonegap iOS app working on simulator but not in device. How to debug iOS 应用程序链接在设备上不起作用,但在模拟器上打开应用程序 - iOS applink not working on the device but opens app on simulator Phonegap和iOS-示例在模拟器中不起作用 - Phonegap and ios - samples not working in simulator Tabbarcontroller在模拟器上工作而不在iOS设备上 - Tabbarcontroller is working in simulator not on iOS device ios:定时器在模拟器中工作但不在设备上工作 - ios: Timer working in simulator but not on device 无法从iPhone设备中的sqlite数据库获取数据,但可以在iOS Simulator中使用 - Data is not fetched from sqlite database in iphone device but working in iOS Simulator 应用程序在后台处理模拟器但不在设备上时更新位置(iOS 9) - Updating locations while app in background working on simulator but not on device (iOS 9) Expo 应用程序在 Expo Go 和 iOS 模拟器上工作,但在真实设备上崩溃 - Expo app working on Expo Go and iOS Simulator but crashes on real device iOS 通用应用程序链接在模拟器上工作,而不是在真实设备上 - iOS universal app links working on simulator, not on real device Flutter iOS 应用程序在模拟器中完美运行,但在真实设备中无法运行 - Flutter iOS app working perfect in simulator but not in real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM