diff options
Diffstat (limited to 'WebCore/storage/IDBCursorBackendImpl.cpp')
-rw-r--r-- | WebCore/storage/IDBCursorBackendImpl.cpp | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/WebCore/storage/IDBCursorBackendImpl.cpp b/WebCore/storage/IDBCursorBackendImpl.cpp index 4cbac0e..3a4dd67 100644 --- a/WebCore/storage/IDBCursorBackendImpl.cpp +++ b/WebCore/storage/IDBCursorBackendImpl.cpp @@ -32,6 +32,7 @@ #include "IDBDatabaseBackendImpl.h" #include "IDBDatabaseError.h" #include "IDBDatabaseException.h" +#include "IDBIndexBackendImpl.h" #include "IDBKeyRange.h" #include "IDBObjectStoreBackendImpl.h" #include "IDBRequest.h" @@ -46,6 +47,17 @@ IDBCursorBackendImpl::IDBCursorBackendImpl(PassRefPtr<IDBObjectStoreBackendImpl> , m_keyRange(keyRange) , m_direction(direction) , m_query(query) + , m_isSerializedScriptValueCursor(true) +{ + loadCurrentRow(); +} + +IDBCursorBackendImpl::IDBCursorBackendImpl(PassRefPtr<IDBIndexBackendImpl> idbIndex, PassRefPtr<IDBKeyRange> keyRange, IDBCursor::Direction direction, PassOwnPtr<SQLiteStatement> query, bool isSerializedScriptValueCursor) + : m_idbIndex(idbIndex) + , m_keyRange(keyRange) + , m_direction(direction) + , m_query(query) + , m_isSerializedScriptValueCursor(isSerializedScriptValueCursor) { loadCurrentRow(); } @@ -65,13 +77,19 @@ PassRefPtr<IDBKey> IDBCursorBackendImpl::key() const return m_currentKey; } -PassRefPtr<SerializedScriptValue> IDBCursorBackendImpl::value() const +PassRefPtr<IDBAny> IDBCursorBackendImpl::value() const { - return m_currentValue; + if (m_isSerializedScriptValueCursor) + return IDBAny::create(m_currentSerializedScriptValue.get()); + return IDBAny::create(m_currentIDBKeyValue.get()); } void IDBCursorBackendImpl::update(PassRefPtr<SerializedScriptValue> prpValue, PassRefPtr<IDBCallbacks> callbacks) { + // FIXME: This method doesn't update indexes. It's dangerous to call in its current state. + callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Not implemented.")); + return; + RefPtr<SerializedScriptValue> value = prpValue; if (!m_query || m_currentId == InvalidId) { @@ -81,7 +99,7 @@ void IDBCursorBackendImpl::update(PassRefPtr<SerializedScriptValue> prpValue, Pa } String sql = "UPDATE ObjectStoreData SET value = ? WHERE id = ?"; - SQLiteStatement updateQuery(m_idbObjectStore->database()->sqliteDatabase(), sql); + SQLiteStatement updateQuery(database()->sqliteDatabase(), sql); bool ok = updateQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. @@ -90,7 +108,8 @@ void IDBCursorBackendImpl::update(PassRefPtr<SerializedScriptValue> prpValue, Pa ok = updateQuery.step() == SQLResultDone; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. - m_currentValue = value.release(); + if (m_isSerializedScriptValueCursor) + m_currentSerializedScriptValue = value.release(); callbacks->onSuccess(); } @@ -102,7 +121,8 @@ void IDBCursorBackendImpl::continueFunction(PassRefPtr<IDBKey> prpKey, PassRefPt m_query = 0; m_currentId = InvalidId; m_currentKey = 0; - m_currentValue = 0; + m_currentSerializedScriptValue = 0; + m_currentIDBKeyValue = 0; callbacks->onSuccess(); return; } @@ -126,6 +146,10 @@ void IDBCursorBackendImpl::continueFunction(PassRefPtr<IDBKey> prpKey, PassRefPt void IDBCursorBackendImpl::remove(PassRefPtr<IDBCallbacks> callbacks) { + // FIXME: This method doesn't update indexes. It's dangerous to call in its current state. + callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Not implemented.")); + return; + if (!m_query || m_currentId == InvalidId) { // FIXME: Use the proper error code when it's specced. callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Operation not possible.")); @@ -133,7 +157,7 @@ void IDBCursorBackendImpl::remove(PassRefPtr<IDBCallbacks> callbacks) } String sql = "DELETE FROM ObjectStoreData WHERE id = ?"; - SQLiteStatement deleteQuery(m_idbObjectStore->database()->sqliteDatabase(), sql); + SQLiteStatement deleteQuery(database()->sqliteDatabase(), sql); bool ok = deleteQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. @@ -142,8 +166,8 @@ void IDBCursorBackendImpl::remove(PassRefPtr<IDBCallbacks> callbacks) ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. m_currentId = InvalidId; - m_currentKey = 0; - m_currentValue = 0; + m_currentSerializedScriptValue = 0; + m_currentIDBKeyValue = 0; callbacks->onSuccess(); } @@ -151,16 +175,18 @@ void IDBCursorBackendImpl::loadCurrentRow() { // The column numbers depend on the query in IDBObjectStoreBackendImpl::openCursor. m_currentId = m_query->getColumnInt64(0); - if (!m_query->isColumnNull(1)) - m_currentKey = IDBKey::create(m_query->getColumnText(1)); - else if (!m_query->isColumnNull(2)) { - ASSERT_NOT_REACHED(); // FIXME: Implement date. - m_currentKey = IDBKey::create(); - } else if (!m_query->isColumnNull(3)) - m_currentKey = IDBKey::create(m_query->getColumnInt(3)); + m_currentKey = IDBKey::fromQuery(*m_query, 1); + if (m_isSerializedScriptValueCursor) + m_currentSerializedScriptValue = SerializedScriptValue::createFromWire(m_query->getColumnText(4)); else - m_currentKey = IDBKey::create(); - m_currentValue = SerializedScriptValue::createFromWire(m_query->getColumnText(4)); + m_currentIDBKeyValue = IDBKey::fromQuery(*m_query, 4); +} + +IDBDatabaseBackendImpl* IDBCursorBackendImpl::database() const +{ + if (m_idbObjectStore) + return m_idbObjectStore->database(); + return m_idbIndex->objectStore()->database(); } } // namespace WebCore |