Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First item to insert into the mobile database isn't added

I'm using JayData in a Telerik Platform mobile application. The good people at JayData worked up this example of what I was looking to do:

http://jsfiddle.net/JayData/zLV7L/

 var savefeedIfNotExists = function (feed) {
            //create jQuery promise
            console.log("create deferred for " + feed.FeedID)

            var def = new $.Deferred();

            //async thread 
            pnrDB.PNRFeeds.filter('it.FeedId == ' + feed.FeedID).count(function (count) {

                console.log("Add Feed - " + feed.FeedName);

                if (count == 0) {
                    var f = new PNRFeed({
                        FeedId: feed.FeedID,
                        FeedName: feed.FeedName,
                        ImageName: feed.ImageName,
                        FeedActive: feed.IsActive,
                        OrderNumber: parseInt(feed.OrderNumber) + 1
                    })

                    pnrDB.PNRFeeds.add(f);

                    console.log("Resolve for - " + feed.FeedName);
                    //promise.resolve() indicates that all async operations have finished
                    //we add the ADD/SKIP debug info to the promise
                    def.resolve("ADD");

                    console.log("Resolved - " + feed.FeedName);
                } else {
                    //console.log('feed id not 0 - ' + f.FeedId);
                    def.resolve("SKIP");
                }
            });
            //return promise in order to wait for the async result of local database query
            return def.promise();
        };

I've added to this code however and when I run it also using their Kendo.js module for JayData (different than the kendo.js from kendo), it seems to interrupt the script when the first promise is created in the loop function. This only happens the FIRST time the script is run - if you were to refresh to do a reload, it then runs correctly and the first item DOES get inserted.

enter image description here

On the second load it seems to work just fine with no call into their JayData module for Kendo:

enter image description here

So even though it appears as though it's going to add the first item (ID 19), that item never gets added to the database. When you reload the same exact script however, it gets tagged as add again and isn't interrupted, so it finally gets into the database.

Anyone have any thoughts or things to try?

like image 365
2GDave Avatar asked Aug 20 '14 13:08

2GDave


People also ask

How to insert data into the Firebase Database in Android apps?

Carefully follow my steps to insert the data into the Firebase database in Android apps, using an Android Studio and I have included the source code given below. Open an Android Studio and start the new project. Put the Application name and the company domain.

Why can't I programmatically add a new record to a table?

When you try to programmatically add a new record to a table by using the NotInList event of the combo box on a form, you might receive the following error message: The text you entered isn't an item in the list. Select an item from the list, or type the text that matches one of the listed items.

Why is my phone number not showing up in the database?

It looks like you got your database schema wrong. Ensure column you put your phone number data into is rather of string type (i.e. VARCHAR ), and not numeric (not INTEGER, BIGINT, DECIMAL etc) Not the answer you're looking for? Browse other questions tagged php html mysql sql or ask your own question.

How do I create an AutoNumber table in access?

Start Microsoft Access. Create a new Db1.mdb database. In the Database window, click Tables under Objects. In the right pane, double-click Create table in Design view. In the first row of the Field Name column, typeID, and then set the corresponding Data Type to AutoNumber.


Video Answer


1 Answers

if you are using html5 then you can use webSQL to perform data operations,it provides all functions like select,insert,update on data The Web SQL specification defines an API for storing data in databases that can be queried using a variant of SQL.

you can use like following function I have used it in my Intel XDK mobile app

if you are using html5 then you can use webSQL to perform data operations,it provides all functions like select,insert,update on data 

> The Web SQL specification defines an API for storing data in databases
> that can be queried using a variant of SQL. you can use like following
> function

<!-- begin snippet: js hide: false -->
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function insert(){
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
 var nam = document.getElementById("Tname").value;
 var id = document.getElementById("Tid").value;
 var name2 = "velocity";
  tx.executeSql('CREATE TABLE IF NOT EXISTS APP (id unique, log)');
  tx.executeSql('INSERT INTO APP (id, log) VALUES (?,?)',[id,nam]);
  //tx.executeSql('INSERT INTO LOGS (id, log) VALUES (61,'+name2+')');
  msg = '<p>Log message created and row inserted.</p>';
  document.querySelector('#status').innerHTML =  msg;
});
}
function readdata(){
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
var id = document.getElementById("Tid").value;
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM APP', [], function (tx, results) {
  console.log("All rows:");
   var len = results.rows.length, i;
   msg = "<p>Found rows: " + len + "</p>";
   document.querySelector('#status').innerHTML +=  msg;
   for (i = 0; i < len; i++){
     msg = "<p><b>Name :-" + results.rows.item(i).log +"<br/>Contact :-" +results.rows.item(i).id + "</b></p>";
     msg = "<p><b>Name :-" + results.rows.item(i).log +"<br/>Contact :-" +results.rows.item(i).id + "</b></p>";
	 //var row = result.rows.item(i);
     //msg = console.log("  " + row.contact + " " + row.nam);
	 document.querySelector('#status').innerHTML +=  msg;
   }
 }, null);
});
}
function ByContact(){
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
var con = document.getElementById("Con").value;
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM APP WHERE (id LIKE ?);',[con], function (tx, results) {
  console.log("All rows:");
   var len = results.rows.length, i;
   msg = "<p>Found rows: " + len + "</p>";
   document.querySelector('#status').innerHTML +=  msg;
   for (i = 0; i < len; i++){
     msg = "<p><b>Name :-" + results.rows.item(i).log +"<br/>Contact :-" +results.rows.item(i).id + "</b></p>";
     msg = "<p><b>Name :-" + results.rows.item(i).log +"<br/>Contact :-" +results.rows.item(i).id + "</b></p>";
	 //var row = result.rows.item(i);
     //msg = console.log("  " + row.contact + " " + row.nam);
	 document.querySelector('#status').innerHTML +=  msg;
   }
 }, null);
});
}

</script>
</head>
<body style="background-image:url('f.jpg');background-repeat:no-repeat;">
<h1 align="center"><font color="white">Contact Form</font></h1>
    <div  style="color:white">
<table align="center">
<tr>
<td>contact no</td>
<td><input type="text" id="Tid"/></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" id="Tname"/></td>
</tr>
<tr>
<td>
<button id="add" onclick="return insert();">Insert</button>
</td>
<td>
<button onclick="return readdata();" id="read">readdata</button>
</td>
<td>
</td>
</tr>
</table>
<table>
<tr>
    <td>
    <button onclick="return ByContact();" id="GetByContact">GetByContact</button>
    </td>
    <td>
    <input type="text" id="Con"/>
    </td>
</tr>

        </table>
        <div id="status" name="status"><font color="white">Your Data Will Show Here</font></div>
</div>       

    </body>
</html>

you can get more information from https://github.com/ccoenraets/backbone-directory/tree/master/localdb http://www.tutorialspoint.com/html5/html5_web_sql.htm

like image 192
Hardik Vyas Avatar answered Oct 08 '22 10:10

Hardik Vyas