2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @param {!WebInspector.DatabaseModel} model
33 WebInspector.Database = function(model, id, domain, name, version)
37 this._domain = domain;
39 this._version = version;
42 WebInspector.Database.prototype = {
43 /** @return {string} */
49 /** @return {string} */
60 /** @return {string} */
71 /** @return {string} */
83 * @param {function(!Array.<string>)} callback
85 getTableNames: function(callback)
87 function sortingCallback(error, names)
90 callback(names.sort());
92 DatabaseAgent.getDatabaseTableNames(this._id, sortingCallback);
96 * @param {string} query
97 * @param {function(!Array.<string>=, !Array.<*>=)} onSuccess
98 * @param {function(string)} onError
100 executeSql: function(query, onSuccess, onError)
103 * @param {?Protocol.Error} error
104 * @param {!Array.<string>=} columnNames
105 * @param {!Array.<*>=} values
106 * @param {!DatabaseAgent.Error=} errorObj
108 function callback(error, columnNames, values, errorObj)
116 if (errorObj.message)
117 message = errorObj.message;
118 else if (errorObj.code == 2)
119 message = WebInspector.UIString("Database no longer has expected version.");
121 message = WebInspector.UIString("An unexpected error %s occurred.", errorObj.code);
125 onSuccess(columnNames, values);
127 DatabaseAgent.executeSQL(this._id, query, callback);
133 * @extends {WebInspector.Object}
135 WebInspector.DatabaseModel = function()
137 this._databases = [];
138 InspectorBackend.registerDatabaseDispatcher(new WebInspector.DatabaseDispatcher(this));
139 DatabaseAgent.enable();
142 WebInspector.DatabaseModel.Events = {
143 DatabaseAdded: "DatabaseAdded"
146 WebInspector.DatabaseModel.prototype = {
148 * @return {!Array.<!WebInspector.Database>}
150 databases: function()
153 for (var databaseId in this._databases)
154 result.push(this._databases[databaseId]);
159 * @param {!DatabaseAgent.DatabaseId} databaseId
160 * @return {!WebInspector.Database}
162 databaseForId: function(databaseId)
164 return this._databases[databaseId];
168 * @param {!WebInspector.Database} database
170 _addDatabase: function(database)
172 this._databases.push(database);
173 this.dispatchEventToListeners(WebInspector.DatabaseModel.Events.DatabaseAdded, database);
176 __proto__: WebInspector.Object.prototype
181 * @implements {DatabaseAgent.Dispatcher}
182 * @param {!WebInspector.DatabaseModel} model
184 WebInspector.DatabaseDispatcher = function(model)
189 WebInspector.DatabaseDispatcher.prototype = {
191 * @param {!DatabaseAgent.Database} payload
193 addDatabase: function(payload)
195 this._model._addDatabase(new WebInspector.Database(
205 * @type {!WebInspector.DatabaseModel}
207 WebInspector.databaseModel;