diff --git a/storage/public/mozIStorageBaseStatement.idl b/storage/public/mozIStorageBaseStatement.idl index 439d3e886ad..52cd3050015 100644 --- a/storage/public/mozIStorageBaseStatement.idl +++ b/storage/public/mozIStorageBaseStatement.idl @@ -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, diff --git a/storage/public/mozIStorageBindingParams.idl b/storage/public/mozIStorageBindingParams.idl index 3e98a996c7f..81d9e6efb3f 100644 --- a/storage/public/mozIStorageBindingParams.idl +++ b/storage/public/mozIStorageBindingParams.idl @@ -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. diff --git a/storage/public/mozIStorageStatement.idl b/storage/public/mozIStorageStatement.idl index 329ce280dc4..28abc59791e 100644 --- a/storage/public/mozIStorageStatement.idl +++ b/storage/public/mozIStorageStatement.idl @@ -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. * diff --git a/storage/public/mozIStorageValueArray.idl b/storage/public/mozIStorageValueArray.idl index fd1de2a9d4a..3dbf75285eb 100644 --- a/storage/public/mozIStorageValueArray.idl +++ b/storage/public/mozIStorageValueArray.idl @@ -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); /** diff --git a/storage/src/StorageBaseStatementInternal.h b/storage/src/StorageBaseStatementInternal.h index 20b289fc1bf..50053008595 100644 --- a/storage/src/StorageBaseStatementInternal.h +++ b/storage/src/StorageBaseStatementInternal.h @@ -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, \ diff --git a/storage/src/mozStorageArgValueArray.cpp b/storage/src/mozStorageArgValueArray.cpp index 019788512ea..3b9daab2fd0 100644 --- a/storage/src/mozStorageArgValueArray.cpp +++ b/storage/src/mozStorageArgValueArray.cpp @@ -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) diff --git a/storage/src/mozStorageBindingParams.cpp b/storage/src/mozStorageBindingParams.cpp index d8c2fded5fb..359bdd8b5a3 100644 --- a/storage/src/mozStorageBindingParams.cpp +++ b/storage/src/mozStorageBindingParams.cpp @@ -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, diff --git a/storage/src/mozStoragePrivateHelpers.h b/storage/src/mozStoragePrivateHelpers.h index 718ad402c1b..e29188ce58e 100644 --- a/storage/src/mozStoragePrivateHelpers.h +++ b/storage/src/mozStoragePrivateHelpers.h @@ -88,6 +88,54 @@ already_AddRefed newCompletionEvent( mozIStorageCompletionCallback *aCallback ); +/** + * Utility method to get a Blob as a string value. The string expects + * the interface exposed by nsAString/nsACString/etc. + */ +template +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(&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 +nsresult +DoBindStringAsBlobByName(T* aThis, const nsACString& aName, const V& aValue) +{ + typedef typename V::char_type char_type; + return aThis->BindBlobByName(aName, + reinterpret_cast(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 +nsresult +DoBindStringAsBlobByIndex(T* aThis, uint32_t aIndex, const V& aValue) +{ + typedef typename V::char_type char_type; + return aThis->BindBlobByIndex(aIndex, + reinterpret_cast(aValue.BeginReading()), + aValue.Length() * sizeof(char_type)); +} + } // namespace storage } // namespace mozilla diff --git a/storage/src/mozStorageRow.cpp b/storage/src/mozStorageRow.cpp index 9f28151e097..7bcac4c3010 100644 --- a/storage/src/mozStorageRow.cpp +++ b/storage/src/mozStorageRow.cpp @@ -194,6 +194,18 @@ Row::GetBlob(uint32_t aIndex, reinterpret_cast(_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) diff --git a/storage/src/mozStorageStatement.cpp b/storage/src/mozStorageStatement.cpp index 8155056d621..9fdc49b9fff 100644 --- a/storage/src/mozStorageStatement.cpp +++ b/storage/src/mozStorageStatement.cpp @@ -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,