Path: blob/trunk/javascript/webdriver/atoms/inject/sql_database.js
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview Ready to inject atoms for handling web SQL database.19*/2021goog.provide('webdriver.atoms.inject.storage.database');2223goog.require('bot.Error');24goog.require('bot.ErrorCode');25goog.require('bot.storage.database');26goog.require('webdriver.atoms.inject');272829/**30* Executes the given query in the Web SQL database specified.31*32* @param {string} databaseName The name of the database.33* @param {string} query The SQL statement.34* @param {Array.<*>} args Arguments to pass to the query.35* @param {function(string)} onDone The callback to invoke when done. The36* result, according to the wire protocol, will be passed to this callback.37*/38webdriver.atoms.inject.storage.database.executeSql =39function(databaseName, query, args, onDone) {40var onSuccessCallback = function(tx, result) {41onDone(webdriver.atoms.inject.executeScript(function(res) {42return result;43}, [result]));44};4546var onErrorCallback = function(error) {47onDone(webdriver.atoms.inject.executeScript(function() {48throw new bot.Error(bot.ErrorCode.SQL_DATABASE_ERROR,49'SQL Error Code: ' + error.code + '. SQL Error Message: ' +50error.message);51}, []));52};5354bot.storage.database.executeSql(55databaseName, query, args, onSuccessCallback, onErrorCallback);56};575859