Changeset 278647 in webkit
- Timestamp:
- Jun 8, 2021, 10:03:32 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 9 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (modified) (24 diffs)
-
WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp (modified) (6 diffs)
-
WebCore/loader/appcache/ApplicationCacheStorage.cpp (modified) (1 diff)
-
WebCore/platform/sql/SQLiteStatement.cpp (modified) (3 diffs)
-
WebCore/platform/sql/SQLiteStatement.h (modified) (3 diffs)
-
WebCore/workers/service/server/RegistrationDatabase.cpp (modified) (4 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/API/glib/IconDatabase.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r278646 r278647 1 2021-06-08 Sam Weinig <weinig@apple.com> 2 3 Adopt WTF::Span in SQLiteStatement 4 https://bugs.webkit.org/show_bug.cgi?id=226773 5 6 Reviewed by Alex Christensen. 7 8 Do some initial adoption of WTF::Span by adopting it in SQLiteStatement. 9 10 - Removes class BlobView. 11 - Renames columnBlobView to columnBlobAsSpan() (mirrors columnBlobAsString() naming) 12 and have it return a Span<const uint8_t>. 13 - Replace bindBlob(int index, const void* blob, int size) with bindBlob(int index, Span<const uint8_t>). 14 15 Due to implicit construction for types with data() and size() functions (actually anything 16 that std::data() and std::size() can reason about), Vector and SharedBuffer cleanly work 17 to convert to Span of the same underlying type. This means that many callers of bindBlob 18 are now simpler, as instead of doing: 19 20 bindBlob(1, foo->data(), foo->size()); 21 22 we instead do: 23 24 bindBlob(1, *foo); 25 26 There is much much more to do to take advantage of this new type, but this is 27 kept intentionally small, as the pulling back the onion can go very deep. 28 29 * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: 30 (WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexInfoTableForIDUpdate): 31 (WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexRecordsTableForIDUpdate): 32 (WebCore::IDBServer::SQLiteIDBBackingStore::addExistingIndex): 33 (WebCore::IDBServer::SQLiteIDBBackingStore::extractExistingDatabaseInfo): 34 (WebCore::IDBServer::SQLiteIDBBackingStore::createObjectStore): 35 (WebCore::IDBServer::SQLiteIDBBackingStore::createIndex): 36 (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord): 37 (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord): 38 (WebCore::IDBServer::SQLiteIDBBackingStore::keyExistsInObjectStore): 39 (WebCore::IDBServer::SQLiteIDBBackingStore::deleteRecord): 40 (WebCore::IDBServer::SQLiteIDBBackingStore::addRecord): 41 (WebCore::IDBServer::SQLiteIDBBackingStore::getRecord): 42 (WebCore::IDBServer::SQLiteIDBBackingStore::getAllObjectStoreRecords): 43 (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedGetIndexRecordForOneKey): 44 (WebCore::IDBServer::SQLiteIDBBackingStore::getCount): 45 * Modules/indexeddb/server/SQLiteIDBCursor.cpp: 46 (WebCore::IDBServer::SQLiteIDBCursor::bindArguments): 47 (WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindPreIndexStatementIfNecessary): 48 (WebCore::IDBServer::SQLiteIDBCursor::internalFetchNextRecord): 49 * loader/appcache/ApplicationCacheStorage.cpp: 50 (WebCore::ApplicationCacheStorage::store): 51 * platform/sql/SQLiteStatement.cpp: 52 (WebCore::SQLiteStatement::bindBlob): 53 (WebCore::SQLiteStatement::columnBlob): 54 (WebCore::SQLiteStatement::columnBlobAsSpan): 55 (WebCore::SQLiteStatement::columnBlobView): Deleted. 56 * platform/sql/SQLiteStatement.h: 57 (WebCore::SQLiteStatement::BlobView::BlobView): Deleted. 58 (WebCore::SQLiteStatement::BlobView::data): Deleted. 59 (WebCore::SQLiteStatement::BlobView::size): Deleted. 60 (): Deleted. 61 * workers/service/server/RegistrationDatabase.cpp: 62 (WebCore::RegistrationDatabase::doPushChanges): 63 (WebCore::RegistrationDatabase::importRecords): 64 1 65 2021-06-08 Jean-Yves Avenard <jya@apple.com> 2 66 -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
r278393 r278647 551 551 uint64_t objectStoreID = statement->columnInt64(2); 552 552 uint64_t newID = indexIDMap.get({ objectStoreID, id }); 553 auto keyPathBuffer View = statement->columnBlobView(3);553 auto keyPathBufferSpan = statement->columnBlobAsSpan(3); 554 554 bool unique = statement->columnInt(4); 555 555 bool multiEntry = statement->columnInt(5); … … 560 560 || sql->bindText(2, name) != SQLITE_OK 561 561 || sql->bindInt64(3, objectStoreID) != SQLITE_OK 562 || sql->bindBlob(4, keyPathBuffer View.data(), keyPathBufferView.size()) != SQLITE_OK562 || sql->bindBlob(4, keyPathBufferSpan) != SQLITE_OK 563 563 || sql->bindInt(5, unique) != SQLITE_OK 564 564 || sql->bindInt(6, multiEntry) != SQLITE_OK … … 614 614 uint64_t objectStoreID = statement->columnInt64(1); 615 615 uint64_t newID = indexIDMap.get({ objectStoreID, id }); 616 auto keyBuffer View = statement->columnBlobView(2);617 auto valueBuffer View = statement->columnBlobView(3);616 auto keyBufferSpan = statement->columnBlobAsSpan(2); 617 auto valueBufferSpan = statement->columnBlobAsSpan(3); 618 618 uint64_t recordID = statement->columnInt64(4); 619 619 … … 622 622 || sql->bindInt64(1, newID) != SQLITE_OK 623 623 || sql->bindInt64(2, objectStoreID) != SQLITE_OK 624 || sql->bindBlob(3, keyBuffer View.data(), keyBufferView.size()) != SQLITE_OK625 || sql->bindBlob(4, valueBuffer View.data(), valueBufferView.size()) != SQLITE_OK624 || sql->bindBlob(3, keyBufferSpan) != SQLITE_OK 625 || sql->bindBlob(4, valueBufferSpan) != SQLITE_OK 626 626 || sql->bindInt64(5, recordID) != SQLITE_OK 627 627 || sql->step() != SQLITE_DONE) { … … 699 699 || sql->bindText(2, info.name()) != SQLITE_OK 700 700 || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK 701 || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK701 || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK 702 702 || sql->bindInt(5, info.unique()) != SQLITE_OK 703 703 || sql->bindInt(6, info.multiEntry()) != SQLITE_OK … … 718 718 int result = sql->step(); 719 719 while (result == SQLITE_ROW) { 720 auto keyBuffer View = sql->columnBlobView(0);720 auto keyBufferSpan = sql->columnBlobAsSpan(0); 721 721 IDBKeyData keyData; 722 if (!deserializeIDBKeyData(keyBuffer View.data(), keyBufferView.size(), keyData)) {722 if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) { 723 723 LOG_ERROR("Unable to deserialize key data from database while getting all records"); 724 724 return false; … … 819 819 uint64_t objectStoreID = sql->columnInt64(0); 820 820 String objectStoreName = sql->columnText(1); 821 auto keyPathBuffer View = sql->columnBlobView(2);821 auto keyPathBufferSpan = sql->columnBlobAsSpan(2); 822 822 823 823 std::optional<IDBKeyPath> objectStoreKeyPath; 824 if (!deserializeIDBKeyPath(keyPathBuffer View.data(), keyPathBufferView.size(), objectStoreKeyPath)) {824 if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), objectStoreKeyPath)) { 825 825 LOG_ERROR("Unable to extract key path from database"); 826 826 return nullptr; … … 855 855 String indexName = sql->columnText(1); 856 856 uint64_t objectStoreID = sql->columnInt64(2); 857 auto keyPathBuffer View = sql->columnBlobView(3);857 auto keyPathBufferSpan = sql->columnBlobAsSpan(3); 858 858 859 859 std::optional<IDBKeyPath> indexKeyPath; 860 if (!deserializeIDBKeyPath(keyPathBuffer View.data(), keyPathBufferView.size(), indexKeyPath)) {860 if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), indexKeyPath)) { 861 861 LOG_ERROR("Unable to extract key path from database"); 862 862 return nullptr; … … 1183 1183 || sql->bindInt64(1, info.identifier()) != SQLITE_OK 1184 1184 || sql->bindText(2, info.name()) != SQLITE_OK 1185 || sql->bindBlob(3, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK1185 || sql->bindBlob(3, *keyPathBlob) != SQLITE_OK 1186 1186 || sql->bindInt(4, info.autoIncrement()) != SQLITE_OK 1187 1187 || sql->step() != SQLITE_DONE) { … … 1397 1397 || sql->bindText(2, info.name()) != SQLITE_OK 1398 1398 || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK 1399 || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK1399 || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK 1400 1400 || sql->bindInt(5, info.unique()) != SQLITE_OK 1401 1401 || sql->bindInt(6, info.multiEntry()) != SQLITE_OK … … 1471 1471 if (!sql 1472 1472 || sql->bindInt64(1, info.identifier()) != SQLITE_OK 1473 || sql->bindBlob(2, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK) {1473 || sql->bindBlob(2, *indexKeyBuffer) != SQLITE_OK) { 1474 1474 LOG_ERROR("Error checking for index record in database"); 1475 1475 return IDBError { UnknownError, "Error checking for index record in database"_s }; … … 1548 1548 || sql->bindInt64(1, indexID) != SQLITE_OK 1549 1549 || sql->bindInt64(2, objectStoreID) != SQLITE_OK 1550 || sql->bindBlob(3, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK1551 || sql->bindBlob(4, valueBuffer->data(), valueBuffer->size()) != SQLITE_OK1550 || sql->bindBlob(3, *indexKeyBuffer) != SQLITE_OK 1551 || sql->bindBlob(4, *valueBuffer) != SQLITE_OK 1552 1552 || sql->bindInt64(5, recordID) != SQLITE_OK 1553 1553 || sql->step() != SQLITE_DONE) { … … 1667 1667 if (!sql 1668 1668 || sql->bindInt64(1, objectStoreID) != SQLITE_OK 1669 || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {1669 || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) { 1670 1670 LOG_ERROR("Could not get record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 1671 1671 return IDBError { UnknownError, "Unable to check for existence of IDBKey in object store"_s }; … … 1753 1753 if (!sql 1754 1754 || sql->bindInt64(1, objectStoreID) != SQLITE_OK 1755 || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {1755 || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) { 1756 1756 LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 1757 1757 return IDBError { UnknownError, "Failed to delete record from object store"_s }; … … 1800 1800 if (!sql 1801 1801 || sql->bindInt64(1, objectStoreID) != SQLITE_OK 1802 || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK1802 || sql->bindBlob(2, *keyBuffer) != SQLITE_OK 1803 1803 || sql->step() != SQLITE_DONE) { 1804 1804 LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); … … 1971 1971 if (!sql 1972 1972 || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK 1973 || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK1974 || sql->bindBlob(3, value.data().data()->data(), value.data().data()->size()) != SQLITE_OK1973 || sql->bindBlob(2, *keyBuffer) != SQLITE_OK 1974 || sql->bindBlob(3, *value.data().data()) != SQLITE_OK 1975 1975 || sql->step() != SQLITE_DONE) { 1976 1976 LOG_ERROR("Could not put record for object store %" PRIi64 " in Records table (%i) - %s", objectStoreInfo.identifier(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); … … 1987 1987 if (!sql 1988 1988 || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK 1989 || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK1989 || sql->bindBlob(2, *keyBuffer) != SQLITE_OK 1990 1990 || sql->step() != SQLITE_DONE) { 1991 1991 LOG_ERROR("Indexing new object store record failed, but unable to remove the object store record itself"); … … 2172 2172 if (!sql 2173 2173 || sql->bindInt64(1, objectStoreID) != SQLITE_OK 2174 || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK2175 || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {2174 || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK 2175 || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) { 2176 2176 LOG_ERROR("Could not get key range record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 2177 2177 return IDBError { UnknownError, "Failed to look up record in object store by key range"_s }; … … 2289 2289 if (!sql 2290 2290 || sql->bindInt64(1, getAllRecordsData.objectStoreIdentifier) != SQLITE_OK 2291 || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK2292 || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {2291 || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK 2292 || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) { 2293 2293 LOG_ERROR("Could not get key range record from object store %" PRIi64 " from Records table (%i) - %s", getAllRecordsData.objectStoreIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 2294 2294 return IDBError { UnknownError, "Failed to look up record in object store by key range"_s }; … … 2309 2309 2310 2310 while (sqlResult == SQLITE_ROW && returnedResults < targetResults) { 2311 auto keyBuffer View = sql->columnBlobView(0);2311 auto keyBufferSpan = sql->columnBlobAsSpan(0); 2312 2312 IDBKeyData keyData; 2313 if (!deserializeIDBKeyData(keyBuffer View.data(), keyBufferView.size(), keyData)) {2313 if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) { 2314 2314 LOG_ERROR("Unable to deserialize key data from database while getting all records"); 2315 2315 return IDBError { UnknownError, "Unable to deserialize key data while getting all records"_s }; … … 2451 2451 if (!sql 2452 2452 || sql->bindInt64(1, indexID) != SQLITE_OK 2453 || sql->bindBlob(2, buffer->data(), buffer->size()) != SQLITE_OK) {2453 || sql->bindBlob(2, *buffer) != SQLITE_OK) { 2454 2454 LOG_ERROR("Unable to lookup index record in database"); 2455 2455 return IDBError { UnknownError, "Unable to lookup index record in database"_s }; … … 2466 2466 2467 2467 IDBKeyData objectStoreKey; 2468 auto key View = sql->columnBlobView(0);2469 2470 if (!deserializeIDBKeyData(key View.data(), keyView.size(), objectStoreKey)) {2468 auto keySpan = sql->columnBlobAsSpan(0); 2469 2470 if (!deserializeIDBKeyData(keySpan.data(), keySpan.size(), objectStoreKey)) { 2471 2471 LOG_ERROR("Unable to deserialize key looking up index record in database"); 2472 2472 return IDBError { UnknownError, "Unable to deserialize key looking up index record in database"_s }; … … 2533 2533 if (!statement 2534 2534 || statement->bindInt64(1, objectStoreIdentifier) != SQLITE_OK 2535 || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK2536 || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {2535 || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK 2536 || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) { 2537 2537 LOG_ERROR("Could not count records in object store %" PRIi64 " from Records table (%i) - %s", objectStoreIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 2538 2538 return IDBError { UnknownError, "Unable to count records in object store due to binding failure"_s }; … … 2550 2550 if (!statement 2551 2551 || statement->bindInt64(1, indexIdentifier) != SQLITE_OK 2552 || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK2553 || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {2552 || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK 2553 || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) { 2554 2554 LOG_ERROR("Could not count records with index %" PRIi64 " from IndexRecords table (%i) - %s", indexIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg()); 2555 2555 return IDBError { UnknownError, "Unable to count records for index due to binding failure"_s }; -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp
r278253 r278647 271 271 272 272 RefPtr<SharedBuffer> buffer = serializeIDBKeyData(m_currentLowerKey); 273 if (m_statement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {273 if (m_statement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) { 274 274 LOG_ERROR("Could not create cursor statement (lower key)"); 275 275 return false; … … 277 277 278 278 buffer = serializeIDBKeyData(m_currentUpperKey); 279 if (m_statement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {279 if (m_statement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) { 280 280 LOG_ERROR("Could not create cursor statement (upper key)"); 281 281 return false; … … 317 317 318 318 RefPtr<SharedBuffer> buffer = serializeIDBKeyData(key); 319 if (m_preIndexStatement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {319 if (m_preIndexStatement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) { 320 320 LOG_ERROR("Could not bind id argument to pre statement (key)"); 321 321 return false; … … 323 323 324 324 buffer = serializeIDBKeyData(m_currentIndexRecordValue); 325 if (m_preIndexStatement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {325 if (m_preIndexStatement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) { 326 326 LOG_ERROR("Could not bind id argument to pre statement (value)"); 327 327 return false; … … 508 508 record.rowID = statement->columnInt64(0); 509 509 ASSERT(record.rowID); 510 auto keyData View = statement->columnBlobView(1);511 512 if (!deserializeIDBKeyData(keyData View.data(), keyDataView.size(), record.record.key)) {510 auto keyDataSpan = statement->columnBlobAsSpan(1); 511 512 if (!deserializeIDBKeyData(keyDataSpan.data(), keyDataSpan.size(), record.record.key)) { 513 513 LOG_ERROR("Unable to deserialize key data from database while advancing cursor"); 514 514 markAsErrored(record); … … 545 545 546 546 if (!m_cachedObjectStoreStatement 547 || m_cachedObjectStoreStatement->bindBlob(1, keyData .data(), keyData.size()) != SQLITE_OK547 || m_cachedObjectStoreStatement->bindBlob(1, keyData) != SQLITE_OK 548 548 || m_cachedObjectStoreStatement->bindInt64(2, m_objectStoreID) != SQLITE_OK) { 549 549 LOG_ERROR("Could not create index cursor statement into object store records (%i) '%s'", database.lastError(), database.lastErrorMsg()); -
trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp
r278253 r278647 816 816 } else { 817 817 if (resource->data().size()) 818 dataStatement->bindBlob(1, resource->data() .data(), resource->data().size());818 dataStatement->bindBlob(1, resource->data()); 819 819 } 820 820 -
trunk/Source/WebCore/platform/sql/SQLiteStatement.cpp
r278619 r278647 86 86 } 87 87 88 int SQLiteStatement::bindBlob(int index, const void* blob, int size)89 { 90 ASSERT(index > 0); 91 ASSERT(static_cast<unsigned>(index) <= bindParameterCount()); 92 ASSERT(blob || !size);93 ASSERT( size>= 0);94 95 return sqlite3_bind_blob(m_statement, index, blob , size, SQLITE_TRANSIENT);88 int SQLiteStatement::bindBlob(int index, Span<const uint8_t> blob) 89 { 90 ASSERT(index > 0); 91 ASSERT(static_cast<unsigned>(index) <= bindParameterCount()); 92 ASSERT(blob.data() || !blob.size()); 93 ASSERT(blob.size() >= 0); 94 95 return sqlite3_bind_blob(m_statement, index, blob.data(), blob.size(), SQLITE_TRANSIENT); 96 96 } 97 97 … … 108 108 characters = upconvertedCharacters; 109 109 110 return bindBlob(index, characters, text.length() * sizeof(UChar));110 return bindBlob(index, Span { reinterpret_cast<const uint8_t*>(characters), text.length() * sizeof(UChar) }); 111 111 } 112 112 … … 283 283 Vector<uint8_t> SQLiteStatement::columnBlob(int col) 284 284 { 285 auto blobView = columnBlobView(col);286 return { blobView.data(), blobView.size() };287 } 288 289 auto SQLiteStatement::columnBlobView(int col) -> BlobView 285 auto span = columnBlobAsSpan(col); 286 return { span.data(), span.size() }; 287 } 288 289 Span<const uint8_t> SQLiteStatement::columnBlobAsSpan(int col) 290 290 { 291 291 ASSERT(col >= 0); -
trunk/Source/WebCore/platform/sql/SQLiteStatement.h
r277768 r278647 28 28 #include "SQLValue.h" 29 29 #include "SQLiteDatabase.h" 30 #include <wtf/Span.h> 30 31 31 32 struct sqlite3_stmt; … … 39 40 WEBCORE_EXPORT SQLiteStatement(SQLiteStatement&&); 40 41 41 WEBCORE_EXPORT int bindBlob(int index, const void* blob, int size);42 WEBCORE_EXPORT int bindBlob(int index, Span<const uint8_t>); 42 43 WEBCORE_EXPORT int bindBlob(int index, const String&); 43 44 WEBCORE_EXPORT int bindText(int index, StringView); … … 73 74 WEBCORE_EXPORT Vector<uint8_t> columnBlob(int col); 74 75 75 class BlobView { 76 public: 77 BlobView() = default; 78 BlobView(const uint8_t* data, size_t size) 79 : m_data(data) 80 , m_size(size) 81 { } 82 83 const uint8_t* data() { return m_data; } 84 size_t size() { return m_size; } 85 86 private: 87 const uint8_t* m_data { nullptr }; 88 const size_t m_size { 0 }; 89 }; 90 // The returned BlobView stays valid until the next step() / reset() or destruction of the statement. 91 BlobView columnBlobView(int col); 76 // The returned Span stays valid until the next step() / reset() or destruction of the statement. 77 Span<const uint8_t> columnBlobAsSpan(int col); 92 78 93 79 SQLiteDatabase& database() { return m_database; } -
trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp
r278253 r278647 460 460 || insertStatement->bindText(7, data.scriptURL.string()) != SQLITE_OK 461 461 || insertStatement->bindText(8, workerTypeToString(data.workerType)) != SQLITE_OK 462 || insertStatement->bindBlob(9, cspEncoder.buffer(), cspEncoder.bufferSize()) != SQLITE_OK462 || insertStatement->bindBlob(9, Span { cspEncoder.buffer(), cspEncoder.bufferSize() }) != SQLITE_OK 463 463 || insertStatement->bindText(10, data.referrerPolicy) != SQLITE_OK 464 || insertStatement->bindBlob(11, scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize()) != SQLITE_OK465 || insertStatement->bindBlob(12, certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize()) != SQLITE_OK464 || insertStatement->bindBlob(11, Span { scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize() }) != SQLITE_OK 465 || insertStatement->bindBlob(12, Span { certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize() }) != SQLITE_OK 466 466 || insertStatement->step() != SQLITE_DONE) { 467 467 RELEASE_LOG_ERROR(ServiceWorker, "Failed to store registration data into records table (%i) - %s", m_database->lastError(), m_database->lastErrorMsg()); … … 516 516 517 517 std::optional<ContentSecurityPolicyResponseHeaders> contentSecurityPolicy; 518 auto contentSecurityPolicyData View = sql->columnBlobView(8);519 if (contentSecurityPolicyData View.size()) {520 WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyData View.data(), contentSecurityPolicyDataView.size());518 auto contentSecurityPolicyDataSpan = sql->columnBlobAsSpan(8); 519 if (contentSecurityPolicyDataSpan.size()) { 520 WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyDataSpan.data(), contentSecurityPolicyDataSpan.size()); 521 521 cspDecoder >> contentSecurityPolicy; 522 522 if (!contentSecurityPolicy) { … … 529 529 530 530 HashMap<URL, ServiceWorkerContextData::ImportedScript> scriptResourceMap; 531 auto scriptResourceMapData View = sql->columnBlobView(10);532 if (scriptResourceMapData View.size()) {533 WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapData View.data(), scriptResourceMapDataView.size());531 auto scriptResourceMapDataSpan = sql->columnBlobAsSpan(10); 532 if (scriptResourceMapDataSpan.size()) { 533 WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapDataSpan.data(), scriptResourceMapDataSpan.size()); 534 534 std::optional<HashMap<URL, ImportedScriptAttributes>> scriptResourceMapWithoutScripts; 535 535 scriptResourceMapDecoder >> scriptResourceMapWithoutScripts; … … 541 541 } 542 542 543 auto certificateInfoData View = sql->columnBlobView(11);543 auto certificateInfoDataSpan = sql->columnBlobAsSpan(11); 544 544 std::optional<CertificateInfo> certificateInfo; 545 545 546 WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoData View.data(), certificateInfoDataView.size());546 WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoDataSpan.data(), certificateInfoDataSpan.size()); 547 547 certificateInfoDecoder >> certificateInfo; 548 548 if (!certificateInfo) { -
trunk/Source/WebKit/ChangeLog
r278646 r278647 1 2021-06-08 Sam Weinig <weinig@apple.com> 2 3 Adopt WTF::Span in SQLiteStatement 4 https://bugs.webkit.org/show_bug.cgi?id=226773 5 6 Reviewed by Alex Christensen. 7 8 * UIProcess/API/glib/IconDatabase.cpp: 9 (WebKit::IconDatabase::addIcon): 10 Adopt new bindBlob() signature. 11 1 12 2021-06-08 Jean-Yves Avenard <jya@apple.com> 2 13 -
trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp
r278532 r278647 399 399 400 400 auto iconID = m_db.lastInsertRowID(); 401 if (m_addIconDataStatement->bindInt64(1, iconID) != SQLITE_OK || m_addIconDataStatement->bindBlob(2, iconData .data(), iconData.size()) != SQLITE_OK) {401 if (m_addIconDataStatement->bindInt64(1, iconID) != SQLITE_OK || m_addIconDataStatement->bindBlob(2, iconData) != SQLITE_OK) { 402 402 LOG_ERROR("IconDatabase::addIcon failed: %s", m_db.lastErrorMsg()); 403 403 return std::nullopt;
Note:
See TracChangeset
for help on using the changeset viewer.