| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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/SQLValue.h" | 28 #include "modules/webdatabase/sqlite/SQLValue.h" |
| 29 #include "platform/Logging.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/text/CString.h" | 34 #include "wtf/text/CString.h" |
| 35 #include <memory> |
| 34 | 36 |
| 35 // 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 |
| 36 // 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. |
| 37 #if SQLITE_VERSION_NUMBER < 3006016 | 39 #if SQLITE_VERSION_NUMBER < 3006016 |
| 38 #error SQLite version 3.6.16 or newer is required | 40 #error SQLite version 3.6.16 or newer is required |
| 39 #endif | 41 #endif |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // Only return error codes consistent with 3.7.6.3. | 45 // Only return error codes consistent with 3.7.6.3. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 95 } |
| 94 | 96 |
| 95 int SQLiteStatement::prepare() | 97 int SQLiteStatement::prepare() |
| 96 { | 98 { |
| 97 ASSERT(!m_isPrepared); | 99 ASSERT(!m_isPrepared); |
| 98 | 100 |
| 99 CString query = m_query.stripWhiteSpace().utf8(); | 101 CString query = m_query.stripWhiteSpace().utf8(); |
| 100 | 102 |
| 101 // 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 |
| 102 // with Oilpan stack scanning. | 104 // with Oilpan stack scanning. |
| 103 OwnPtr<const char*> tail = adoptPtr(new const char*); | 105 std::unique_ptr<const char*> tail = wrapUnique(new const char*); |
| 104 OwnPtr<sqlite3_stmt*> statement = adoptPtr(new sqlite3_stmt*); | 106 std::unique_ptr<sqlite3_stmt*> statement = wrapUnique(new sqlite3_stmt*); |
| 105 *tail = nullptr; | 107 *tail = nullptr; |
| 106 *statement = nullptr; | 108 *statement = nullptr; |
| 107 int error; | 109 int error; |
| 108 { | 110 { |
| 109 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 111 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 110 | 112 |
| 111 WTF_LOG(SQLDatabase, "SQL - prepare - %s", query.data()); | 113 WTF_LOG(SQLDatabase, "SQL - prepare - %s", query.data()); |
| 112 | 114 |
| 113 // 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; |
| 114 // this lets SQLite avoid an extra string copy. | 116 // this lets SQLite avoid an extra string copy. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 ASSERT(col >= 0); | 309 ASSERT(col >= 0); |
| 308 if (!m_statement) | 310 if (!m_statement) |
| 309 if (prepareAndStep() != SQLITE_ROW) | 311 if (prepareAndStep() != SQLITE_ROW) |
| 310 return 0; | 312 return 0; |
| 311 if (columnCount() <= col) | 313 if (columnCount() <= col) |
| 312 return 0; | 314 return 0; |
| 313 return sqlite3_column_int64(m_statement, col); | 315 return sqlite3_column_int64(m_statement, col); |
| 314 } | 316 } |
| 315 | 317 |
| 316 } // namespace blink | 318 } // namespace blink |
| OLD | NEW |