#ifndef SQLError_h
#define SQLError_h
#include "bindings/v8/ScriptWrappable.h"
#include "wtf/ThreadSafeRefCounted.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class SQLErrorData {
public:
static PassOwnPtr<SQLErrorData> create(unsigned code, const String& message)
{
return adoptPtr(new SQLErrorData(code, message));
}
static PassOwnPtr<SQLErrorData> create(unsigned code, const char* message, int sqliteCode, const char* sqliteMessage)
{
return create(code, String::format("%s (%d %s)", message, sqliteCode, sqliteMessage));
}
static PassOwnPtr<SQLErrorData> create(const SQLErrorData& data)
{
return create(data.code(), data.message());
}
unsigned code() const { return m_code; }
String message() const { return m_message.isolatedCopy(); }
private:
SQLErrorData(unsigned code, const String& message) : m_code(code), m_message(message.isolatedCopy()) { }
unsigned m_code;
String m_message;
};
class SQLError : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<SQLError>, public ScriptWrappable {
public:
static PassRefPtrWillBeRawPtr<SQLError> create(const SQLErrorData& data) { return adoptRefWillBeNoop(new SQLError(data)); }
void trace(Visitor*) { }
unsigned code() const { return m_data.code(); }
String message() const { return m_data.message(); }
enum SQLErrorCode {
UNKNOWN_ERR = 0,
DATABASE_ERR = 1,
VERSION_ERR = 2,
TOO_LARGE_ERR = 3,
QUOTA_ERR = 4,
SYNTAX_ERR = 5,
CONSTRAINT_ERR = 6,
TIMEOUT_ERR = 7
};
static const char quotaExceededErrorMessage[];
static const char unknownErrorMessage[];
static const char versionErrorMessage[];
private:
explicit SQLError(const SQLErrorData& data) : m_data(data)
{
ScriptWrappable::init(this);
}
const SQLErrorData m_data;
};
}
#endif