2 * Copyright (C) 2010 Google 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 are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "V8SQLTransactionSync.h"
37 #include "DatabaseSync.h"
38 #include "ExceptionCode.h"
39 #include "SQLResultSet.h"
41 #include "V8Binding.h"
42 #include "V8BindingMacros.h"
44 #include "V8SQLResultSet.h"
45 #include <wtf/Vector.h>
51 v8::Handle<v8::Value> V8SQLTransactionSync::executeSqlCallback(const v8::Arguments& args)
53 INC_STATS("DOM.SQLTransactionSync.executeSql()");
56 return throwError(SYNTAX_ERR);
58 STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, statement, args[0]);
60 Vector<SQLValue> sqlValues;
62 if (args.Length() > 1 && !isUndefinedOrNull(args[1])) {
63 if (!args[1]->IsObject())
64 return throwError(TYPE_MISMATCH_ERR);
66 uint32_t sqlArgsLength = 0;
67 v8::Local<v8::Object> sqlArgsObject = args[1]->ToObject();
68 EXCEPTION_BLOCK(v8::Local<v8::Value>, length, sqlArgsObject->Get(v8::String::New("length")));
70 if (isUndefinedOrNull(length))
71 sqlArgsLength = sqlArgsObject->GetPropertyNames()->Length();
73 sqlArgsLength = length->Uint32Value();
75 for (unsigned int i = 0; i < sqlArgsLength; ++i) {
76 v8::Local<v8::Integer> key = v8::Integer::New(i);
77 EXCEPTION_BLOCK(v8::Local<v8::Value>, value, sqlArgsObject->Get(key));
79 if (value.IsEmpty() || value->IsNull())
80 sqlValues.append(SQLValue());
81 else if (value->IsNumber()) {
82 EXCEPTION_BLOCK(double, sqlValue, value->NumberValue());
83 sqlValues.append(SQLValue(sqlValue));
85 STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, sqlValue, value);
86 sqlValues.append(SQLValue(sqlValue));
91 SQLTransactionSync* transaction = V8SQLTransactionSync::toNative(args.Holder());
94 v8::Handle<v8::Value> result = toV8(transaction->executeSQL(statement, sqlValues, ec));
95 V8Proxy::setDOMException(ec);
100 } // namespace WebCore