Академический Документы
Профессиональный Документы
Культура Документы
July , 2018
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
OBJECTIVES
To store data into web storage (local storage or session storage)
To store data into Web SQL database
[1, 6]
WEB STORAGE
What is the web storage?
Web storage allows you to use JavaScript to set name/value pairs that you can
retrieve across multiple page reloads.
With HTML web storage, web apps can store data locally within the user's browser.
[1]
LOCAL STORAGE vs. SESSION STORAGE
Local Storage Session Storage
data is store in localStorage object data is stored in a window object
data is available to all windows or tabs data is discard when the window or tab
that are loaded from the same origin is closed
(i.e., same domain, protocol, and port)
data is saved even after the other windows/tabs are not aware of
window/tab is closed the values
2. grabs the values from the 3 form inputs using jQuery’s val()
function and save each in a local storage variable
CREATING [1]
DATABASE
To set up a
database
for storing the
submitted data,
put the below
codes
at the bottom
part
of ready()
function.
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15a
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
db is a global variable
which is used for
holding
a reference to the
database connection
once we’ve established
it
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15b
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15c
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15d
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
A string of your
database name that
will be presented in
the
interface to the user,
Ex: At Google Chrome’s
Developer Tools
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15e
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15f
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
calls openDatabase()
and stores the
connection in the db
variable.
If the database doesn’t
already exist, it will be
created.
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15g
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
CREATING [1]
DATABASE
calls the
transaction()
method of the db
object’to allow
transaction to the
database for executing
any database queries.
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 15h
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
Inserting one new row (of record) into a database involves these below steps:
1. overrides submit event of the #createEntry form:
Inserting one new row (of record) into a database involves these below steps:
2. creates a function called createEntry() to handle the transaction of inserting
a new entry (or row) to the database:
function createEntry(){
...
...
}
Inserting one new row (of record) into a database involves these below
steps:
4. executes SQL for inserting
The SQL statement that willone
be new entry with
executed the above
for inserting onedata
new from step
row to the3database.
The question marks are data placeholders.
Inserting one new row (of record) into a database involves these below steps:
5. handles action after successfully inserting (i.e., success in executing SQL)
Inserting one new row (of record) into a database involves these below steps:
6. handles errors incase of inserting failure (i.e., failure in executing SQL)
The error handler is passed two parameters:
the name of the function that will
the transaction object and the error object.
execute if the SQL query fails
Inserting one new row (of record) into a database involves these below steps:
6. handles errors incase of inserting failure (i.e., failure in executing SQL)
The error handler is passed two parameters:
the name of the function that will
the transaction object and the error object.
execute if the SQL query fails
[1]
Purpose
need to remove any other
<li>s before appending
rows from the database
over again and again.
Purpose
Select every rows from the
database table entries
where a field date is equal
to currentDate and order
those result sets by the field
food.
Purpose
The object result will
contain all result sets
from the query.
Purpose
The property length counts
total number of row
(of record)
Purpose
The property length counts
total number of row
(of record)
Purpose
To insert each row of record
from database to each <li>
elements of
Purpose
To remove unnecessary
style and duplicated id
Purpose
Later, we will need this
data-entryId for
comparison of deleting the
entry in case the user
clicks delete button.
[1]
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 24a
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
[1]
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 24b
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
[1]
DELETING ROW
Deleting an existing row (of record) from a database involves these below
steps:
1. binds click events to the Delete buttons as they are created by the refreshEntries()
2. removes the entry from the database
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 25a
PHNOM PENH INTERNATIONAL UNIVERSITY FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY
[1]
DELETING ROW
Deleting an existing row (of record) from a database involves these below
steps:
1. binds click events to the Delete buttons as they are created by the refreshEntries()
2. removes the entry from the database
CLIENT-SIDE DATA STORAGE PROGRAMMING MOBILE APPLICATIONS | BY SAR VATHNAK >> 25b
PRACTICE
REFERENCES
[1] 2012_JonathanStark_Building-android-apps-with-html, css, and-javascript[2ed]
[2] Official homepage of jQT, http://jqtjs.com/
[3] Current used version of jQT used, https://github.com/senchalabs/jQTouch/releases/
download/v1.0.1/jqt-demo-v1.0.1-0-g8a462395772f.tgz
[4] Documentation & tutorials of jQT: https://github.com/senchalabs/jQTouch/wiki
[5] SQL Tutorial, https://www.w3schools.com/sql/
[6] HTML5 Web Storage, https://www.w3schools.com/htmL/html5_webstorage.asp
[7] JavaScript Get Date Methods, https://www.w3schools.com/js/js_date_methods.asp
[8] Javascript add leading zeroes to date, https://stackoverflow.com/questions/3605214/
javascript-add-leading-zeroes-to-date
[9] SQLite, https://en.wikipedia.org/wiki/SQLite#Web_browsers