forked from phonegap/phonegap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcordova_storage_storage.md.html
980 lines (809 loc) · 37.2 KB
/
cordova_storage_storage.md.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
<meta name="generator" content="joDoc">
<title>Apache Cordova API Documentation</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
<link rel="stylesheet" type="text/css" href="prettify/prettify.css">
</head>
<body>
<div id="header">
<h1><a href="index.html">Apache <strong>Cordova</strong> Documentation</a></h1>
<small>
<select><optgroup label="English" value="en">
<option value="edge">edge</option>
<option selected value="1.8.0rc1">1.8.0rc1</option>
<option value="1.7.0rc1">1.7.0rc1</option>
<option value="1.7.0">1.7.0</option>
<option value="1.6.1">1.6.1</option>
<option value="1.6.0rc1">1.6.0rc1</option>
<option value="1.6.0">1.6.0</option>
<option value="1.5.0rc1">1.5.0rc1</option>
<option value="1.5.0">1.5.0</option>
<option value="1.4.1">1.4.1</option>
<option value="1.4.0rc1">1.4.0rc1</option>
<option value="1.4.0">1.4.0</option>
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
<option value="1.0.0rc3">1.0.0rc3</option>
<option value="1.0.0rc2">1.0.0rc2</option>
<option value="1.0.0rc1">1.0.0rc1</option>
<option value="1.0.0">1.0.0</option>
<option value="0.9.6">0.9.6</option>
<option value="0.9.5.1">0.9.5.1</option>
<option value="0.9.5">0.9.5</option>
<option value="0.9.4">0.9.4</option>
<option value="0.9.3">0.9.3</option>
<option value="0.9.2">0.9.2</option>
</optgroup>
<optgroup label="Español" value="es"><option value="1.0.0">1.0.0</option></optgroup>
<optgroup label="Français" value="fr">
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
</optgroup>
<optgroup label="Japanese" value="jp"><option value="0.9.5">0.9.5</option></optgroup></select></small>
</div>
<div id="subheader">
<h1>Storage</h1>
<small><select><option value="Storage">Storage</option>
<option value="Storage_methods"> - Methods</option>
<option value="Storage_arguments"> - Arguments</option>
<option value="Storage_objects"> - Objects</option>
<option value="Storage_permissions"> - Permissions</option>
<option value="openDatabase">openDatabase</option>
<option value="openDatabase_description"> - Description</option>
<option value="openDatabase_supported_platforms"> - Supported Platforms</option>
<option value="openDatabase_quick_example"> - Quick Example</option>
<option value="openDatabase_full_example"> - Full Example</option>
<option value="database_name">database_name</option>
<option value="database_version">database_version</option>
<option value="database_displayname">database_displayname</option>
<option value="database_size">database_size</option>
<option value="Database">Database</option>
<option value="Database_methods"> - Methods</option>
<option value="Database_details"> - Details</option>
<option value="Database_supported_platforms"> - Supported Platforms</option>
<option value="Database_transaction_quick_example"> - Transaction Quick Example</option>
<option value="Database_change_version_quick_example"> - Change Version Quick Example</option>
<option value="Database_full_example"> - Full Example</option>
<option value="Database_android_1_x_quirks"> - Android 1.X Quirks</option>
<option value="SQLTransaction">SQLTransaction</option>
<option value="SQLTransaction_methods"> - Methods</option>
<option value="SQLTransaction_details"> - Details</option>
<option value="SQLTransaction_supported_platforms"> - Supported Platforms</option>
<option value="SQLTransaction_execute_sql_quick_example"> - Execute SQL Quick Example</option>
<option value="SQLTransaction_full_example"> - Full Example</option>
<option value="SQLResultSet">SQLResultSet</option>
<option value="SQLResultSet_properties"> - Properties</option>
<option value="SQLResultSet_details"> - Details</option>
<option value="SQLResultSet_supported_platforms"> - Supported Platforms</option>
<option value="SQLResultSet_execute_sql_quick_example"> - Execute SQL Quick Example</option>
<option value="SQLResultSet_full_example"> - Full Example</option>
<option value="SQLResultSetList">SQLResultSetList</option>
<option value="SQLResultSetList_properties"> - Properties</option>
<option value="SQLResultSetList_methods"> - Methods</option>
<option value="SQLResultSetList_details"> - Details</option>
<option value="SQLResultSetList_supported_platforms"> - Supported Platforms</option>
<option value="SQLResultSetList_execute_sql_quick_example"> - Execute SQL Quick Example</option>
<option value="SQLResultSetList_full_example"> - Full Example</option>
<option value="SQLError">SQLError</option>
<option value="SQLError_properties"> - Properties</option>
<option value="SQLError_constants"> - Constants</option>
<option value="SQLError_description"> - Description</option>
<option value="localStorage">localStorage</option>
<option value="localStorage_methods"> - Methods</option>
<option value="localStorage_details"> - Details</option>
<option value="localStorage_supported_platforms"> - Supported Platforms</option>
<option value="localStorage_key_quick_example"> - Key Quick Example</option>
<option value="localStorage_set_item_quick_example"> - Set Item Quick Example</option>
<option value="localStorage_get_item_quick_example"> - Get Item Quick Example</option>
<option value="localStorage_remove_item_quick_example"> - Remove Item Quick Example</option>
<option value="localStorage_clear_quick_example"> - Clear Quick Example</option>
<option value="localStorage_full_example"> - Full Example</option>
<option value="localStorage_windows_phone_7_quirks"> - Windows Phone 7 Quirks</option></select></small>
</div>
<div id="sidebar">
<div class="vertical_divider"></div>
<h1>API Reference</h1>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></li>
<li><a href="cordova_camera_camera.md.html#Camera">Camera</a></li>
<li><a href="cordova_media_capture_capture.md.html#Capture">Capture</a></li>
<li><a href="cordova_compass_compass.md.html#Compass">Compass</a></li>
<li><a href="cordova_connection_connection.md.html#Connection">Connection</a></li>
<li><a href="cordova_contacts_contacts.md.html#Contacts">Contacts</a></li>
<li><a href="cordova_device_device.md.html#Device">Device</a></li>
<li><a href="cordova_events_events.md.html#Events">Events</a></li>
<li><a href="cordova_file_file.md.html#File">File</a></li>
<li><a href="cordova_geolocation_geolocation.md.html#Geolocation">Geolocation</a></li>
<li><a href="cordova_media_media.md.html#Media">Media</a></li>
<li><a href="cordova_notification_notification.md.html#Notification">Notification</a></li>
<li><a href="cordova_storage_storage.md.html#Storage">Storage</a></li>
</ul>
<h1>Guides</h1>
<ul>
<li><a href="guide_getting-started_index.md.html#Getting%20Started%20Guides">Getting Started Guides</a></li>
<li><a href="guide_upgrading_index.md.html#Upgrading%20Guides">Upgrading Guides</a></li>
<li><a href="guide_whitelist_index.md.html#Domain%20Whitelist%20Guide">Domain Whitelist Guide</a></li>
<li><a href="_index.html">Keyword Index</a></li>
</ul>
</div>
<div id="scrollable">
<div id="content">
<h1><a name="Storage">Storage</a></h1>
<blockquote>
<p>Provides access to the devices storage options.</p>
</blockquote>
<p>This API is based on the <a class="external" href="http://dev.w3.org/html5/webdatabase/">W3C Web SQL </a><a href="cordova_storage_storage.md.html#Database">Database</a> Specification and <a class="external" href="http://dev.w3.org/html5/webstorage/">W3C Web </a><a href="cordova_storage_storage.md.html#Storage">Storage</a> API Specification. Some devices already provide an implementation of this spec. For those devices, the built-in support is used instead of replacing it with Cordova's implementation. For devices that don't have storage support, Cordova's implementation should be compatible with the W3C specification.</p>
<h2>
<a name="Storage_methods">Methods</a>
</h2>
<ul>
<li><a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a></li>
</ul>
<h2>
<a name="Storage_arguments">Arguments</a>
</h2>
<ul>
<li><a href="cordova_storage_storage.md.html#database_name">database_name</a></li>
<li><a href="cordova_storage_storage.md.html#database_version">database_version</a></li>
<li><a href="cordova_storage_storage.md.html#database_displayname">database_displayname</a></li>
<li><a href="cordova_storage_storage.md.html#database_size">database_size</a></li>
</ul>
<h2>
<a name="Storage_objects">Objects</a>
</h2>
<ul>
<li><a href="cordova_storage_storage.md.html#Database">Database</a></li>
<li><a href="cordova_storage_storage.md.html#SQLTransaction">SQLTransaction</a></li>
<li><a href="cordova_storage_storage.md.html#SQLResultSet">SQLResultSet</a></li>
<li><a href="cordova_storage_storage.md.html#SQLResultSetList">SQLResultSetList</a></li>
<li><a href="cordova_storage_storage.md.html#SQLError">SQLError</a></li>
<li><a href="cordova_storage_storage.md.html#localStorage">localStorage</a></li>
</ul>
<h2>
<a name="Storage_permissions">Permissions</a>
</h2>
<h3>Android</h3>
<h4>app/res/xml/plugins.xml</h4>
<pre class="prettyprint"><code><plugin name="<a href="cordova_storage_storage.md.html#Storage">Storage</a>" value="org.apache.cordova.<a href="cordova_storage_storage.md.html#Storage">Storage</a>"/>
</code></pre>
<h3>Bada</h3>
<pre class="prettyprint"><code>@TODO
</code></pre>
<h3>BlackBerry WebWorks</h3>
<h4>www/plugins.xml</h4>
<pre class="prettyprint"><code>@TODO
</code></pre>
<h4>www/config.xml</h4>
<pre class="prettyprint"><code><feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
</code></pre>
<h3>iOS</h3>
<pre class="prettyprint"><code>No plugin required.
</code></pre>
<h3>webOS</h3>
<pre class="prettyprint"><code>@TODO
</code></pre>
<h3>Windows Phone</h3>
<pre class="prettyprint"><code>No additional permissions required.
</code></pre>
<hr>
<h1><a name="openDatabase">openDatabase</a></h1>
<p>Returns a new <a href="cordova_storage_storage.md.html#Database">Database</a> object.</p>
<pre class="prettyprint"><code>var dbShell = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>(<a href="cordova_storage_storage.md.html#database_name">database_name</a>, <a href="cordova_storage_storage.md.html#database_version">database_version</a>, <a href="cordova_storage_storage.md.html#database_displayname">database_displayname</a>, <a href="cordova_storage_storage.md.html#database_size">database_size</a>);
</code></pre>
<h2>
<a name="openDatabase_description">Description</a>
</h2>
<p>window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a> returns a new <a href="cordova_storage_storage.md.html#Database">Database</a> object.</p>
<p>This method will create a new SQL Lite <a href="cordova_storage_storage.md.html#Database">Database</a> and return a <a href="cordova_storage_storage.md.html#Database">Database</a> object. Use the <a href="cordova_storage_storage.md.html#Database">Database</a> Object to manipulate the data.</p>
<h2>
<a name="openDatabase_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>webOS</li>
</ul>
<h2>
<a name="openDatabase_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("test", "1.0", "Test DB", 1000000);
</code></pre>
<h2>
<a name="openDatabase_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("test", "1.0", "Test DB", 1000000);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Open <a href="cordova_storage_storage.md.html#Database">Database</a></p>
</body>
</html>
</code></pre>
<hr>
<h1><a name="database_name">database_name</a></h1>
<p>The name of the database.</p>
<hr>
<h1><a name="database_version">database_version</a></h1>
<p>The version of the database.</p>
<hr>
<h1><a name="database_displayname">database_displayname</a></h1>
<p>The display name of the database.</p>
<hr>
<h1><a name="database_size">database_size</a></h1>
<p>The size of the database in bytes.</p>
<hr>
<h1><a name="Database">Database</a></h1>
<p>Contains methods that allow the user to manipulate the <a href="cordova_storage_storage.md.html#Database">Database</a></p>
<h2>
<a name="Database_methods">Methods</a>
</h2>
<ul>
<li>
<strong>transaction</strong>: Runs a database transaction. </li>
<li>
<strong>changeVersion</strong>: method allows scripts to atomically verify the version number and change it at the same time as doing a schema update. </li>
</ul>
<h2>
<a name="Database_details">Details</a>
</h2>
<p>A <a href="cordova_storage_storage.md.html#Database">Database</a> object is returned from a call to <code>window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>()</code>.</p>
<h2>
<a name="Database_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>webOS</li>
</ul>
<h2>
<a name="Database_transaction_quick_example">Transaction Quick Example</a>
</h2>
<pre class="prettyprint"><code>function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
function successCB() {
alert("success!");
}
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
</code></pre>
<h2>
<a name="Database_change_version_quick_example">Change Version Quick Example</a>
</h2>
<pre class="prettyprint"><code>var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.changeVersion("1.0", "1.1");
</code></pre>
<h2>
<a name="Database_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Transaction error callback
//
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
</script>
</head>
<body>
<h1>Example</h1>
<p><a href="cordova_storage_storage.md.html#Database">Database</a></p>
</body>
</html>
</code></pre>
<h2>
<a name="Database_android_1_x_quirks">Android 1.X Quirks</a>
</h2>
<ul>
<li>
<strong>changeVersion:</strong> This method is not support by Android 1.X devices.</li>
</ul>
<hr>
<h1><a name="SQLTransaction">SQLTransaction</a></h1>
<p>Contains methods that allow the user to execute SQL statements against the <a href="cordova_storage_storage.md.html#Database">Database</a>.</p>
<h2>
<a name="SQLTransaction_methods">Methods</a>
</h2>
<ul>
<li>
<strong>executeSql</strong>: executes a SQL statement</li>
</ul>
<h2>
<a name="SQLTransaction_details">Details</a>
</h2>
<p>When you call a <a href="cordova_storage_storage.md.html#Database">Database</a> objects transaction method it's callback methods will be called with a <a href="cordova_storage_storage.md.html#SQLTransaction">SQLTransaction</a> object. The user can build up a database transaction by calling the executeSql method multiple times. </p>
<h2>
<a name="SQLTransaction_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>webOS</li>
</ul>
<h2>
<a name="SQLTransaction_execute_sql_quick_example">Execute SQL Quick Example</a>
</h2>
<pre class="prettyprint"><code>function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function errorCB(err) {
alert("Error processing SQL: "+err);
}
function successCB() {
alert("success!");
}
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
</code></pre>
<h2>
<a name="SQLTransaction_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Transaction error callback
//
function errorCB(err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
</script>
</head>
<body>
<h1>Example</h1>
<p><a href="cordova_storage_storage.md.html#SQLTransaction">SQLTransaction</a></p>
</body>
</html>
</code></pre>
<hr>
<h1><a name="SQLResultSet">SQLResultSet</a></h1>
<p>When the executeSql method of a <a href="cordova_storage_storage.md.html#SQLTransaction">SQLTransaction</a> is called it will invoke it's callback with a <a href="cordova_storage_storage.md.html#SQLResultSet">SQLResultSet</a>.</p>
<h2>
<a name="SQLResultSet_properties">Properties</a>
</h2>
<ul>
<li>
<strong>insertId</strong>: the row ID of the row that the <a href="cordova_storage_storage.md.html#SQLResultSet">SQLResultSet</a> object's SQL statement inserted into the database</li>
<li>
<strong>rowsAffected</strong>: the number of rows that were changed by the SQL statement. If the statement did not affect any rows then it is set to 0. </li>
<li>
<strong>rows</strong>: a SQLResultSetRowList representing the rows returned. If no rows are returned the object will be empty.</li>
</ul>
<h2>
<a name="SQLResultSet_details">Details</a>
</h2>
<p>When you call the <a href="cordova_storage_storage.md.html#SQLTransaction">SQLTransaction</a> executeSql method its callback methods will be called with a <a href="cordova_storage_storage.md.html#SQLResultSet">SQLResultSet</a> object. The result object has three properties. The first is the <code>insertId</code> which will return the row number of a success SQL insert statement. If the SQL statement is not an insert then the <code>insertId</code> is not set. The <code>rowsAffected</code> is always 0 for a SQL select statement. For insert or update statements it returns the number of rows that have been modified. The final property is of type <a href="cordova_storage_storage.md.html#SQLResultSetList">SQLResultSetList</a> and it contains the data returned from a SQL select statement.</p>
<h2>
<a name="SQLResultSet_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>webOS</li>
</ul>
<h2>
<a name="SQLResultSet_execute_sql_quick_example">Execute SQL Quick Example</a>
</h2>
<pre class="prettyprint"><code>function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
console.log("Returned rows = " + results.rows.length);
// this will be true since it was a select statement and so rowsAffected was 0
if (!resultSet.rowsAffected) {
console.log('No rows affected!');
return false;
}
// for an insert statement, this property will return the ID of the last inserted row
console.log("Last inserted row ID = " + results.insertId);
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
</code></pre>
<h2>
<a name="SQLResultSet_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
console.log("Returned rows = " + results.rows.length);
// this will be true since it was a select statement and so rowsAffected was 0
if (!results.rowsAffected) {
console.log('No rows affected!');
return false;
}
// for an insert statement, this property will return the ID of the last inserted row
console.log("Last inserted row ID = " + results.insertId);
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
}
// Cordova is ready
//
function onDeviceReady() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
</script>
</head>
<body>
<h1>Example</h1>
<p><a href="cordova_storage_storage.md.html#Database">Database</a></p>
</body>
</html>
</code></pre>
<hr>
<h1><a name="SQLResultSetList">SQLResultSetList</a></h1>
<p>One of the properties of the <a href="cordova_storage_storage.md.html#SQLResultSet">SQLResultSet</a> containing the rows returned from a SQL query.</p>
<h2>
<a name="SQLResultSetList_properties">Properties</a>
</h2>
<ul>
<li>
<strong>length</strong>: the number of rows returned by the SQL query</li>
</ul>
<h2>
<a name="SQLResultSetList_methods">Methods</a>
</h2>
<ul>
<li>
<strong>item</strong>: returns the row at the specified index represented by a JavaScript object.</li>
</ul>
<h2>
<a name="SQLResultSetList_details">Details</a>
</h2>
<p>The <a href="cordova_storage_storage.md.html#SQLResultSetList">SQLResultSetList</a> contains the data returned from a SQL select statement. The object contains a length property letting you know how many rows the select statement has been returned. To get a row of data you would call the <code>item</code> method specifing an index. The item method returns a JavaScript Object who's properties are the columns of the database the select statement was executed against.</p>
<h2>
<a name="SQLResultSetList_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>webOS</li>
</ul>
<h2>
<a name="SQLResultSetList_execute_sql_quick_example">Execute SQL Quick Example</a>
</h2>
<pre class="prettyprint"><code>function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
</code></pre>
<h2>
<a name="SQLResultSetList_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
}
// Cordova is ready
//
function onDeviceReady() {
var db = window.<a href="cordova_storage_storage.md.html#openDatabase">openDatabase</a>("<a href="cordova_storage_storage.md.html#Database">Database</a>", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
</script>
</head>
<body>
<h1>Example</h1>
<p><a href="cordova_storage_storage.md.html#Database">Database</a></p>
</body>
</html>
</code></pre>
<hr>
<h1><a name="SQLError">SQLError</a></h1>
<p>A <code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a></code> object is thrown when an error occurs.</p>
<h2>
<a name="SQLError_properties">Properties</a>
</h2>
<ul>
<li>
<strong>code:</strong> One of the predefined error codes listed below.</li>
<li>
<strong>message:</strong> A description of the error.</li>
</ul>
<h2>
<a name="SQLError_constants">Constants</a>
</h2>
<ul>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.UNKNOWN_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.DATABASE_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.VERSION_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.TOO_LARGE_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.QUOTA_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.SYNTAX_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.CONSTRAINT_ERR</code></li>
<li><code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a>.TIMEOUT_ERR</code></li>
</ul>
<h2>
<a name="SQLError_description">Description</a>
</h2>
<p>The <code><a href="cordova_storage_storage.md.html#SQLError">SQLError</a></code> object is thrown when an error occurs when manipulating a database.</p>
<hr>
<h1><a name="localStorage">localStorage</a></h1>
<p>Provides access to a W3C <a href="cordova_storage_storage.md.html#Storage">Storage</a> interface (http://dev.w3.org/html5/webstorage/#the-localstorage-attribute)</p>
<pre class="prettyprint"><code>var storage = window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>;
</code></pre>
<h2>
<a name="localStorage_methods">Methods</a>
</h2>
<ul>
<li>
<strong>key</strong>: Returns the name of the key at the position specified. </li>
<li>
<strong>getItem</strong>: Returns the item identified by it's key.</li>
<li>
<strong>setItem</strong>: Saves and item at the key provided.</li>
<li>
<strong>removeItem</strong>: Removes the item identified by it's key.</li>
<li>
<strong>clear</strong>: Removes all of the key value pairs.</li>
</ul>
<h2>
<a name="localStorage_details">Details</a>
</h2>
<p><a href="cordova_storage_storage.md.html#localStorage">localStorage</a> provides an interface to a W3C <a href="cordova_storage_storage.md.html#Storage">Storage</a> interface. It allows one to save data as key-value pairs.</p>
<p>Note: window.sessionStorage provides the same interface, but is cleared between app launches.</p>
<h2>
<a name="localStorage_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 6.0 and higher)</li>
<li>iPhone</li>
<li>Windows Phone 7</li>
<li>webOS</li>
</ul>
<h2>
<a name="localStorage_key_quick_example">Key Quick Example</a>
</h2>
<pre class="prettyprint"><code>var keyName = window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.key(0);
</code></pre>
<h2>
<a name="localStorage_set_item_quick_example">Set Item Quick Example</a>
</h2>
<pre class="prettyprint"><code>window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.setItem("key", "value");
</code></pre>
<h2>
<a name="localStorage_get_item_quick_example">Get Item Quick Example</a>
</h2>
<pre class="prettyprint"><code>var value = window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.getItem("key");
// value is now equal to "value"
</code></pre>
<h2>
<a name="localStorage_remove_item_quick_example">Remove Item Quick Example</a>
</h2>
<pre class="prettyprint"><code>window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.removeItem("key");
</code></pre>
<h2>
<a name="localStorage_clear_quick_example">Clear Quick Example</a>
</h2>
<pre class="prettyprint"><code>window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.clear();
</code></pre>
<h2>
<a name="localStorage_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_storage_storage.md.html#Storage">Storage</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.setItem("key", "value");
var keyname = window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.key(i);
// keyname is now equal to "key"
var value = window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.getItem("key");
// value is now equal to "value"
window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.removeItem("key");
window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.setItem("key2", "value2");
window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.clear();
// <a href="cordova_storage_storage.md.html#localStorage">localStorage</a> is now empty
}
</script>
</head>
<body>
<h1>Example</h1>
<p><a href="cordova_storage_storage.md.html#localStorage">localStorage</a></p>
</body>
</html>
</code></pre>
<h2>
<a name="localStorage_windows_phone_7_quirks">Windows Phone 7 Quirks</a>
</h2>
<ul>
<li>dot notation is NOT available on Windows Phone. Be sure to use : window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.setItem/getItem, and not the w3 spec defined calls to window.<a href="cordova_storage_storage.md.html#localStorage">localStorage</a>.someKey = 'someValue';</li>
</ul>
</div>
</div>
<!-- Functionality and Syntax Highlighting -->
<script type="text/javascript" src="index.js"></script><script type="text/javascript" src="prettify/prettify.js"></script>
</body>
</html>