зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1154325 P1 Add convenience routines to bind and get Blobs as strings. r=asuth
This commit is contained in:
Родитель
a874312867
Коммит
81dce6f7c5
|
@ -19,7 +19,7 @@ interface mozIStorageBindingParamsArray;
|
|||
* (mozIStorageStatement) that can be used for both synchronous and asynchronous
|
||||
* purposes.
|
||||
*/
|
||||
[scriptable, uuid(5d34f333-ed3f-4aa2-ba51-f2a8b0cfa33a)]
|
||||
[scriptable, uuid(16ca67aa-1325-43e2-aac7-859afd1590b2)]
|
||||
interface mozIStorageBaseStatement : mozIStorageBindingParams {
|
||||
/**
|
||||
* Finalizes a statement so you can successfully close a database connection.
|
||||
|
@ -67,6 +67,12 @@ interface mozIStorageBaseStatement : mozIStorageBindingParams {
|
|||
in unsigned long aParamIndex,
|
||||
[array,const,size_is(aValueSize)] in octet aValue,
|
||||
in unsigned long aValueSize);
|
||||
[deprecated] void bindStringAsBlobParameter(
|
||||
in unsigned long aParamIndex,
|
||||
in AString aValue);
|
||||
[deprecated] void bindUTF8StringAsBlobParameter(
|
||||
in unsigned long aParamIndex,
|
||||
in AUTF8String aValue);
|
||||
[deprecated] void bindAdoptedBlobParameter(
|
||||
in unsigned long aParamIndex,
|
||||
[array,size_is(aValueSize)] in octet aValue,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
interface nsIVariant;
|
||||
|
||||
[scriptable, uuid(7d8763ad-79d9-4674-ada1-37fd702af68c)]
|
||||
[scriptable, uuid(2d09f42f-966e-4663-b4b3-b0c8676bf2bf)]
|
||||
interface mozIStorageBindingParams : nsISupports {
|
||||
/**
|
||||
* Binds aValue to the parameter with the name aName.
|
||||
|
@ -34,6 +34,11 @@ interface mozIStorageBindingParams : nsISupports {
|
|||
void bindBlobByName(in AUTF8String aName,
|
||||
[array, const, size_is(aValueSize)] in octet aValue,
|
||||
in unsigned long aValueSize);
|
||||
|
||||
// Convenience routines for storing strings as blobs.
|
||||
void bindStringAsBlobByName(in AUTF8String aName, in AString aValue);
|
||||
void bindUTF8StringAsBlobByName(in AUTF8String aName, in AUTF8String aValue);
|
||||
|
||||
// The function adopts the storage for the provided blob. After calling
|
||||
// this function, mozStorage will ensure that NS_Free is called on the
|
||||
// underlying pointer.
|
||||
|
@ -66,6 +71,11 @@ interface mozIStorageBindingParams : nsISupports {
|
|||
void bindBlobByIndex(in unsigned long aIndex,
|
||||
[array, const, size_is(aValueSize)] in octet aValue,
|
||||
in unsigned long aValueSize);
|
||||
|
||||
// Convenience routines for storing strings as blobs.
|
||||
void bindStringAsBlobByIndex(in unsigned long aIndex, in AString aValue);
|
||||
void bindUTF8StringAsBlobByIndex(in unsigned long aIndex, in AUTF8String aValue);
|
||||
|
||||
// The function adopts the storage for the provided blob. After calling
|
||||
// this function, mozStorage will ensure that NS_Free is called on the
|
||||
// underlying pointer.
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* A SQL statement that can be used for both synchronous and asynchronous
|
||||
* purposes.
|
||||
*/
|
||||
[scriptable, uuid(b3c4476e-c490-4e3b-9db1-e2d3a6f0287c)]
|
||||
[scriptable, uuid(5f567c35-6c32-4140-828c-683ea49cfd3a)]
|
||||
interface mozIStorageStatement : mozIStorageBaseStatement {
|
||||
/**
|
||||
* Create a clone of this statement, by initializing a new statement
|
||||
|
@ -207,6 +207,29 @@ interface mozIStorageStatement : mozIStorageBaseStatement {
|
|||
* The contents of the BLOB. This will be NULL if aDataSize == 0.
|
||||
*/
|
||||
void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
|
||||
|
||||
/**
|
||||
* Retrieve the contents of a Blob column from the current result row as a
|
||||
* string.
|
||||
*
|
||||
* @param aIndex
|
||||
* 0-based colummn index.
|
||||
* @return The value for the result Blob column interpreted as a String.
|
||||
* No encoding conversion is performed.
|
||||
*/
|
||||
AString getBlobAsString(in unsigned long aIndex);
|
||||
|
||||
/**
|
||||
* Retrieve the contents of a Blob column from the current result row as a
|
||||
* UTF8 string.
|
||||
*
|
||||
* @param aIndex
|
||||
* 0-based colummn index.
|
||||
* @return The value for the result Blob column interpreted as a UTF8 String.
|
||||
* No encoding conversion is performed.
|
||||
*/
|
||||
AUTF8String getBlobAsUTF8String(in unsigned long aIndex);
|
||||
|
||||
/**
|
||||
* Check whether the given column in the current result row is NULL.
|
||||
*
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* mozIStorageValueArray wraps an array of SQL values, such as a single database
|
||||
* row.
|
||||
*/
|
||||
[scriptable, uuid(07b5b93e-113c-4150-863c-d247b003a55d)]
|
||||
[scriptable, uuid(6e6306f4-ffa7-40f5-96ca-36159ce8f431)]
|
||||
interface mozIStorageValueArray : nsISupports {
|
||||
/**
|
||||
* These type values are returned by getTypeOfIndex
|
||||
|
@ -62,6 +62,8 @@ interface mozIStorageValueArray : nsISupports {
|
|||
|
||||
// data will be NULL if dataSize = 0
|
||||
void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
|
||||
AString getBlobAsString(in unsigned long aIndex);
|
||||
AUTF8String getBlobAsUTF8String(in unsigned long aIndex);
|
||||
boolean getIsNull(in unsigned long aIndex);
|
||||
|
||||
/**
|
||||
|
|
|
@ -321,6 +321,20 @@ NS_DEFINE_STATIC_IID_ACCESSOR(StorageBaseStatementInternal,
|
|||
const uint8_t *aValue, \
|
||||
uint32_t aValueSize), \
|
||||
(aWhere, aValue, aValueSize)) \
|
||||
BIND_GEN_IMPL(_class, _optionalGuard, \
|
||||
StringAsBlob, \
|
||||
(const nsACString &aWhere, \
|
||||
const nsAString& aValue), \
|
||||
(uint32_t aWhere, \
|
||||
const nsAString& aValue), \
|
||||
(aWhere, aValue)) \
|
||||
BIND_GEN_IMPL(_class, _optionalGuard, \
|
||||
UTF8StringAsBlob, \
|
||||
(const nsACString &aWhere, \
|
||||
const nsACString& aValue), \
|
||||
(uint32_t aWhere, \
|
||||
const nsACString& aValue), \
|
||||
(aWhere, aValue)) \
|
||||
BIND_GEN_IMPL(_class, _optionalGuard, \
|
||||
AdoptedBlob, \
|
||||
(const nsACString &aWhere, \
|
||||
|
|
|
@ -152,6 +152,18 @@ ArgValueArray::GetBlob(uint32_t aIndex,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ArgValueArray::GetBlobAsString(uint32_t aIndex, nsAString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ArgValueArray::GetBlobAsUTF8String(uint32_t aIndex, nsACString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ArgValueArray::GetIsNull(uint32_t aIndex,
|
||||
bool *_isNull)
|
||||
|
|
|
@ -358,6 +358,20 @@ BindingParams::BindBlobByName(const nsACString &aName,
|
|||
return BindByName(aName, value);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindStringAsBlobByName(const nsACString& aName,
|
||||
const nsAString& aValue)
|
||||
{
|
||||
return DoBindStringAsBlobByName(this, aName, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindUTF8StringAsBlobByName(const nsACString& aName,
|
||||
const nsACString& aValue)
|
||||
{
|
||||
return DoBindStringAsBlobByName(this, aName, aValue);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindAdoptedBlobByName(const nsACString &aName,
|
||||
|
@ -493,6 +507,19 @@ BindingParams::BindBlobByIndex(uint32_t aIndex,
|
|||
return BindByIndex(aIndex, value);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindStringAsBlobByIndex(uint32_t aIndex, const nsAString& aValue)
|
||||
{
|
||||
return DoBindStringAsBlobByIndex(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindUTF8StringAsBlobByIndex(uint32_t aIndex,
|
||||
const nsACString& aValue)
|
||||
{
|
||||
return DoBindStringAsBlobByIndex(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BindingParams::BindAdoptedBlobByIndex(uint32_t aIndex,
|
||||
uint8_t *aValue,
|
||||
|
|
|
@ -88,6 +88,54 @@ already_AddRefed<nsIRunnable> newCompletionEvent(
|
|||
mozIStorageCompletionCallback *aCallback
|
||||
);
|
||||
|
||||
/**
|
||||
* Utility method to get a Blob as a string value. The string expects
|
||||
* the interface exposed by nsAString/nsACString/etc.
|
||||
*/
|
||||
template<class T, class V>
|
||||
nsresult
|
||||
DoGetBlobAsString(T* aThis, uint32_t aIndex, V& aValue)
|
||||
{
|
||||
typedef typename V::char_type char_type;
|
||||
|
||||
uint32_t size;
|
||||
char_type* blob;
|
||||
nsresult rv =
|
||||
aThis->GetBlob(aIndex, &size, reinterpret_cast<uint8_t**>(&blob));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aValue.Adopt(blob, size / sizeof(char_type));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to bind a string value as a Blob. The string expects
|
||||
* the interface exposed by nsAString/nsACString/etc.
|
||||
*/
|
||||
template<class T, class V>
|
||||
nsresult
|
||||
DoBindStringAsBlobByName(T* aThis, const nsACString& aName, const V& aValue)
|
||||
{
|
||||
typedef typename V::char_type char_type;
|
||||
return aThis->BindBlobByName(aName,
|
||||
reinterpret_cast<const uint8_t*>(aValue.BeginReading()),
|
||||
aValue.Length() * sizeof(char_type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to bind a string value as a Blob. The string expects
|
||||
* the interface exposed by nsAString/nsACString/etc.
|
||||
*/
|
||||
template<class T, class V>
|
||||
nsresult
|
||||
DoBindStringAsBlobByIndex(T* aThis, uint32_t aIndex, const V& aValue)
|
||||
{
|
||||
typedef typename V::char_type char_type;
|
||||
return aThis->BindBlobByIndex(aIndex,
|
||||
reinterpret_cast<const uint8_t*>(aValue.BeginReading()),
|
||||
aValue.Length() * sizeof(char_type));
|
||||
}
|
||||
|
||||
} // namespace storage
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -194,6 +194,18 @@ Row::GetBlob(uint32_t aIndex,
|
|||
reinterpret_cast<void **>(_blob));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Row::GetBlobAsString(uint32_t aIndex, nsAString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Row::GetBlobAsUTF8String(uint32_t aIndex, nsACString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Row::GetIsNull(uint32_t aIndex,
|
||||
bool *_isNull)
|
||||
|
|
|
@ -832,6 +832,18 @@ Statement::GetBlob(uint32_t aIndex,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Statement::GetBlobAsString(uint32_t aIndex, nsAString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Statement::GetBlobAsUTF8String(uint32_t aIndex, nsACString& aValue)
|
||||
{
|
||||
return DoGetBlobAsString(this, aIndex, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Statement::GetSharedUTF8String(uint32_t aIndex,
|
||||
uint32_t *_length,
|
||||
|
|
Загрузка…
Ссылка в новой задаче