summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/sql
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-05-20 09:56:07 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-05-20 09:56:07 +0000
commit41386e9cb918eed93b3f13648cbef387e371e451 (patch)
treea97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/WebCore/platform/sql
parente15dd966d523731101f70ccf768bba12435a0208 (diff)
downloadWebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/WebCore/platform/sql')
-rw-r--r--Source/WebCore/platform/sql/SQLValue.cpp2
-rw-r--r--Source/WebCore/platform/sql/SQLValue.h2
-rw-r--r--Source/WebCore/platform/sql/SQLiteAuthorizer.cpp2
-rw-r--r--Source/WebCore/platform/sql/SQLiteDatabase.cpp88
-rw-r--r--Source/WebCore/platform/sql/SQLiteDatabase.h52
-rw-r--r--Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp12
-rw-r--r--Source/WebCore/platform/sql/SQLiteDatabaseTracker.h8
-rw-r--r--Source/WebCore/platform/sql/SQLiteFileSystem.cpp28
-rw-r--r--Source/WebCore/platform/sql/SQLiteFileSystem.h9
-rw-r--r--Source/WebCore/platform/sql/SQLiteStatement.cpp63
-rw-r--r--Source/WebCore/platform/sql/SQLiteStatement.h54
-rw-r--r--Source/WebCore/platform/sql/SQLiteTransaction.cpp6
-rw-r--r--Source/WebCore/platform/sql/SQLiteTransaction.h19
13 files changed, 191 insertions, 154 deletions
diff --git a/Source/WebCore/platform/sql/SQLValue.cpp b/Source/WebCore/platform/sql/SQLValue.cpp
index ef1b19c9d..b301ad28f 100644
--- a/Source/WebCore/platform/sql/SQLValue.cpp
+++ b/Source/WebCore/platform/sql/SQLValue.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
diff --git a/Source/WebCore/platform/sql/SQLValue.h b/Source/WebCore/platform/sql/SQLValue.h
index f4428f586..86ff887c1 100644
--- a/Source/WebCore/platform/sql/SQLValue.h
+++ b/Source/WebCore/platform/sql/SQLValue.h
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
diff --git a/Source/WebCore/platform/sql/SQLiteAuthorizer.cpp b/Source/WebCore/platform/sql/SQLiteAuthorizer.cpp
index b7e60a040..d47a44d8b 100644
--- a/Source/WebCore/platform/sql/SQLiteAuthorizer.cpp
+++ b/Source/WebCore/platform/sql/SQLiteAuthorizer.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
diff --git a/Source/WebCore/platform/sql/SQLiteDatabase.cpp b/Source/WebCore/platform/sql/SQLiteDatabase.cpp
index 2e4b263f3..e442ad0d8 100644
--- a/Source/WebCore/platform/sql/SQLiteDatabase.cpp
+++ b/Source/WebCore/platform/sql/SQLiteDatabase.cpp
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -31,7 +31,6 @@
#include "Logging.h"
#include "SQLiteFileSystem.h"
#include "SQLiteStatement.h"
-#include <mutex>
#include <sqlite3.h>
#include <thread>
#include <wtf/Threading.h>
@@ -40,14 +39,16 @@
namespace WebCore {
-static const char notOpenErrorMessage[] = "database is not open";
+const int SQLResultDone = SQLITE_DONE;
+const int SQLResultError = SQLITE_ERROR;
+const int SQLResultOk = SQLITE_OK;
+const int SQLResultRow = SQLITE_ROW;
+const int SQLResultSchema = SQLITE_SCHEMA;
+const int SQLResultFull = SQLITE_FULL;
+const int SQLResultInterrupt = SQLITE_INTERRUPT;
+const int SQLResultConstraint = SQLITE_CONSTRAINT;
-static void unauthorizedSQLFunction(sqlite3_context *context, int, sqlite3_value **)
-{
- const char* functionName = (const char*)sqlite3_user_data(context);
- String errorMessage = String::format("Function %s is unauthorized", functionName);
- sqlite3_result_error(context, errorMessage.utf8().data(), -1);
-}
+static const char notOpenErrorMessage[] = "database is not open";
SQLiteDatabase::SQLiteDatabase()
: m_db(0)
@@ -55,26 +56,11 @@ SQLiteDatabase::SQLiteDatabase()
, m_transactionInProgress(false)
, m_sharable(false)
, m_openingThread(0)
+ , m_interrupted(false)
, m_openError(SQLITE_ERROR)
, m_openErrorMessage()
, m_lastChangesCount(0)
{
- static std::once_flag flag;
- std::call_once(flag, [] {
- // It should be safe to call this outside of std::call_once, since it is documented to be
- // completely threadsafe. But in the past it was not safe, and the SQLite developers still
- // aren't confident that it really is, and we still support ancient versions of SQLite. So
- // std::call_once is used to stay on the safe side. See bug #143245.
- int ret = sqlite3_initialize();
- if (ret != SQLITE_OK) {
-#if SQLITE_VERSION_NUMBER >= 3007015
- WTFLogAlways("Failed to initialize SQLite: %s", sqlite3_errstr(ret));
-#else
- WTFLogAlways("Failed to initialize SQLite");
-#endif
- CRASH();
- }
- });
}
SQLiteDatabase::~SQLiteDatabase()
@@ -96,8 +82,6 @@ bool SQLiteDatabase::open(const String& filename, bool forWebSQLDatabase)
return false;
}
- overrideUnauthorizedFunctions();
-
m_openError = sqlite3_extended_result_codes(m_db, 1);
if (m_openError != SQLITE_OK) {
m_openErrorMessage = sqlite3_errmsg(m_db);
@@ -138,7 +122,7 @@ void SQLiteDatabase::close()
// ASSERT(currentThread() == m_openingThread);
sqlite3* db = m_db;
{
- LockHolder locker(m_databaseClosingMutex);
+ MutexLocker locker(m_databaseClosingMutex);
m_db = 0;
}
sqlite3_close(db);
@@ -149,23 +133,27 @@ void SQLiteDatabase::close()
m_openErrorMessage = CString();
}
-void SQLiteDatabase::overrideUnauthorizedFunctions()
+void SQLiteDatabase::interrupt()
{
- static const std::pair<const char*, int> functionParameters[] = {
- { "rtreenode", 2 },
- { "rtreedepth", 1 },
- { "eval", 1 },
- { "eval", 2 },
- { "printf", -1 },
- { "fts3_tokenizer", 1 },
- { "fts3_tokenizer", 2 },
- };
+ m_interrupted = true;
+ while (!m_lockingMutex.tryLock()) {
+ MutexLocker locker(m_databaseClosingMutex);
+ if (!m_db)
+ return;
+ sqlite3_interrupt(m_db);
+ std::this_thread::yield();
+ }
- for (auto& functionParameter : functionParameters)
- sqlite3_create_function(m_db, functionParameter.first, functionParameter.second, SQLITE_UTF8, const_cast<char*>(functionParameter.first), unauthorizedSQLFunction, 0, 0);
+ m_lockingMutex.unlock();
+}
+
+bool SQLiteDatabase::isInterrupted()
+{
+ ASSERT(!m_lockingMutex.tryLock());
+ return m_interrupted;
}
-void SQLiteDatabase::setFullsync(bool fsync)
+void SQLiteDatabase::setFullsync(bool fsync)
{
if (fsync)
executeCommand(ASCIILiteral("PRAGMA fullfsync = 1;"));
@@ -178,7 +166,7 @@ int64_t SQLiteDatabase::maximumSize()
int64_t maxPageCount = 0;
{
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
SQLiteStatement statement(*this, ASCIILiteral("PRAGMA max_page_count"));
maxPageCount = statement.getColumnInt64(0);
@@ -198,12 +186,12 @@ void SQLiteDatabase::setMaximumSize(int64_t size)
ASSERT(currentPageSize || !m_db);
int64_t newMaxPageCount = currentPageSize ? size / currentPageSize : 0;
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
SQLiteStatement statement(*this, "PRAGMA max_page_count = " + String::number(newMaxPageCount));
statement.prepare();
- if (statement.step() != SQLITE_ROW)
+ if (statement.step() != SQLResultRow)
LOG_ERROR("Failed to set maximum size of database to %lli bytes", static_cast<long long>(size));
enableAuthorizer(true);
@@ -215,7 +203,7 @@ int SQLiteDatabase::pageSize()
// Since the page size of a database is locked in at creation and therefore cannot be dynamic,
// we can cache the value for future use
if (m_pageSize == -1) {
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
SQLiteStatement statement(*this, ASCIILiteral("PRAGMA page_size"));
@@ -232,7 +220,7 @@ int64_t SQLiteDatabase::freeSpaceSize()
int64_t freelistCount = 0;
{
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
// Note: freelist_count was added in SQLite 3.4.1.
SQLiteStatement statement(*this, ASCIILiteral("PRAGMA freelist_count"));
@@ -248,7 +236,7 @@ int64_t SQLiteDatabase::totalSize()
int64_t pageCount = 0;
{
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
SQLiteStatement statement(*this, ASCIILiteral("PRAGMA page_count"));
pageCount = statement.getColumnInt64(0);
@@ -327,7 +315,7 @@ int SQLiteDatabase::runVacuumCommand()
int SQLiteDatabase::runIncrementalVacuumCommand()
{
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
enableAuthorizer(false);
if (!executeCommand(ASCIILiteral("PRAGMA incremental_vacuum")))
@@ -468,7 +456,7 @@ void SQLiteDatabase::setAuthorizer(PassRefPtr<DatabaseAuthorizer> auth)
return;
}
- LockHolder locker(m_authorizerLock);
+ MutexLocker locker(m_authorizerLock);
m_authorizer = auth;
diff --git a/Source/WebCore/platform/sql/SQLiteDatabase.h b/Source/WebCore/platform/sql/SQLiteDatabase.h
index 639a8a772..60c3a69c2 100644
--- a/Source/WebCore/platform/sql/SQLiteDatabase.h
+++ b/Source/WebCore/platform/sql/SQLiteDatabase.h
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -28,8 +28,6 @@
#define SQLiteDatabase_h
#include <functional>
-#include <sqlite3.h>
-#include <wtf/Lock.h>
#include <wtf/Threading.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
@@ -46,23 +44,34 @@ class DatabaseAuthorizer;
class SQLiteStatement;
class SQLiteTransaction;
+extern const int SQLResultDone;
+extern const int SQLResultError;
+extern const int SQLResultOk;
+extern const int SQLResultRow;
+extern const int SQLResultSchema;
+extern const int SQLResultFull;
+extern const int SQLResultInterrupt;
+extern const int SQLResultConstraint;
+
class SQLiteDatabase {
WTF_MAKE_NONCOPYABLE(SQLiteDatabase);
friend class SQLiteTransaction;
public:
- WEBCORE_EXPORT SQLiteDatabase();
- WEBCORE_EXPORT ~SQLiteDatabase();
+ SQLiteDatabase();
+ ~SQLiteDatabase();
- WEBCORE_EXPORT bool open(const String& filename, bool forWebSQLDatabase = false);
+ bool open(const String& filename, bool forWebSQLDatabase = false);
bool isOpen() const { return m_db; }
- WEBCORE_EXPORT void close();
+ void close();
+ void interrupt();
+ bool isInterrupted();
void updateLastChangesCount();
- WEBCORE_EXPORT bool executeCommand(const String&);
+ bool executeCommand(const String&);
bool returnsAtLeastOneResult(const String&);
- WEBCORE_EXPORT bool tableExists(const String&);
+ bool tableExists(const String&);
void clearAllTables();
int runVacuumCommand();
int runIncrementalVacuumCommand();
@@ -95,8 +104,8 @@ public:
enum SynchronousPragma { SyncOff = 0, SyncNormal = 1, SyncFull = 2 };
void setSynchronous(SynchronousPragma);
- WEBCORE_EXPORT int lastError();
- WEBCORE_EXPORT const char* lastErrorMsg();
+ int lastError();
+ const char* lastErrorMsg();
sqlite3* sqlite3Handle() const {
#if !PLATFORM(IOS)
@@ -107,7 +116,7 @@ public:
void setAuthorizer(PassRefPtr<DatabaseAuthorizer>);
- Lock& databaseMutex() { return m_lockingMutex; }
+ Mutex& databaseMutex() { return m_lockingMutex; }
bool isAutoCommitOn() const;
// The SQLite AUTO_VACUUM pragma can be either NONE, FULL, or INCREMENTAL.
@@ -122,15 +131,15 @@ public:
enum AutoVacuumPragma { AutoVacuumNone = 0, AutoVacuumFull = 1, AutoVacuumIncremental = 2 };
bool turnOnIncrementalAutoVacuum();
- WEBCORE_EXPORT void setCollationFunction(const String& collationName, std::function<int(int, const void*, int, const void*)>);
+ void setCollationFunction(const String& collationName, std::function<int(int, const void*, int, const void*)>);
void removeCollationFunction(const String& collationName);
// Set this flag to allow access from multiple threads. Not all multi-threaded accesses are safe!
// See http://www.sqlite.org/cvstrac/wiki?p=MultiThreading for more info.
#ifndef NDEBUG
- WEBCORE_EXPORT void disableThreadingChecks();
+ void disableThreadingChecks();
#else
- WEBCORE_EXPORT void disableThreadingChecks() {}
+ void disableThreadingChecks() {}
#endif
private:
@@ -139,22 +148,21 @@ private:
void enableAuthorizer(bool enable);
int pageSize();
-
- void overrideUnauthorizedFunctions();
-
+
sqlite3* m_db;
int m_pageSize;
bool m_transactionInProgress;
bool m_sharable;
- Lock m_authorizerLock;
+ Mutex m_authorizerLock;
RefPtr<DatabaseAuthorizer> m_authorizer;
- Lock m_lockingMutex;
+ Mutex m_lockingMutex;
ThreadIdentifier m_openingThread;
- Lock m_databaseClosingMutex;
+ Mutex m_databaseClosingMutex;
+ bool m_interrupted;
int m_openError;
CString m_openErrorMessage;
diff --git a/Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp b/Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp
index 3754a4c48..8438ac18b 100644
--- a/Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp
+++ b/Source/WebCore/platform/sql/SQLiteDatabaseTracker.cpp
@@ -27,7 +27,7 @@
#include "SQLiteDatabaseTracker.h"
#include <mutex>
-#include <wtf/Lock.h>
+#include <wtf/NeverDestroyed.h>
namespace WebCore {
@@ -36,7 +36,11 @@ namespace SQLiteDatabaseTracker {
static SQLiteDatabaseTrackerClient* s_staticSQLiteDatabaseTrackerClient = nullptr;
static unsigned s_transactionInProgressCounter = 0;
-static StaticLock transactionInProgressMutex;
+static std::mutex& transactionInProgressMutex()
+{
+ static NeverDestroyed<std::mutex> tipMutex;
+ return tipMutex;
+}
void setClient(SQLiteDatabaseTrackerClient* client)
{
@@ -50,7 +54,7 @@ void incrementTransactionInProgressCount()
if (!s_staticSQLiteDatabaseTrackerClient)
return;
- std::lock_guard<StaticLock> lock(transactionInProgressMutex);
+ std::lock_guard<std::mutex> lock(transactionInProgressMutex());
s_transactionInProgressCounter++;
if (s_transactionInProgressCounter == 1)
@@ -62,7 +66,7 @@ void decrementTransactionInProgressCount()
if (!s_staticSQLiteDatabaseTrackerClient)
return;
- std::lock_guard<StaticLock> lock(transactionInProgressMutex);
+ std::lock_guard<std::mutex> lock(transactionInProgressMutex());
ASSERT(s_transactionInProgressCounter);
s_transactionInProgressCounter--;
diff --git a/Source/WebCore/platform/sql/SQLiteDatabaseTracker.h b/Source/WebCore/platform/sql/SQLiteDatabaseTracker.h
index 45b01c673..483d9afe3 100644
--- a/Source/WebCore/platform/sql/SQLiteDatabaseTracker.h
+++ b/Source/WebCore/platform/sql/SQLiteDatabaseTracker.h
@@ -32,13 +32,13 @@ namespace WebCore {
namespace SQLiteDatabaseTracker {
-WEBCORE_EXPORT void decrementTransactionInProgressCount();
-WEBCORE_EXPORT void incrementTransactionInProgressCount();
+void decrementTransactionInProgressCount();
+void incrementTransactionInProgressCount();
-WEBCORE_EXPORT void setClient(SQLiteDatabaseTrackerClient*);
+void setClient(SQLiteDatabaseTrackerClient*);
#if !ASSERT_DISABLED
-WEBCORE_EXPORT bool hasTransactionInProgress();
+bool hasTransactionInProgress();
#endif
};
diff --git a/Source/WebCore/platform/sql/SQLiteFileSystem.cpp b/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
index 98de996b4..e8cfb0e16 100644
--- a/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
+++ b/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
@@ -50,7 +50,33 @@ SQLiteFileSystem::SQLiteFileSystem()
int SQLiteFileSystem::openDatabase(const String& filename, sqlite3** database, bool)
{
- return sqlite3_open(fileSystemRepresentation(filename).data(), database);
+ return sqlite3_open(filename.utf8().data(), database);
+}
+
+String SQLiteFileSystem::getFileNameForNewDatabase(const String& dbDir, const String&,
+ const String&, SQLiteDatabase* db)
+{
+ // try to get the next sequence number from the given database
+ // if we can't get a number, return an empty string
+ SQLiteStatement sequenceStatement(*db, "SELECT seq FROM sqlite_sequence WHERE name='Databases';");
+ if (sequenceStatement.prepare() != SQLResultOk)
+ return String();
+ int result = sequenceStatement.step();
+ int64_t seq = 0;
+ if (result == SQLResultRow)
+ seq = sequenceStatement.getColumnInt64(0);
+ else if (result != SQLResultDone)
+ return String();
+ sequenceStatement.finalize();
+
+ // increment the number until we can use it to form a file name that doesn't exist
+ String fileName;
+ do {
+ ++seq;
+ fileName = pathByAppendingComponent(dbDir, String::format("%016" PRIx64 ".db", seq));
+ } while (fileExists(fileName));
+
+ return String::format("%016" PRIx64 ".db", seq);
}
String SQLiteFileSystem::appendDatabaseFileNameToPath(const String& path, const String& fileName)
diff --git a/Source/WebCore/platform/sql/SQLiteFileSystem.h b/Source/WebCore/platform/sql/SQLiteFileSystem.h
index d3e4c43fe..9c5f29512 100644
--- a/Source/WebCore/platform/sql/SQLiteFileSystem.h
+++ b/Source/WebCore/platform/sql/SQLiteFileSystem.h
@@ -54,6 +54,15 @@ public:
// using a custom VFS.
static int openDatabase(const String& filename, sqlite3** database, bool forWebSQLDatabase);
+ // Returns the file name for a database.
+ //
+ // dbDir - The directory where all databases are stored.
+ // dbName - The name of the database.
+ // originIdentifier - The origin that wants to use this database.
+ // db - A database with a number generator used to create unique file names.
+ static String getFileNameForNewDatabase(const String& dbDir, const String& dbName,
+ const String& originIdentifier, SQLiteDatabase* db);
+
// Creates an absolute file path given a directory and a file name.
//
// path - The directory.
diff --git a/Source/WebCore/platform/sql/SQLiteStatement.cpp b/Source/WebCore/platform/sql/SQLiteStatement.cpp
index 135c00b16..3486b2be0 100644
--- a/Source/WebCore/platform/sql/SQLiteStatement.cpp
+++ b/Source/WebCore/platform/sql/SQLiteStatement.cpp
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -30,7 +30,7 @@
#include "SQLValue.h"
#include <sqlite3.h>
#include <wtf/Assertions.h>
-#include <wtf/text/StringView.h>
+#include <wtf/text/StringImpl.h>
// SQLite 3.6.16 makes sqlite3_prepare_v2 automatically retry preparing the statement
// once if the database scheme has changed. We rely on this behavior.
@@ -59,7 +59,9 @@ int SQLiteStatement::prepare()
{
ASSERT(!m_isPrepared);
- LockHolder databaseLock(m_database.databaseMutex());
+ MutexLocker databaseLock(m_database.databaseMutex());
+ if (m_database.isInterrupted())
+ return SQLITE_INTERRUPT;
CString query = m_query.stripWhiteSpace().utf8();
@@ -69,7 +71,7 @@ int SQLiteStatement::prepare()
// this lets SQLite avoid an extra string copy.
size_t lengthIncludingNullCharacter = query.length() + 1;
- const char* tail = nullptr;
+ const char* tail;
int error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), lengthIncludingNullCharacter, &m_statement, &tail);
if (error != SQLITE_OK)
@@ -86,7 +88,10 @@ int SQLiteStatement::prepare()
int SQLiteStatement::step()
{
- LockHolder databaseLock(m_database.databaseMutex());
+ MutexLocker databaseLock(m_database.databaseMutex());
+ if (m_database.isInterrupted())
+ return SQLITE_INTERRUPT;
+ //ASSERT(m_isPrepared);
if (!m_statement)
return SQLITE_OK;
@@ -172,13 +177,12 @@ int SQLiteStatement::bindBlob(int index, const String& text)
{
// String::characters() returns 0 for the empty string, which SQLite
// treats as a null, so we supply a non-null pointer for that case.
- auto upconvertedCharacters = StringView(text).upconvertedCharacters();
UChar anyCharacter = 0;
const UChar* characters;
if (text.isEmpty() && !text.isNull())
characters = &anyCharacter;
else
- characters = upconvertedCharacters;
+ characters = text.deprecatedCharacters();
return bindBlob(index, characters, text.length() * sizeof(UChar));
}
@@ -191,13 +195,12 @@ int SQLiteStatement::bindText(int index, const String& text)
// String::characters() returns 0 for the empty string, which SQLite
// treats as a null, so we supply a non-null pointer for that case.
- auto upconvertedCharacters = StringView(text).upconvertedCharacters();
UChar anyCharacter = 0;
const UChar* characters;
if (text.isEmpty() && !text.isNull())
characters = &anyCharacter;
else
- characters = upconvertedCharacters;
+ characters = text.deprecatedCharacters();
return sqlite3_bind_text16(m_statement, index, characters, sizeof(UChar) * text.length(), SQLITE_TRANSIENT);
}
@@ -425,30 +428,32 @@ void SQLiteStatement::getColumnBlobAsVector(int col, Vector<char>& result)
result[i] = (static_cast<const unsigned char*>(blob))[i];
}
-void SQLiteStatement::getColumnBlobAsVector(int col, Vector<uint8_t>& result)
+const void* SQLiteStatement::getColumnBlob(int col, int& size)
{
ASSERT(col >= 0);
- if (!m_statement && prepareAndStep() != SQLITE_ROW) {
- result.clear();
- return;
- }
+ size = 0;
- if (columnCount() <= col) {
- result.clear();
- return;
+ if (finalize() != SQLITE_OK)
+ LOG(SQLDatabase, "Finalize failed");
+ if (prepare() != SQLITE_OK) {
+ LOG(SQLDatabase, "Prepare failed");
+ return 0;
}
-
- const void* blob = sqlite3_column_blob(m_statement, col);
- if (!blob) {
- result.clear();
- return;
+ if (step() != SQLITE_ROW) {
+ LOG(SQLDatabase, "Step wasn't a row");
+ return 0;
}
+
+ if (columnCount() <= col)
+ return 0;
- int size = sqlite3_column_bytes(m_statement, col);
- result.resize((size_t)size);
- for (int i = 0; i < size; ++i)
- result[i] = (static_cast<const uint8_t*>(blob))[i];
+ const void* blob = sqlite3_column_blob(m_statement, col);
+ if (!blob)
+ return 0;
+
+ size = sqlite3_column_bytes(m_statement, col);
+ return blob;
}
bool SQLiteStatement::returnTextResults(int col, Vector<String>& v)
@@ -481,7 +486,7 @@ bool SQLiteStatement::returnIntResults(int col, Vector<int>& v)
finalize();
if (prepare() != SQLITE_OK)
return false;
-
+
while (step() == SQLITE_ROW)
v.append(getColumnInt(col));
bool result = true;
@@ -501,7 +506,7 @@ bool SQLiteStatement::returnInt64Results(int col, Vector<int64_t>& v)
finalize();
if (prepare() != SQLITE_OK)
return false;
-
+
while (step() == SQLITE_ROW)
v.append(getColumnInt64(col));
bool result = true;
diff --git a/Source/WebCore/platform/sql/SQLiteStatement.h b/Source/WebCore/platform/sql/SQLiteStatement.h
index 645a0434e..8a9e4ac3e 100644
--- a/Source/WebCore/platform/sql/SQLiteStatement.h
+++ b/Source/WebCore/platform/sql/SQLiteStatement.h
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -37,30 +37,30 @@ class SQLValue;
class SQLiteStatement {
WTF_MAKE_NONCOPYABLE(SQLiteStatement); WTF_MAKE_FAST_ALLOCATED;
public:
- WEBCORE_EXPORT SQLiteStatement(SQLiteDatabase&, const String&);
- WEBCORE_EXPORT ~SQLiteStatement();
+ SQLiteStatement(SQLiteDatabase&, const String&);
+ ~SQLiteStatement();
- WEBCORE_EXPORT int prepare();
- WEBCORE_EXPORT int bindBlob(int index, const void* blob, int size);
- WEBCORE_EXPORT int bindBlob(int index, const String&);
- WEBCORE_EXPORT int bindText(int index, const String&);
- WEBCORE_EXPORT int bindInt(int index, int);
- WEBCORE_EXPORT int bindInt64(int index, int64_t);
- WEBCORE_EXPORT int bindDouble(int index, double);
- WEBCORE_EXPORT int bindNull(int index);
- WEBCORE_EXPORT int bindValue(int index, const SQLValue&);
- WEBCORE_EXPORT unsigned bindParameterCount() const;
+ int prepare();
+ int bindBlob(int index, const void* blob, int size);
+ int bindBlob(int index, const String&);
+ int bindText(int index, const String&);
+ int bindInt(int index, int);
+ int bindInt64(int index, int64_t);
+ int bindDouble(int index, double);
+ int bindNull(int index);
+ int bindValue(int index, const SQLValue&);
+ unsigned bindParameterCount() const;
- WEBCORE_EXPORT int step();
- WEBCORE_EXPORT int finalize();
- WEBCORE_EXPORT int reset();
+ int step();
+ int finalize();
+ int reset();
int prepareAndStep() { if (int error = prepare()) return error; return step(); }
// prepares, steps, and finalizes the query.
// returns true if all 3 steps succeed with step() returning SQLITE_DONE
// returns false otherwise
- WEBCORE_EXPORT bool executeCommand();
+ bool executeCommand();
// prepares, steps, and finalizes.
// returns true is step() returns SQLITE_ROW
@@ -73,24 +73,24 @@ public:
// returned in the last step()
int columnCount();
- WEBCORE_EXPORT bool isColumnNull(int col);
- WEBCORE_EXPORT bool isColumnDeclaredAsBlob(int col);
+ bool isColumnNull(int col);
+ bool isColumnDeclaredAsBlob(int col);
String getColumnName(int col);
SQLValue getColumnValue(int col);
- WEBCORE_EXPORT String getColumnText(int col);
+ String getColumnText(int col);
double getColumnDouble(int col);
- WEBCORE_EXPORT int getColumnInt(int col);
- WEBCORE_EXPORT int64_t getColumnInt64(int col);
- WEBCORE_EXPORT String getColumnBlobAsString(int col);
- WEBCORE_EXPORT void getColumnBlobAsVector(int col, Vector<char>&);
- WEBCORE_EXPORT void getColumnBlobAsVector(int col, Vector<uint8_t>&);
+ int getColumnInt(int col);
+ int64_t getColumnInt64(int col);
+ const void* getColumnBlob(int col, int& size);
+ String getColumnBlobAsString(int col);
+ void getColumnBlobAsVector(int col, Vector<char>&);
bool returnTextResults(int col, Vector<String>&);
bool returnIntResults(int col, Vector<int>&);
bool returnInt64Results(int col, Vector<int64_t>&);
bool returnDoubleResults(int col, Vector<double>&);
- SQLiteDatabase& database() { return m_database; }
+ SQLiteDatabase* database() { return &m_database; }
const String& query() const { return m_query; }
diff --git a/Source/WebCore/platform/sql/SQLiteTransaction.cpp b/Source/WebCore/platform/sql/SQLiteTransaction.cpp
index 54e0a1802..d15ced3ae 100644
--- a/Source/WebCore/platform/sql/SQLiteTransaction.cpp
+++ b/Source/WebCore/platform/sql/SQLiteTransaction.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
diff --git a/Source/WebCore/platform/sql/SQLiteTransaction.h b/Source/WebCore/platform/sql/SQLiteTransaction.h
index b9d1f7940..0546f4f24 100644
--- a/Source/WebCore/platform/sql/SQLiteTransaction.h
+++ b/Source/WebCore/platform/sql/SQLiteTransaction.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -36,19 +36,16 @@ class SQLiteDatabase;
class SQLiteTransaction {
WTF_MAKE_NONCOPYABLE(SQLiteTransaction); WTF_MAKE_FAST_ALLOCATED;
public:
- WEBCORE_EXPORT SQLiteTransaction(SQLiteDatabase& db, bool readOnly = false);
- WEBCORE_EXPORT ~SQLiteTransaction();
+ SQLiteTransaction(SQLiteDatabase& db, bool readOnly = false);
+ ~SQLiteTransaction();
- WEBCORE_EXPORT void begin();
- WEBCORE_EXPORT void commit();
- WEBCORE_EXPORT void rollback();
+ void begin();
+ void commit();
+ void rollback();
void stop();
bool inProgress() const { return m_inProgress; }
bool wasRolledBackBySqlite() const;
-
- SQLiteDatabase& database() const { return m_db; }
-
private:
SQLiteDatabase& m_db;
bool m_inProgress;