/
Database.yml
193 lines (157 loc) Β· 8.54 KB
/
Database.yml
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
---
name: Titanium.Database
summary: |
The top-level `Database` module, used for creating and accessing the
in-application SQLite database.
extends: Titanium.Module
since: "0.1"
platforms: [android, iphone, ipad, blackberry]
methods:
- name: install
summary: Installs an SQLite database to device's internal storage.
description: |
Copies an SQLite database file to the device's internal storage (only) and
creates a persistent name that is available for the lifetime of the app.
On Android, if the source file does not exist, an empty database is created.
Returns a reference to the opened database. If the destination file already
exists, behaves as <Titanium.Database.open>.
This method is primarily used for iOS.
With Android, as there is often minimal internal storage available, `install`
may only be appropriate for small databases or for prototyping. When database
files are to be stored on external storage (for example, SD Card), a combination of
<Titanium.Filesystem> and <Titanium.Database.open> is required.
With Titanium 1.8.0.1 on iOS, the default database location changed in accordance
with Apple's guidelines. If a database file already exists in the old
location, `install` will automatically move it to the new location
rather than copying the file from the path provided in the first
argument.
Files stored in the `Private Documents` directory on iOS5 will be
automatically backed up to iCloud and removed from the device in low
storage situations. See
[How do I prevent files from being backed up to iCloud and iTunes?](https://developer.apple.com/library/ios/qa/qa1719/_index.html)
for details. To prevent this for database files, use the <Titanium.Database.DB.file>
object with the <Titanium.Filesystem.File.setRemoteBackup> method.
Always [close](Titanium.Database.DB.close) the database after use.
returns:
type: Titanium.Database.DB
parameters:
- name: path
summary: |
Path and filename of the database file to copy to internal storage.
File location is relative to the script's context unless an absolute
path, such as one constructed with a <Titanium.Filesystem>
constant, is used.
type: String
- name: dbName
summary: |
Destination filename, which will subsequently be passed to
<Titanium.Database.open>.
type: String
examples:
- title: Install a Database (iOS)
example: |
A database, with a filename of `mydb1` and located in the same directory as the
the running script, is installed.
var db1 = Ti.Database.install('mydb1', 'mydb1Installed');
The file is copied to the default database location with a file
extension of `sql`.
**On simulator**
* `/Users/user_name/Library/Application Support/iPhone Simulator/ios_version/Applications/apple_app_id/Library/Private Documents/mydb1Installed.sql` (Titanium 1.8.0.1)
* `/Users/user_name/Library/Application Support/iPhone Simulator/ios_version/Applications/apple_app_id/Library/Application Support/database/mydb1Installed.sql` (earlier versions)
**On device**
* `/Applications/apple_app_id/Library/Private Documents/mydb1Installed.sql` (Titanium 1.8.0.1)
* `/Applications/apple_app_id/Library/Application Support/database/mydb1Installed.sql` (earlier versions)
To prevent the database file being automatically backed up to iCloud, use `setRemoteBackup`.
db1.file.setRemoteBackup(false);
- title: Install a Database to Internal Storage (Android)
example: |
A database, with a filename of `mydb1` and located in the same directory as the
the running script, is installed.
var db1 = Ti.Database.install('mydb1', 'mydb1Installed');
Unlike on iOS, no file extension is added. The file is opened in the
following default database location, on both emulator and device.
* `file:///data/data/appID/databases/mydb1Installed`
- title: Install a Database to External Storage (Android)
example: |
The device is checked for the presence of external storage and a
database, with a filename of `mydb2` and located in the same directory as the
the running script, is installed.
if (Ti.Platform.name === 'android' && Ti.Filesystem.isExternalStoragePresent()) {
var db2 = Ti.Database.install('mydb2', Ti.Filesystem.externalStorageDirectory + 'path' + Ti.Filesystem.separator + 'to' + Ti.Filesystem.separator + 'mydb2Installed');
}
Unlike on iOS, no file extension is added. The file is copied to the
absolute path provided.
* `file:///sdcard/path/to/mydb2Installed`
platforms: [android, iphone, ipad]
- name: open
summary: Opens an SQLite database.
description: |
Opens an SQLite database and returns a reference to it. If the database does
not exist, creates an empty database file and returns a reference to this
opened database.
With Titanium 1.8.0.1 on iOS, the default database location changed in accordance
with Apple's guidelines. If a database file already exists in the old
location, `open` will automatically move it to the new location.
Always [close](Titanium.Database.DB.close) the database after use.
returns:
type: Titanium.Database.DB
parameters:
- name: dbName
summary: |
The dbname previously passed to <Titanium.Database.install>. On Android,
an absolute path to the file, including one that is constructed with a
<Titanium.Filesystem> constant, may be used.
type: String
examples:
- title: Open a Database from Internal Storage (iOS)
example: |
A database, with a persistant name of `mydb1Installed` and located in the
default database location on internal storage, is opened.
var db = Ti.Database.open('mydb1Installed');
A file extension of `sql` is added, and the file is opened from the
following location.
On simulator
* `/Users/<user name>/Library/Application Support/iPhone Simulator/<iOS version>/Applications/<apple app id>/Library/Private Documents/mydb1Installed.sql` (Titanium 1.8.0.1)
* `/Users/<user name>/Library/Application Support/iPhone Simulator/<iOS version>/Applications/<apple app id>/Library/Application Support/database/mydb1Installed.sql` (earlier versions)
On device
* `/Applications/<apple app id>/Library/Private Documents/mydb1Installed.sql` (Titanium 1.8.0.1)
* `/Applications/<apple app id>/Library/Application Support/database/mydb1Installed.sql` (earlier versions)
- title: Open a Database on Internal Storage (Android)
example: |
A database, with a persistant name of `mydb1Installed` and located in the
default database location on internal storage, is opened.
var db1 = Ti.Database.open('mydb1Installed');
Unlike on iOS, no file extension is added. The file is opened in
the following location.
* `file:///data/data/appID/databases/mydb1Installed`
- title: Open a Database on External Storage (Android)
example: |
A database, with a filename of `mydb2Installed` and located at the
absolute path provided, is opened.
if (Ti.Platform.name === 'android' && Ti.Filesystem.isExternalStoragePresent()) {
var db2 = Ti.Database.open(Ti.Filesystem.externalStorageDirectory + 'path' + Ti.Filesystem.separator + 'to' + Ti.Filesystem.separator + 'mydb2Installed');
}
Unlike on iOS, no file extension is added. The file is copied to the
absolute path, as follows.
* `file:///sdcard/path/to/mydb2Installed`
properties:
- name: FIELD_TYPE_DOUBLE
summary: Constant for requesting a column's value returned in double form.
type: Number
permission: read-only
exclude-platforms: [blackberry]
- name: FIELD_TYPE_FLOAT
summary: Constant for requesting a column's value returned in float form.
type: Number
permission: read-only
exclude-platforms: [blackberry]
- name: FIELD_TYPE_INT
summary: Constant for requesting a column's value returned in integer form.
type: Number
permission: read-only
exclude-platforms: [blackberry]
- name: FIELD_TYPE_STRING
summary: Constant for requesting a column's value returned in string form.
type: Number
permission: read-only
exclude-platforms: [blackberry]