mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1154325 P1 Add convenience routines to bind and get Blobs as strings. r=asuth
This commit is contained in:
parent
70c4125c44
commit
9f4d2c5641
@ -19,7 +19,7 @@ interface mozIStorageBindingParamsArray;
|
|||||||
* (mozIStorageStatement) that can be used for both synchronous and asynchronous
|
* (mozIStorageStatement) that can be used for both synchronous and asynchronous
|
||||||
* purposes.
|
* purposes.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(5d34f333-ed3f-4aa2-ba51-f2a8b0cfa33a)]
|
[scriptable, uuid(16ca67aa-1325-43e2-aac7-859afd1590b2)]
|
||||||
interface mozIStorageBaseStatement : mozIStorageBindingParams {
|
interface mozIStorageBaseStatement : mozIStorageBindingParams {
|
||||||
/**
|
/**
|
||||||
* Finalizes a statement so you can successfully close a database connection.
|
* Finalizes a statement so you can successfully close a database connection.
|
||||||
@ -67,6 +67,12 @@ interface mozIStorageBaseStatement : mozIStorageBindingParams {
|
|||||||
in unsigned long aParamIndex,
|
in unsigned long aParamIndex,
|
||||||
[array,const,size_is(aValueSize)] in octet aValue,
|
[array,const,size_is(aValueSize)] in octet aValue,
|
||||||
in unsigned long aValueSize);
|
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(
|
[deprecated] void bindAdoptedBlobParameter(
|
||||||
in unsigned long aParamIndex,
|
in unsigned long aParamIndex,
|
||||||
[array,size_is(aValueSize)] in octet aValue,
|
[array,size_is(aValueSize)] in octet aValue,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
interface nsIVariant;
|
interface nsIVariant;
|
||||||
|
|
||||||
[scriptable, uuid(7d8763ad-79d9-4674-ada1-37fd702af68c)]
|
[scriptable, uuid(2d09f42f-966e-4663-b4b3-b0c8676bf2bf)]
|
||||||
interface mozIStorageBindingParams : nsISupports {
|
interface mozIStorageBindingParams : nsISupports {
|
||||||
/**
|
/**
|
||||||
* Binds aValue to the parameter with the name aName.
|
* Binds aValue to the parameter with the name aName.
|
||||||
@ -34,6 +34,11 @@ interface mozIStorageBindingParams : nsISupports {
|
|||||||
void bindBlobByName(in AUTF8String aName,
|
void bindBlobByName(in AUTF8String aName,
|
||||||
[array, const, size_is(aValueSize)] in octet aValue,
|
[array, const, size_is(aValueSize)] in octet aValue,
|
||||||
in unsigned long aValueSize);
|
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
|
// The function adopts the storage for the provided blob. After calling
|
||||||
// this function, mozStorage will ensure that NS_Free is called on the
|
// this function, mozStorage will ensure that NS_Free is called on the
|
||||||
// underlying pointer.
|
// underlying pointer.
|
||||||
@ -66,6 +71,11 @@ interface mozIStorageBindingParams : nsISupports {
|
|||||||
void bindBlobByIndex(in unsigned long aIndex,
|
void bindBlobByIndex(in unsigned long aIndex,
|
||||||
[array, const, size_is(aValueSize)] in octet aValue,
|
[array, const, size_is(aValueSize)] in octet aValue,
|
||||||
in unsigned long aValueSize);
|
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
|
// The function adopts the storage for the provided blob. After calling
|
||||||
// this function, mozStorage will ensure that NS_Free is called on the
|
// this function, mozStorage will ensure that NS_Free is called on the
|
||||||
// underlying pointer.
|
// underlying pointer.
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* A SQL statement that can be used for both synchronous and asynchronous
|
* A SQL statement that can be used for both synchronous and asynchronous
|
||||||
* purposes.
|
* purposes.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(b3c4476e-c490-4e3b-9db1-e2d3a6f0287c)]
|
[scriptable, uuid(5f567c35-6c32-4140-828c-683ea49cfd3a)]
|
||||||
interface mozIStorageStatement : mozIStorageBaseStatement {
|
interface mozIStorageStatement : mozIStorageBaseStatement {
|
||||||
/**
|
/**
|
||||||
* Create a clone of this statement, by initializing a new statement
|
* 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.
|
* 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);
|
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.
|
* 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
|
* mozIStorageValueArray wraps an array of SQL values, such as a single database
|
||||||
* row.
|
* row.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(07b5b93e-113c-4150-863c-d247b003a55d)]
|
[scriptable, uuid(6e6306f4-ffa7-40f5-96ca-36159ce8f431)]
|
||||||
interface mozIStorageValueArray : nsISupports {
|
interface mozIStorageValueArray : nsISupports {
|
||||||
/**
|
/**
|
||||||
* These type values are returned by getTypeOfIndex
|
* These type values are returned by getTypeOfIndex
|
||||||
@ -62,6 +62,8 @@ interface mozIStorageValueArray : nsISupports {
|
|||||||
|
|
||||||
// data will be NULL if dataSize = 0
|
// data will be NULL if dataSize = 0
|
||||||
void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
|
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);
|
boolean getIsNull(in unsigned long aIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,6 +321,20 @@ NS_DEFINE_STATIC_IID_ACCESSOR(StorageBaseStatementInternal,
|
|||||||
const uint8_t *aValue, \
|
const uint8_t *aValue, \
|
||||||
uint32_t aValueSize), \
|
uint32_t aValueSize), \
|
||||||
(aWhere, aValue, 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, \
|
BIND_GEN_IMPL(_class, _optionalGuard, \
|
||||||
AdoptedBlob, \
|
AdoptedBlob, \
|
||||||
(const nsACString &aWhere, \
|
(const nsACString &aWhere, \
|
||||||
|
@ -152,6 +152,18 @@ ArgValueArray::GetBlob(uint32_t aIndex,
|
|||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
ArgValueArray::GetIsNull(uint32_t aIndex,
|
ArgValueArray::GetIsNull(uint32_t aIndex,
|
||||||
bool *_isNull)
|
bool *_isNull)
|
||||||
|
@ -358,6 +358,20 @@ BindingParams::BindBlobByName(const nsACString &aName,
|
|||||||
return BindByName(aName, value);
|
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
|
NS_IMETHODIMP
|
||||||
BindingParams::BindAdoptedBlobByName(const nsACString &aName,
|
BindingParams::BindAdoptedBlobByName(const nsACString &aName,
|
||||||
@ -493,6 +507,19 @@ BindingParams::BindBlobByIndex(uint32_t aIndex,
|
|||||||
return BindByIndex(aIndex, value);
|
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
|
NS_IMETHODIMP
|
||||||
BindingParams::BindAdoptedBlobByIndex(uint32_t aIndex,
|
BindingParams::BindAdoptedBlobByIndex(uint32_t aIndex,
|
||||||
uint8_t *aValue,
|
uint8_t *aValue,
|
||||||
|
@ -88,6 +88,54 @@ already_AddRefed<nsIRunnable> newCompletionEvent(
|
|||||||
mozIStorageCompletionCallback *aCallback
|
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 storage
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
@ -194,6 +194,18 @@ Row::GetBlob(uint32_t aIndex,
|
|||||||
reinterpret_cast<void **>(_blob));
|
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
|
NS_IMETHODIMP
|
||||||
Row::GetIsNull(uint32_t aIndex,
|
Row::GetIsNull(uint32_t aIndex,
|
||||||
bool *_isNull)
|
bool *_isNull)
|
||||||
|
@ -832,6 +832,18 @@ Statement::GetBlob(uint32_t aIndex,
|
|||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
Statement::GetSharedUTF8String(uint32_t aIndex,
|
Statement::GetSharedUTF8String(uint32_t aIndex,
|
||||||
uint32_t *_length,
|
uint32_t *_length,
|
||||||
|
Loading…
Reference in New Issue
Block a user