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.
32 WebInspector.Database = function(id, domain, name, version)
35 this._domain = domain;
37 this._version = version;
40 WebInspector.Database.prototype = {
78 return WebInspector.Resource.prototype.__lookupGetter__("displayDomain").call(this);
81 getTableNames: function(callback)
83 function sortingCallback(error, names)
86 callback(names.sort());
88 DatabaseAgent.getDatabaseTableNames(this._id, sortingCallback);
91 executeSql: function(query, onSuccess, onError)
93 function callback(error, success, transactionId)
100 onError(WebInspector.UIString("Database not found."));
103 WebInspector.DatabaseDispatcher._callbacks[transactionId] = {"onSuccess": onSuccess, "onError": onError};
105 DatabaseAgent.executeSQL(this._id, query, callback);
111 * @implements {DatabaseAgent.Dispatcher}
113 WebInspector.DatabaseDispatcher = function()
117 WebInspector.DatabaseDispatcher._callbacks = {};
119 WebInspector.DatabaseDispatcher.prototype = {
120 addDatabase: function(payload)
122 var database = new WebInspector.Database(
127 WebInspector.panels.resources.addDatabase(database);
130 sqlTransactionSucceeded: function(transactionId, columnNames, values)
132 if (!WebInspector.DatabaseDispatcher._callbacks[transactionId])
135 var callback = WebInspector.DatabaseDispatcher._callbacks[transactionId].onSuccess;
136 delete WebInspector.DatabaseDispatcher._callbacks[transactionId];
138 callback(columnNames, values);
141 sqlTransactionFailed: function(transactionId, errorObj)
143 if (!WebInspector.DatabaseDispatcher._callbacks[transactionId])
146 var callback = WebInspector.DatabaseDispatcher._callbacks[transactionId].onError;
147 delete WebInspector.DatabaseDispatcher._callbacks[transactionId];
153 InspectorBackend.registerDatabaseDispatcher(new WebInspector.DatabaseDispatcher());