⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278647 in webkit


Ignore:
Timestamp:
Jun 8, 2021, 10:03:32 PM (5 years ago)
Author:
weinig@apple.com
Message:

Adopt WTF::Span in SQLiteStatement
https://bugs.webkit.org/show_bug.cgi?id=226773

Reviewed by Alex Christensen.

Source/WebCore:

Do some initial adoption of WTF::Span by adopting it in SQLiteStatement.

  • Removes class BlobView.
  • Renames columnBlobView to columnBlobAsSpan() (mirrors columnBlobAsString() naming) and have it return a Span<const uint8_t>.
  • Replace bindBlob(int index, const void* blob, int size) with bindBlob(int index, Span<const uint8_t>).

Due to implicit construction for types with data() and size() functions (actually anything
that std::data() and std::size() can reason about), Vector and SharedBuffer cleanly work
to convert to Span of the same underlying type. This means that many callers of bindBlob
are now simpler, as instead of doing:

bindBlob(1, foo->data(), foo->size());

we instead do:

bindBlob(1, *foo);

There is much much more to do to take advantage of this new type, but this is
kept intentionally small, as the pulling back the onion can go very deep.

  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexInfoTableForIDUpdate):
(WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexRecordsTableForIDUpdate):
(WebCore::IDBServer::SQLiteIDBBackingStore::addExistingIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::extractExistingDatabaseInfo):
(WebCore::IDBServer::SQLiteIDBBackingStore::createObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::keyExistsInObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getAllObjectStoreRecords):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedGetIndexRecordForOneKey):
(WebCore::IDBServer::SQLiteIDBBackingStore::getCount):

  • Modules/indexeddb/server/SQLiteIDBCursor.cpp:

(WebCore::IDBServer::SQLiteIDBCursor::bindArguments):
(WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindPreIndexStatementIfNecessary):
(WebCore::IDBServer::SQLiteIDBCursor::internalFetchNextRecord):

  • loader/appcache/ApplicationCacheStorage.cpp:

(WebCore::ApplicationCacheStorage::store):

  • platform/sql/SQLiteStatement.cpp:

(WebCore::SQLiteStatement::bindBlob):
(WebCore::SQLiteStatement::columnBlob):
(WebCore::SQLiteStatement::columnBlobAsSpan):
(WebCore::SQLiteStatement::columnBlobView): Deleted.

  • platform/sql/SQLiteStatement.h:

(WebCore::SQLiteStatement::BlobView::BlobView): Deleted.
(WebCore::SQLiteStatement::BlobView::data): Deleted.
(WebCore::SQLiteStatement::BlobView::size): Deleted.
(): Deleted.

  • workers/service/server/RegistrationDatabase.cpp:

(WebCore::RegistrationDatabase::doPushChanges):
(WebCore::RegistrationDatabase::importRecords):

Source/WebKit:

  • UIProcess/API/glib/IconDatabase.cpp:

(WebKit::IconDatabase::addIcon):
Adopt new bindBlob() signature.

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278646 r278647  
     12021-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
    1652021-06-08  Jean-Yves Avenard  <jya@apple.com>
    266
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r278393 r278647  
    551551            uint64_t objectStoreID = statement->columnInt64(2);
    552552            uint64_t newID = indexIDMap.get({ objectStoreID, id });
    553             auto keyPathBufferView = statement->columnBlobView(3);
     553            auto keyPathBufferSpan = statement->columnBlobAsSpan(3);
    554554            bool unique = statement->columnInt(4);
    555555            bool multiEntry = statement->columnInt(5);
     
    560560                || sql->bindText(2, name) != SQLITE_OK
    561561                || sql->bindInt64(3, objectStoreID) != SQLITE_OK
    562                 || sql->bindBlob(4, keyPathBufferView.data(), keyPathBufferView.size()) != SQLITE_OK
     562                || sql->bindBlob(4, keyPathBufferSpan) != SQLITE_OK
    563563                || sql->bindInt(5, unique) != SQLITE_OK
    564564                || sql->bindInt(6, multiEntry) != SQLITE_OK
     
    614614            uint64_t objectStoreID = statement->columnInt64(1);
    615615            uint64_t newID = indexIDMap.get({ objectStoreID, id });
    616             auto keyBufferView = statement->columnBlobView(2);
    617             auto valueBufferView = statement->columnBlobView(3);
     616            auto keyBufferSpan = statement->columnBlobAsSpan(2);
     617            auto valueBufferSpan = statement->columnBlobAsSpan(3);
    618618            uint64_t recordID = statement->columnInt64(4);
    619619
     
    622622                || sql->bindInt64(1, newID) != SQLITE_OK
    623623                || sql->bindInt64(2, objectStoreID) != SQLITE_OK
    624                 || sql->bindBlob(3, keyBufferView.data(), keyBufferView.size()) != SQLITE_OK
    625                 || sql->bindBlob(4, valueBufferView.data(), valueBufferView.size()) != SQLITE_OK
     624                || sql->bindBlob(3, keyBufferSpan) != SQLITE_OK
     625                || sql->bindBlob(4, valueBufferSpan) != SQLITE_OK
    626626                || sql->bindInt64(5, recordID) != SQLITE_OK
    627627                || sql->step() != SQLITE_DONE) {
     
    699699            || sql->bindText(2, info.name()) != SQLITE_OK
    700700            || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK
    701             || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
     701            || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK
    702702            || sql->bindInt(5, info.unique()) != SQLITE_OK
    703703            || sql->bindInt(6, info.multiEntry()) != SQLITE_OK
     
    718718        int result = sql->step();
    719719        while (result == SQLITE_ROW) {
    720             auto keyBufferView = sql->columnBlobView(0);
     720            auto keyBufferSpan = sql->columnBlobAsSpan(0);
    721721            IDBKeyData keyData;
    722             if (!deserializeIDBKeyData(keyBufferView.data(), keyBufferView.size(), keyData)) {
     722            if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) {
    723723                LOG_ERROR("Unable to deserialize key data from database while getting all records");
    724724                return false;
     
    819819            uint64_t objectStoreID = sql->columnInt64(0);
    820820            String objectStoreName = sql->columnText(1);
    821             auto keyPathBufferView = sql->columnBlobView(2);
     821            auto keyPathBufferSpan = sql->columnBlobAsSpan(2);
    822822
    823823            std::optional<IDBKeyPath> objectStoreKeyPath;
    824             if (!deserializeIDBKeyPath(keyPathBufferView.data(), keyPathBufferView.size(), objectStoreKeyPath)) {
     824            if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), objectStoreKeyPath)) {
    825825                LOG_ERROR("Unable to extract key path from database");
    826826                return nullptr;
     
    855855            String indexName = sql->columnText(1);
    856856            uint64_t objectStoreID = sql->columnInt64(2);
    857             auto keyPathBufferView = sql->columnBlobView(3);
     857            auto keyPathBufferSpan = sql->columnBlobAsSpan(3);
    858858
    859859            std::optional<IDBKeyPath> indexKeyPath;
    860             if (!deserializeIDBKeyPath(keyPathBufferView.data(), keyPathBufferView.size(), indexKeyPath)) {
     860            if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), indexKeyPath)) {
    861861                LOG_ERROR("Unable to extract key path from database");
    862862                return nullptr;
     
    11831183            || sql->bindInt64(1, info.identifier()) != SQLITE_OK
    11841184            || sql->bindText(2, info.name()) != SQLITE_OK
    1185             || sql->bindBlob(3, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
     1185            || sql->bindBlob(3, *keyPathBlob) != SQLITE_OK
    11861186            || sql->bindInt(4, info.autoIncrement()) != SQLITE_OK
    11871187            || sql->step() != SQLITE_DONE) {
     
    13971397            || sql->bindText(2, info.name()) != SQLITE_OK
    13981398            || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK
    1399             || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
     1399            || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK
    14001400            || sql->bindInt(5, info.unique()) != SQLITE_OK
    14011401            || sql->bindInt(6, info.multiEntry()) != SQLITE_OK
     
    14711471    if (!sql
    14721472        || sql->bindInt64(1, info.identifier()) != SQLITE_OK
    1473         || sql->bindBlob(2, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK) {
     1473        || sql->bindBlob(2, *indexKeyBuffer) != SQLITE_OK) {
    14741474        LOG_ERROR("Error checking for index record in database");
    14751475        return IDBError { UnknownError, "Error checking for index record in database"_s };
     
    15481548            || sql->bindInt64(1, indexID) != SQLITE_OK
    15491549            || sql->bindInt64(2, objectStoreID) != SQLITE_OK
    1550             || sql->bindBlob(3, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK
    1551             || sql->bindBlob(4, valueBuffer->data(), valueBuffer->size()) != SQLITE_OK
     1550            || sql->bindBlob(3, *indexKeyBuffer) != SQLITE_OK
     1551            || sql->bindBlob(4, *valueBuffer) != SQLITE_OK
    15521552            || sql->bindInt64(5, recordID) != SQLITE_OK
    15531553            || sql->step() != SQLITE_DONE) {
     
    16671667    if (!sql
    16681668        || sql->bindInt64(1, objectStoreID) != SQLITE_OK
    1669         || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {
     1669        || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) {
    16701670        LOG_ERROR("Could not get record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
    16711671        return IDBError { UnknownError, "Unable to check for existence of IDBKey in object store"_s };
     
    17531753        if (!sql
    17541754            || sql->bindInt64(1, objectStoreID) != SQLITE_OK
    1755             || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {
     1755            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) {
    17561756            LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
    17571757            return IDBError { UnknownError, "Failed to delete record from object store"_s };
     
    18001800        if (!sql
    18011801            || sql->bindInt64(1, objectStoreID) != SQLITE_OK
    1802             || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
     1802            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
    18031803            || sql->step() != SQLITE_DONE) {
    18041804            LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
     
    19711971        if (!sql
    19721972            || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK
    1973             || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
    1974             || sql->bindBlob(3, value.data().data()->data(), value.data().data()->size()) != SQLITE_OK
     1973            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
     1974            || sql->bindBlob(3, *value.data().data()) != SQLITE_OK
    19751975            || sql->step() != SQLITE_DONE) {
    19761976            LOG_ERROR("Could not put record for object store %" PRIi64 " in Records table (%i) - %s", objectStoreInfo.identifier(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
     
    19871987        if (!sql
    19881988            || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK
    1989             || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
     1989            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
    19901990            || sql->step() != SQLITE_DONE) {
    19911991            LOG_ERROR("Indexing new object store record failed, but unable to remove the object store record itself");
     
    21722172        if (!sql
    21732173            || sql->bindInt64(1, objectStoreID) != SQLITE_OK
    2174             || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
    2175             || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
     2174            || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK
     2175            || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) {
    21762176            LOG_ERROR("Could not get key range record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
    21772177            return IDBError { UnknownError, "Failed to look up record in object store by key range"_s };
     
    22892289    if (!sql
    22902290        || sql->bindInt64(1, getAllRecordsData.objectStoreIdentifier) != SQLITE_OK
    2291         || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
    2292         || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
     2291        || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK
     2292        || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) {
    22932293        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());
    22942294        return IDBError { UnknownError, "Failed to look up record in object store by key range"_s };
     
    23092309
    23102310    while (sqlResult == SQLITE_ROW && returnedResults < targetResults) {
    2311         auto keyBufferView = sql->columnBlobView(0);
     2311        auto keyBufferSpan = sql->columnBlobAsSpan(0);
    23122312        IDBKeyData keyData;
    2313         if (!deserializeIDBKeyData(keyBufferView.data(), keyBufferView.size(), keyData)) {
     2313        if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) {
    23142314            LOG_ERROR("Unable to deserialize key data from database while getting all records");
    23152315            return IDBError { UnknownError, "Unable to deserialize key data while getting all records"_s };
     
    24512451    if (!sql
    24522452        || sql->bindInt64(1, indexID) != SQLITE_OK
    2453         || sql->bindBlob(2, buffer->data(), buffer->size()) != SQLITE_OK) {
     2453        || sql->bindBlob(2, *buffer) != SQLITE_OK) {
    24542454        LOG_ERROR("Unable to lookup index record in database");
    24552455        return IDBError { UnknownError, "Unable to lookup index record in database"_s };
     
    24662466
    24672467    IDBKeyData objectStoreKey;
    2468     auto keyView = sql->columnBlobView(0);
    2469 
    2470     if (!deserializeIDBKeyData(keyView.data(), keyView.size(), objectStoreKey)) {
     2468    auto keySpan = sql->columnBlobAsSpan(0);
     2469
     2470    if (!deserializeIDBKeyData(keySpan.data(), keySpan.size(), objectStoreKey)) {
    24712471        LOG_ERROR("Unable to deserialize key looking up index record in database");
    24722472        return IDBError { UnknownError, "Unable to deserialize key looking up index record in database"_s };
     
    25332533        if (!statement
    25342534            || statement->bindInt64(1, objectStoreIdentifier) != SQLITE_OK
    2535             || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
    2536             || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
     2535            || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK
     2536            || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) {
    25372537            LOG_ERROR("Could not count records in object store %" PRIi64 " from Records table (%i) - %s", objectStoreIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
    25382538            return IDBError { UnknownError, "Unable to count records in object store due to binding failure"_s };
     
    25502550        if (!statement
    25512551            || statement->bindInt64(1, indexIdentifier) != SQLITE_OK
    2552             || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
    2553             || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
     2552            || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK
     2553            || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) {
    25542554            LOG_ERROR("Could not count records with index %" PRIi64 " from IndexRecords table (%i) - %s", indexIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
    25552555            return IDBError { UnknownError, "Unable to count records for index due to binding failure"_s };
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp

    r278253 r278647  
    271271
    272272    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) {
    274274        LOG_ERROR("Could not create cursor statement (lower key)");
    275275        return false;
     
    277277
    278278    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) {
    280280        LOG_ERROR("Could not create cursor statement (upper key)");
    281281        return false;
     
    317317
    318318    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) {
    320320        LOG_ERROR("Could not bind id argument to pre statement (key)");
    321321        return false;
     
    323323
    324324    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) {
    326326        LOG_ERROR("Could not bind id argument to pre statement (value)");
    327327        return false;
     
    508508    record.rowID = statement->columnInt64(0);
    509509    ASSERT(record.rowID);
    510     auto keyDataView = statement->columnBlobView(1);
    511 
    512     if (!deserializeIDBKeyData(keyDataView.data(), keyDataView.size(), record.record.key)) {
     510    auto keyDataSpan = statement->columnBlobAsSpan(1);
     511
     512    if (!deserializeIDBKeyData(keyDataSpan.data(), keyDataSpan.size(), record.record.key)) {
    513513        LOG_ERROR("Unable to deserialize key data from database while advancing cursor");
    514514        markAsErrored(record);
     
    545545
    546546        if (!m_cachedObjectStoreStatement
    547             || m_cachedObjectStoreStatement->bindBlob(1, keyData.data(), keyData.size()) != SQLITE_OK
     547            || m_cachedObjectStoreStatement->bindBlob(1, keyData) != SQLITE_OK
    548548            || m_cachedObjectStoreStatement->bindInt64(2, m_objectStoreID) != SQLITE_OK) {
    549549            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  
    816816    } else {
    817817        if (resource->data().size())
    818             dataStatement->bindBlob(1, resource->data().data(), resource->data().size());
     818            dataStatement->bindBlob(1, resource->data());
    819819    }
    820820   
  • trunk/Source/WebCore/platform/sql/SQLiteStatement.cpp

    r278619 r278647  
    8686}
    8787
    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);
     88int 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);
    9696}
    9797
     
    108108        characters = upconvertedCharacters;
    109109
    110     return bindBlob(index, characters, text.length() * sizeof(UChar));
     110    return bindBlob(index, Span { reinterpret_cast<const uint8_t*>(characters), text.length() * sizeof(UChar) });
    111111}
    112112
     
    283283Vector<uint8_t> SQLiteStatement::columnBlob(int col)
    284284{
    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
     289Span<const uint8_t> SQLiteStatement::columnBlobAsSpan(int col)
    290290{
    291291    ASSERT(col >= 0);
  • trunk/Source/WebCore/platform/sql/SQLiteStatement.h

    r277768 r278647  
    2828#include "SQLValue.h"
    2929#include "SQLiteDatabase.h"
     30#include <wtf/Span.h>
    3031
    3132struct sqlite3_stmt;
     
    3940    WEBCORE_EXPORT SQLiteStatement(SQLiteStatement&&);
    4041   
    41     WEBCORE_EXPORT int bindBlob(int index, const void* blob, int size);
     42    WEBCORE_EXPORT int bindBlob(int index, Span<const uint8_t>);
    4243    WEBCORE_EXPORT int bindBlob(int index, const String&);
    4344    WEBCORE_EXPORT int bindText(int index, StringView);
     
    7374    WEBCORE_EXPORT Vector<uint8_t> columnBlob(int col);
    7475
    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);
    9278
    9379    SQLiteDatabase& database() { return m_database; }
  • trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp

    r278253 r278647  
    460460            || insertStatement->bindText(7, data.scriptURL.string()) != SQLITE_OK
    461461            || insertStatement->bindText(8, workerTypeToString(data.workerType)) != SQLITE_OK
    462             || insertStatement->bindBlob(9, cspEncoder.buffer(), cspEncoder.bufferSize()) != SQLITE_OK
     462            || insertStatement->bindBlob(9, Span { cspEncoder.buffer(), cspEncoder.bufferSize() }) != SQLITE_OK
    463463            || insertStatement->bindText(10, data.referrerPolicy) != SQLITE_OK
    464             || insertStatement->bindBlob(11, scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize()) != SQLITE_OK
    465             || insertStatement->bindBlob(12, certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize()) != SQLITE_OK
     464            || insertStatement->bindBlob(11, Span { scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize() }) != SQLITE_OK
     465            || insertStatement->bindBlob(12, Span { certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize() }) != SQLITE_OK
    466466            || insertStatement->step() != SQLITE_DONE) {
    467467            RELEASE_LOG_ERROR(ServiceWorker, "Failed to store registration data into records table (%i) - %s", m_database->lastError(), m_database->lastErrorMsg());
     
    516516
    517517        std::optional<ContentSecurityPolicyResponseHeaders> contentSecurityPolicy;
    518         auto contentSecurityPolicyDataView = sql->columnBlobView(8);
    519         if (contentSecurityPolicyDataView.size()) {
    520             WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyDataView.data(), contentSecurityPolicyDataView.size());
     518        auto contentSecurityPolicyDataSpan = sql->columnBlobAsSpan(8);
     519        if (contentSecurityPolicyDataSpan.size()) {
     520            WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyDataSpan.data(), contentSecurityPolicyDataSpan.size());
    521521            cspDecoder >> contentSecurityPolicy;
    522522            if (!contentSecurityPolicy) {
     
    529529
    530530        HashMap<URL, ServiceWorkerContextData::ImportedScript> scriptResourceMap;
    531         auto scriptResourceMapDataView = sql->columnBlobView(10);
    532         if (scriptResourceMapDataView.size()) {
    533             WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapDataView.data(), scriptResourceMapDataView.size());
     531        auto scriptResourceMapDataSpan = sql->columnBlobAsSpan(10);
     532        if (scriptResourceMapDataSpan.size()) {
     533            WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapDataSpan.data(), scriptResourceMapDataSpan.size());
    534534            std::optional<HashMap<URL, ImportedScriptAttributes>> scriptResourceMapWithoutScripts;
    535535            scriptResourceMapDecoder >> scriptResourceMapWithoutScripts;
     
    541541        }
    542542
    543         auto certificateInfoDataView = sql->columnBlobView(11);
     543        auto certificateInfoDataSpan = sql->columnBlobAsSpan(11);
    544544        std::optional<CertificateInfo> certificateInfo;
    545545
    546         WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoDataView.data(), certificateInfoDataView.size());
     546        WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoDataSpan.data(), certificateInfoDataSpan.size());
    547547        certificateInfoDecoder >> certificateInfo;
    548548        if (!certificateInfo) {
  • trunk/Source/WebKit/ChangeLog

    r278646 r278647  
     12021-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
    1122021-06-08  Jean-Yves Avenard  <jya@apple.com>
    213
  • trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp

    r278532 r278647  
    399399
    400400    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) {
    402402        LOG_ERROR("IconDatabase::addIcon failed: %s", m_db.lastErrorMsg());
    403403        return std::nullopt;
Note: See TracChangeset for help on using the changeset viewer.