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 * @param {string} domain
34 * @param {string} name
35 * @param {string} version
37 WebInspector.Database = function(model, id, domain, name, version)
41 this._domain = domain;
43 this._version = version;
46 WebInspector.Database.prototype = {
47 /** @return {string} */
53 /** @return {string} */
64 /** @return {string} */
75 /** @return {string} */
87 * @param {function(!Array.<string>)} callback
89 getTableNames: function(callback)
91 function sortingCallback(error, names)
94 callback(names.sort());
96 this._model._agent.getDatabaseTableNames(this._id, sortingCallback);
100 * @param {string} query
101 * @param {function(!Array.<string>=, !Array.<*>=)} onSuccess
102 * @param {function(string)} onError
104 executeSql: function(query, onSuccess, onError)
107 * @param {?Protocol.Error} error
108 * @param {!Array.<string>=} columnNames
109 * @param {!Array.<*>=} values
110 * @param {!DatabaseAgent.Error=} errorObj
112 function callback(error, columnNames, values, errorObj)
120 if (errorObj.message)
121 message = errorObj.message;
122 else if (errorObj.code == 2)
123 message = WebInspector.UIString("Database no longer has expected version.");
125 message = WebInspector.UIString("An unexpected error %s occurred.", errorObj.code);
129 onSuccess(columnNames, values);
131 this._model._agent.executeSQL(this._id, query, callback);
137 * @extends {WebInspector.SDKModel}
138 * @param {!WebInspector.Target} target
140 WebInspector.DatabaseModel = function(target)
142 WebInspector.SDKModel.call(this, WebInspector.DatabaseModel, target);
144 this._databases = [];
145 target.registerDatabaseDispatcher(new WebInspector.DatabaseDispatcher(this));
146 this._agent = target.databaseAgent();
147 this._agent.enable();
150 WebInspector.DatabaseModel.Events = {
151 DatabaseAdded: "DatabaseAdded"
154 WebInspector.DatabaseModel.prototype = {
156 * @return {!Array.<!WebInspector.Database>}
158 databases: function()
161 for (var databaseId in this._databases)
162 result.push(this._databases[databaseId]);
167 * @param {!DatabaseAgent.DatabaseId} databaseId
168 * @return {!WebInspector.Database}
170 databaseForId: function(databaseId)
172 return this._databases[databaseId];
176 * @param {!WebInspector.Database} database
178 _addDatabase: function(database)
180 this._databases.push(database);
181 this.dispatchEventToListeners(WebInspector.DatabaseModel.Events.DatabaseAdded, database);
184 __proto__: WebInspector.SDKModel.prototype
189 * @implements {DatabaseAgent.Dispatcher}
190 * @param {!WebInspector.DatabaseModel} model
192 WebInspector.DatabaseDispatcher = function(model)
197 WebInspector.DatabaseDispatcher.prototype = {
199 * @param {!DatabaseAgent.Database} payload
201 addDatabase: function(payload)
203 this._model._addDatabase(new WebInspector.Database(
213 * @type {!WebInspector.DatabaseModel}
215 WebInspector.databaseModel;