SQLiteFileSystem.cpp [plain text]
#define __STDC_FORMAT_MACROS
#include "config.h"
#include "SQLiteFileSystem.h"
#if ENABLE(DATABASE)
#include "FileSystem.h"
#include "SQLiteDatabase.h"
#include "SQLiteStatement.h"
#include <inttypes.h>
#include <sqlite3.h>
#include <sqlite3_private.h>
namespace WebCore {
SQLiteFileSystem::SQLiteFileSystem()
{
}
void SQLiteFileSystem::registerSQLiteVFS()
{
}
int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database, bool)
{
String path = fileName;
return sqlite3_open16(path.charactersWithNullTermination(), database);
}
String SQLiteFileSystem::getFileNameForNewDatabase(const String& dbDir, const String&,
const String&, SQLiteDatabase* db)
{
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();
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)
{
return pathByAppendingComponent(path, fileName);
}
bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String& path)
{
if (path.isEmpty())
return false;
return makeAllDirectories(path);
}
bool SQLiteFileSystem::ensureDatabaseFileExists(const String& fileName, bool checkPathOnly)
{
if (fileName.isEmpty())
return false;
if (checkPathOnly) {
String dir = directoryName(fileName);
return ensureDatabaseDirectoryExists(dir);
}
return fileExists(fileName);
}
bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String& path)
{
return deleteEmptyDirectory(path);
}
bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
{
return deleteFile(fileName);
}
bool SQLiteFileSystem::truncateDatabaseFile(sqlite3* database)
{
return sqlite3_file_control(database, 0, SQLITE_TRUNCATE_DATABASE, 0) == SQLITE_OK;
}
long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
{
long long size;
return getFileSize(fileName, size) ? size : 0;
}
} #endif // ENABLE(DATABASE)