зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1380606 - Add an `IS_VALID_GUID()` SQL function to Places. r=mak
This exposes `IsValidGUID` to SQL, matching `GENERATE_GUID()` and making it easier to SELECT rows with invalid GUIDs. MozReview-Commit-ID: Dspm8A59P5L --HG-- extra : rebase_source : 9bbc853ae3892314cc3bab7469c0f9c25706aea5
This commit is contained in:
Родитель
d4cf5c3f6e
Коммит
b8e3915bf5
|
@ -1330,6 +1330,8 @@ Database::InitFunctions()
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = GenerateGUIDFunction::create(mMainConn);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = IsValidGUIDFunction::create(mMainConn);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = FixupURLFunction::create(mMainConn);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = FrecencyNotificationFunction::create(mMainConn);
|
||||
|
|
|
@ -771,6 +771,40 @@ namespace places {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// GUID Validation Function
|
||||
|
||||
/* static */
|
||||
nsresult
|
||||
IsValidGUIDFunction::create(mozIStorageConnection *aDBConn)
|
||||
{
|
||||
RefPtr<IsValidGUIDFunction> function = new IsValidGUIDFunction();
|
||||
return aDBConn->CreateFunction(
|
||||
NS_LITERAL_CSTRING("is_valid_guid"), 1, function
|
||||
);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(
|
||||
IsValidGUIDFunction,
|
||||
mozIStorageFunction
|
||||
)
|
||||
|
||||
NS_IMETHODIMP
|
||||
IsValidGUIDFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
|
||||
nsIVariant **_result)
|
||||
{
|
||||
// Must have non-null function arguments.
|
||||
MOZ_ASSERT(aArguments);
|
||||
|
||||
nsAutoCString guid;
|
||||
aArguments->GetUTF8String(0, guid);
|
||||
|
||||
RefPtr<nsVariant> result = new nsVariant();
|
||||
result->SetAsBool(IsValidGUID(guid));
|
||||
result.forget(_result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Get Unreversed Host Function
|
||||
|
||||
|
|
|
@ -241,6 +241,29 @@ private:
|
|||
~GenerateGUIDFunction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* SQL function to check if a GUID is valid. This is just a wrapper around
|
||||
* IsValidGUID in Helpers.h.
|
||||
*
|
||||
* @return true if valid, false otherwise.
|
||||
*/
|
||||
class IsValidGUIDFunction final : public mozIStorageFunction
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_MOZISTORAGEFUNCTION
|
||||
|
||||
/**
|
||||
* Registers the function with the specified database connection.
|
||||
*
|
||||
* @param aDBConn
|
||||
* The database connection to register with.
|
||||
*/
|
||||
static nsresult create(mozIStorageConnection *aDBConn);
|
||||
private:
|
||||
~IsValidGUIDFunction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* SQL function to unreverse the rev_host of a page.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче