OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
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 | |
13 * distribution. | |
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. | |
17 * | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 | |
33 #include "v8_binding.h" | |
34 #include "v8_custom.h" | |
35 #include "v8_proxy.h" | |
36 | |
37 #include "Database.h" | |
38 #include "SQLValue.h" | |
39 #include "V8CustomSQLStatementCallback.h" | |
40 #include "V8CustomSQLStatementErrorCallback.h" | |
41 #include <wtf/Vector.h> | |
42 | |
43 using namespace WTF; | |
44 | |
45 namespace WebCore { | |
46 | |
47 CALLBACK_FUNC_DECL(SQLTransactionExecuteSql) | |
48 { | |
49 INC_STATS("DOM.SQLTransaction.executeSql()"); | |
50 | |
51 if (args.Length() == 0) { | |
52 V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, "SQL statement is required.")
; | |
53 return v8::Undefined(); | |
54 } | |
55 | |
56 String statement = ToWebCoreString(args[0]); | |
57 | |
58 Vector<SQLValue> sqlValues; | |
59 | |
60 if (args.Length() > 1) { | |
61 // FIXME: Make this work for v8::Arrayish objects, as well | |
62 if (!args[1]->IsArray()) { | |
63 V8Proxy::ThrowError(V8Proxy::TYPE_ERROR, "Statement arguments must b
e an v8::Array."); | |
64 return v8::Undefined(); | |
65 } | |
66 | |
67 v8::Local<v8::Array> arguments = v8::Local<v8::Array>::Cast(args[1]); | |
68 uint32_t length = arguments->Length(); | |
69 | |
70 for (unsigned int i = 0; i < length; ++i) { | |
71 v8::Local<v8::Value> value = arguments->Get(v8::Integer::New(i)); | |
72 if (value.IsEmpty() || value->IsNull()) | |
73 sqlValues.append(SQLValue()); | |
74 else if (value->IsNumber()) | |
75 sqlValues.append(SQLValue(value->NumberValue())); | |
76 else | |
77 sqlValues.append(SQLValue(ToWebCoreString(value))); | |
78 } | |
79 } | |
80 | |
81 SQLTransaction* transaction = V8Proxy::ToNativeObject<SQLTransaction>(V8Clas
sIndex::SQLTRANSACTION, args.Holder()); | |
82 | |
83 Frame* frame = V8Proxy::retrieveFrame(); | |
84 | |
85 RefPtr<SQLStatementCallback> callback; | |
86 if (args.Length() > 2) { | |
87 if (!args[2]->IsObject()) { | |
88 V8Proxy::ThrowError(V8Proxy::TYPE_ERROR, "Statement callback must be
of valid type."); | |
89 return v8::Undefined(); | |
90 } | |
91 | |
92 if (frame) | |
93 callback = V8CustomSQLStatementCallback::create(args[2], frame); | |
94 } | |
95 | |
96 RefPtr<SQLStatementErrorCallback> errorCallback; | |
97 if (args.Length() > 3) { | |
98 if (!args[2]->IsObject()) { | |
99 V8Proxy::ThrowError(V8Proxy::TYPE_ERROR, "Statement error callback m
ust be of valid type."); | |
100 return v8::Undefined(); | |
101 } | |
102 | |
103 if (frame) | |
104 errorCallback = V8CustomSQLStatementErrorCallback::create(args[3], f
rame); | |
105 } | |
106 | |
107 ExceptionCode ec = 0; | |
108 transaction->executeSQL(statement, sqlValues, callback, errorCallback, ec); | |
109 V8Proxy::SetDOMException(ec); | |
110 | |
111 return v8::Undefined(); | |
112 } | |
113 | |
114 } // namespace WebCore | |
OLD | NEW |