Langsung ke konten utama

Postingan

Menampilkan postingan dari Juni, 2015

How to Round Up and Round Down Numbers In AX

To round number in AX, we can use 2 method. If we wanna round up, we can use  RoundUp(real value, real unit)  function and we can use  RoundDown(real value, real unit)  function if we wanna round down numbers. For example, we can see the source code of a job below : static void Rounding(Args _args) {     real    temp, roundingUp, roundingDown;     ;     temp = 3000 / 7;     roundingUp = roundUp(temp, 1);     roundingDown = roundDown(temp, 1);     info(strFmt("Origin : %1 RoundingUp : %2 RoundingDown : %3", temp, RoundingUp, roundingDown)); } The result is like a picture below :

Delete indexeddb data by index

var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" };; var db; var transaction, objectStore; var request = indexedDB.open("IndexedDBname", 1);         request.onsuccess = function (evt) {        db = request.result;  var deleteindex = db.transaction(["indexdbtable"], "readwrite") .objectStore("indexdbtable")                 .delete(1); // example if you want to delete index no 1 deleteindex.onsuccess = function(event) { console.log("index 1 deleted" + "indexdbtable");  // log };  };

Function to delete Indexeddb Object(table)

var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB; var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" };; var db; var transaction, objectStore; // "IndexDB" is your indexed db name (database) var request = indexedDB.open("IndexDB", 1);         request.onsuccess = function (evt) {         db = request.result; //"indexobject" is your indexdb object (table) transaction = db.transaction("indexobject", "readwrite"); objectStore = transaction.objectStore("indexobject");   // clear all the data out of the object store var objectStoreRequest = objectStore.clear(); objectStoreRequest.onsuccess = function(event) {     // report the success of our clear operation console.log('clear '+"indexobject"); }; };

IndexedDB Fuzzy Search

This is how to create  key range between the search term and the search term with a 'z' letter at the final. db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important part, thank Velmont to point out 'prev' ) . onsuccess = function ( e ) { e || ( e = event ); var cursor = e . target . result ; if ( cursor ) { // console.log(cursor.value.column1 + ' = ' + cursor.value.column2); cursor . continue (); } }; If you need to order the result, so I defined a array before the transaction, then we call it when we loaded all data, like this: var result = []; db . transaction ([ 'table' ], 'readonly' ) . objectStore ( 'table' ) . openCursor ( IDBKeyRange . bound ( searchTerm , searchTerm + '\uffff' ), // The important

Use HTML5 IndexedDB cursors to update existing records

The  HTML5   IndexedDB  is still in the working draft stage and not fully implemented in major Internet browsers yet. Nevertheless, I tried to use its asynchronous API to develop a  Google Maps  application. It took me a little while to figure out how to update an existing record in the IndexedDB  database store. This can be done by opening a read-write cursor to the record to be updated. Then call the cursor  update  method to replace it with the new record. An example Javascript code snippet is shown below. try { var objDb; //the database to update var store = 'myStore' ; //the database store to update var key = 88; //the key of the existing record to update var newRec = 'hello world' ; //the new record var objStore = null ; var objTrans = null ; var objCursor = null ; var objKeyRange = null ;   //...etc...open the database....etc... //open a read-write transaction objTrans = objDb.transaction(store,_IDBTransaction.READ_WRITE);