| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/webdatabase/sqlite/SQLiteStatement.h" | 26 #include "modules/webdatabase/sqlite/SQLiteStatement.h" |
| 27 | 27 |
| 28 #include "modules/webdatabase/sqlite/SQLLog.h" |
| 28 #include "modules/webdatabase/sqlite/SQLValue.h" | 29 #include "modules/webdatabase/sqlite/SQLValue.h" |
| 29 #include "platform/Logging.h" | |
| 30 #include "platform/heap/SafePoint.h" | 30 #include "platform/heap/SafePoint.h" |
| 31 #include "third_party/sqlite/sqlite3.h" | 31 #include "third_party/sqlite/sqlite3.h" |
| 32 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
| 33 #include "wtf/PtrUtil.h" | 33 #include "wtf/PtrUtil.h" |
| 34 #include "wtf/text/CString.h" | 34 #include "wtf/text/CString.h" |
| 35 #include <memory> | 35 #include <memory> |
| 36 | 36 |
| 37 // SQLite 3.6.16 makes sqlite3_prepare_v2 automatically retry preparing the stat
ement | 37 // SQLite 3.6.16 makes sqlite3_prepare_v2 automatically retry preparing the stat
ement |
| 38 // once if the database scheme has changed. We rely on this behavior. | 38 // once if the database scheme has changed. We rely on this behavior. |
| 39 #if SQLITE_VERSION_NUMBER < 3006016 | 39 #if SQLITE_VERSION_NUMBER < 3006016 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Need to pass non-stack |const char*| and |sqlite3_stmt*| to avoid race | 103 // Need to pass non-stack |const char*| and |sqlite3_stmt*| to avoid race |
| 104 // with Oilpan stack scanning. | 104 // with Oilpan stack scanning. |
| 105 std::unique_ptr<const char*> tail = wrapUnique(new const char*); | 105 std::unique_ptr<const char*> tail = wrapUnique(new const char*); |
| 106 std::unique_ptr<sqlite3_stmt*> statement = wrapUnique(new sqlite3_stmt*); | 106 std::unique_ptr<sqlite3_stmt*> statement = wrapUnique(new sqlite3_stmt*); |
| 107 *tail = nullptr; | 107 *tail = nullptr; |
| 108 *statement = nullptr; | 108 *statement = nullptr; |
| 109 int error; | 109 int error; |
| 110 { | 110 { |
| 111 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 111 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 112 | 112 |
| 113 WTF_LOG(SQLDatabase, "SQL - prepare - %s", query.data()); | 113 SQL_DVLOG(1) << "SQL - prepare - " << query.data(); |
| 114 | 114 |
| 115 // Pass the length of the string including the null character to sqlite3
_prepare_v2; | 115 // Pass the length of the string including the null character to sqlite3
_prepare_v2; |
| 116 // this lets SQLite avoid an extra string copy. | 116 // this lets SQLite avoid an extra string copy. |
| 117 size_t lengthIncludingNullCharacter = query.length() + 1; | 117 size_t lengthIncludingNullCharacter = query.length() + 1; |
| 118 | 118 |
| 119 error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), len
gthIncludingNullCharacter, statement.get(), tail.get()); | 119 error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), len
gthIncludingNullCharacter, statement.get(), tail.get()); |
| 120 } | 120 } |
| 121 m_statement = *statement; | 121 m_statement = *statement; |
| 122 | 122 |
| 123 if (error != SQLITE_OK) | 123 if (error != SQLITE_OK) |
| 124 WTF_LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, que
ry.data(), sqlite3_errmsg(m_database.sqlite3Handle())); | 124 SQL_DVLOG(1) << "sqlite3_prepare16 failed (" << error << ")\n" << query.
data() << "\n" << sqlite3_errmsg(m_database.sqlite3Handle()); |
| 125 else if (*tail && **tail) | 125 else if (*tail && **tail) |
| 126 error = SQLITE_ERROR; | 126 error = SQLITE_ERROR; |
| 127 | 127 |
| 128 #if ENABLE(ASSERT) | 128 #if ENABLE(ASSERT) |
| 129 m_isPrepared = error == SQLITE_OK; | 129 m_isPrepared = error == SQLITE_OK; |
| 130 #endif | 130 #endif |
| 131 return restrictError(error); | 131 return restrictError(error); |
| 132 } | 132 } |
| 133 | 133 |
| 134 int SQLiteStatement::step() | 134 int SQLiteStatement::step() |
| 135 { | 135 { |
| 136 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 136 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 137 //ASSERT(m_isPrepared); | 137 //ASSERT(m_isPrepared); |
| 138 | 138 |
| 139 if (!m_statement) | 139 if (!m_statement) |
| 140 return SQLITE_OK; | 140 return SQLITE_OK; |
| 141 | 141 |
| 142 // The database needs to update its last changes count before each statement | 142 // The database needs to update its last changes count before each statement |
| 143 // in order to compute properly the lastChanges() return value. | 143 // in order to compute properly the lastChanges() return value. |
| 144 m_database.updateLastChangesCount(); | 144 m_database.updateLastChangesCount(); |
| 145 | 145 |
| 146 WTF_LOG(SQLDatabase, "SQL - step - %s", m_query.ascii().data()); | 146 SQL_DVLOG(1) << "SQL - step - " << m_query; |
| 147 int error = sqlite3_step(m_statement); | 147 int error = sqlite3_step(m_statement); |
| 148 if (error != SQLITE_DONE && error != SQLITE_ROW) { | 148 if (error != SQLITE_DONE && error != SQLITE_ROW) { |
| 149 WTF_LOG(SQLDatabase, "sqlite3_step failed (%i)\nQuery - %s\nError - %s", | 149 SQL_DVLOG(1) << "sqlite3_step failed (" << error << " )\nQuery - " |
| 150 error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Hand
le())); | 150 << m_query << "\nError - " << sqlite3_errmsg(m_database.sqlite3Handl
e()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 return restrictError(error); | 153 return restrictError(error); |
| 154 } | 154 } |
| 155 | 155 |
| 156 int SQLiteStatement::finalize() | 156 int SQLiteStatement::finalize() |
| 157 { | 157 { |
| 158 #if ENABLE(ASSERT) | 158 #if ENABLE(ASSERT) |
| 159 m_isPrepared = false; | 159 m_isPrepared = false; |
| 160 #endif | 160 #endif |
| 161 if (!m_statement) | 161 if (!m_statement) |
| 162 return SQLITE_OK; | 162 return SQLITE_OK; |
| 163 WTF_LOG(SQLDatabase, "SQL - finalize - %s", m_query.ascii().data()); | 163 SQL_DVLOG(1) << "SQL - finalize - " << m_query; |
| 164 int result = sqlite3_finalize(m_statement); | 164 int result = sqlite3_finalize(m_statement); |
| 165 m_statement = 0; | 165 m_statement = 0; |
| 166 return restrictError(result); | 166 return restrictError(result); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool SQLiteStatement::executeCommand() | 169 bool SQLiteStatement::executeCommand() |
| 170 { | 170 { |
| 171 if (!m_statement && prepare() != SQLITE_OK) | 171 if (!m_statement && prepare() != SQLITE_OK) |
| 172 return false; | 172 return false; |
| 173 ASSERT(m_isPrepared); | 173 ASSERT(m_isPrepared); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 ASSERT(col >= 0); | 309 ASSERT(col >= 0); |
| 310 if (!m_statement) | 310 if (!m_statement) |
| 311 if (prepareAndStep() != SQLITE_ROW) | 311 if (prepareAndStep() != SQLITE_ROW) |
| 312 return 0; | 312 return 0; |
| 313 if (columnCount() <= col) | 313 if (columnCount() <= col) |
| 314 return 0; | 314 return 0; |
| 315 return sqlite3_column_int64(m_statement, col); | 315 return sqlite3_column_int64(m_statement, col); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace blink | 318 } // namespace blink |
| OLD | NEW |