summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-18 14:56:50 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commit0c6d523c02dafb95b0683b88222e17a4fa6782a6 (patch)
treed162284bb5f2b5791247db968b9fea1a85a3a356 /Source/WebCore/platform
parent2925efd2fcef1f8b9fd48979144877c1a5ec214b (diff)
QtWebKit should not require SQLite version to 3.6.16.
Revert r152134 which raised the minimum SQLite version, and r152201 which removed a method the reverted code needed. Change-Id: Ie028992137f3983d114f3491423afe6303173544 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebCore/platform')
-rw-r--r--Source/WebCore/platform/sql/SQLiteFileSystem.cpp6
-rw-r--r--Source/WebCore/platform/sql/SQLiteFileSystem.h4
-rw-r--r--Source/WebCore/platform/sql/SQLiteStatement.cpp46
3 files changed, 32 insertions, 24 deletions
diff --git a/Source/WebCore/platform/sql/SQLiteFileSystem.cpp b/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
index 735f0b41f..cbf8883ed 100644
--- a/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
+++ b/Source/WebCore/platform/sql/SQLiteFileSystem.cpp
@@ -44,9 +44,11 @@ SQLiteFileSystem::SQLiteFileSystem()
{
}
-int SQLiteFileSystem::openDatabase(const String& filename, sqlite3** database, bool)
+int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database, bool)
{
- return sqlite3_open(filename.utf8().data(), database);
+ // SQLite expects a null terminator on its UTF-16 strings.
+ String path = fileName;
+ return sqlite3_open16(path.deprecatedCharactersWithNullTermination(), database);
}
String SQLiteFileSystem::getFileNameForNewDatabase(const String& dbDir, const String&,
diff --git a/Source/WebCore/platform/sql/SQLiteFileSystem.h b/Source/WebCore/platform/sql/SQLiteFileSystem.h
index 14085b929..9800f7e54 100644
--- a/Source/WebCore/platform/sql/SQLiteFileSystem.h
+++ b/Source/WebCore/platform/sql/SQLiteFileSystem.h
@@ -46,13 +46,13 @@ class SQLiteFileSystem {
public:
// Opens a database file.
//
- // filemame - The name of the database file.
+ // fileName - The name of the database file.
// database - The SQLite structure that represents the database stored
// in the given file.
// forWebSQLDatabase - True, if and only if we're opening a Web SQL Database file.
// Used by Chromium to determine if the DB file needs to be opened
// using a custom VFS.
- static int openDatabase(const String& filename, sqlite3** database, bool forWebSQLDatabase);
+ static int openDatabase(const String& fileName, sqlite3** database, bool forWebSQLDatabase);
// Returns the file name for a database.
//
diff --git a/Source/WebCore/platform/sql/SQLiteStatement.cpp b/Source/WebCore/platform/sql/SQLiteStatement.cpp
index 1203e84ee..fd2af3286 100644
--- a/Source/WebCore/platform/sql/SQLiteStatement.cpp
+++ b/Source/WebCore/platform/sql/SQLiteStatement.cpp
@@ -32,14 +32,18 @@
#include <wtf/Assertions.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.
-#if SQLITE_VERSION_NUMBER < 3006016
-#error SQLite version 3.6.16 or newer is required
-#endif
-
namespace WebCore {
+#if SQLITE_VERSION_NUMBER < 3003009
+
+// FIXME: This overload helps us compile with older versions of SQLite 3, but things like quotas will not work.
+static inline int sqlite3_prepare16_v2(sqlite3* db, const void* zSql, int nBytes, sqlite3_stmt** ppStmt, const void** pzTail)
+{
+ return sqlite3_prepare16(db, zSql, nBytes, ppStmt, pzTail);
+}
+
+#endif
+
SQLiteStatement::SQLiteStatement(SQLiteDatabase& db, const String& sql)
: m_database(db)
, m_query(sql)
@@ -63,23 +67,25 @@ int SQLiteStatement::prepare()
if (m_database.isInterrupted())
return SQLITE_INTERRUPT;
- CString query = m_query.stripWhiteSpace().utf8();
-
- LOG(SQLDatabase, "SQL - prepare - %s", query.data());
-
- // Pass the length of the string including the null character to sqlite3_prepare_v2;
- // this lets SQLite avoid an extra string copy.
- size_t lengthIncludingNullCharacter = query.length() + 1;
-
- const char* tail;
- int error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), lengthIncludingNullCharacter, &m_statement, &tail);
+ const void* tail = 0;
+ LOG(SQLDatabase, "SQL - prepare - %s", m_query.ascii().data());
+ String strippedQuery = m_query.stripWhiteSpace();
+ const UChar* nullTermed = strippedQuery.deprecatedCharactersWithNullTermination();
+ int error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), nullTermed, -1, &m_statement, &tail);
+
+ // Starting with version 3.6.16, sqlite has a patch (http://www.sqlite.org/src/ci/256ec3c6af)
+ // that should make sure sqlite3_prepare16_v2 doesn't return a SQLITE_SCHEMA error.
+ // If we're using an older sqlite version, try to emulate the patch.
+ if (error == SQLITE_SCHEMA) {
+ sqlite3_finalize(m_statement);
+ error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), m_query.deprecatedCharactersWithNullTermination(), -1, &m_statement, &tail);
+ }
if (error != SQLITE_OK)
- LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, query.data(), sqlite3_errmsg(m_database.sqlite3Handle()));
-
- if (tail && *tail)
+ LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Handle()));
+ const UChar* ch = static_cast<const UChar*>(tail);
+ if (ch && *ch)
error = SQLITE_ERROR;
-
#ifndef NDEBUG
m_isPrepared = error == SQLITE_OK;
#endif