зеркало из https://github.com/mozilla/pjs.git
Bug 490867 - Variant fixes: coerce null to empty string, GetIsNull should check correct type, variant base type should be void, r=sdwilsh
Adds a NullVariant derived class of Variant_base.
This commit is contained in:
Родитель
51f2e02a74
Коммит
4427484d44
|
@ -22,6 +22,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
||||
* Drew Willcoxon <adw@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -299,6 +300,37 @@ struct variant_blob_traits<PRUint8[]>
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* NULL type
|
||||
*/
|
||||
|
||||
class NullVariant : public Variant_base
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD GetDataType(PRUint16 *_type)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_type);
|
||||
*_type = nsIDataType::VTYPE_EMPTY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAsAUTF8String(nsACString &_str)
|
||||
{
|
||||
// Return a void string.
|
||||
_str.Truncate(0);
|
||||
_str.SetIsVoid(PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAsAString(nsAString &_str)
|
||||
{
|
||||
// Return a void string.
|
||||
_str.Truncate(0);
|
||||
_str.SetIsVoid(PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Template Implementation
|
||||
|
||||
|
@ -361,7 +393,6 @@ typedef Variant<double> FloatVariant;
|
|||
typedef Variant<nsString> TextVariant;
|
||||
typedef Variant<nsCString> UTF8TextVariant;
|
||||
typedef Variant<PRUint8[]> BlobVariant;
|
||||
typedef Variant_base NullVariant;
|
||||
|
||||
} // namespace storage
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -65,7 +65,8 @@ inline
|
|||
NS_IMETHODIMP
|
||||
Variant_base::GetDataType(PRUint16 *_type)
|
||||
{
|
||||
*_type = nsIDataType::VTYPE_EMPTY;
|
||||
NS_ENSURE_ARG_POINTER(_type);
|
||||
*_type = nsIDataType::VTYPE_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -235,10 +235,11 @@ Row::GetIsNull(PRUint32 aIndex,
|
|||
PRBool *_isNull)
|
||||
{
|
||||
ENSURE_INDEX_VALUE(aIndex, mNumCols);
|
||||
NS_ENSURE_ARG_POINTER(_isNull);
|
||||
|
||||
PRUint16 type;
|
||||
(void)mData.ObjectAt(aIndex)->GetDataType(&type);
|
||||
*_isNull = type == nsIDataType::VTYPE_VOID;
|
||||
*_isNull = type == nsIDataType::VTYPE_EMPTY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -167,21 +167,25 @@ function test_get_data()
|
|||
do_check_neq(null, tuple);
|
||||
|
||||
// Check that it's what we expect
|
||||
do_check_false(tuple.getIsNull(0));
|
||||
do_check_eq(tuple.getResultByName("string"), tuple.getResultByIndex(0));
|
||||
do_check_eq(TEXT, tuple.getResultByName("string"));
|
||||
do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_TEXT,
|
||||
tuple.getTypeOfIndex(0));
|
||||
|
||||
do_check_false(tuple.getIsNull(1));
|
||||
do_check_eq(tuple.getResultByName("number"), tuple.getResultByIndex(1));
|
||||
do_check_eq(REAL, tuple.getResultByName("number"));
|
||||
do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT,
|
||||
tuple.getTypeOfIndex(1));
|
||||
|
||||
do_check_true(tuple.getIsNull(2));
|
||||
do_check_eq(tuple.getResultByName("nuller"), tuple.getResultByIndex(2));
|
||||
do_check_eq(null, tuple.getResultByName("nuller"));
|
||||
do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_NULL,
|
||||
tuple.getTypeOfIndex(2));
|
||||
|
||||
do_check_false(tuple.getIsNull(3));
|
||||
var blobByName = tuple.getResultByName("blober");
|
||||
do_check_eq(BLOB.length, blobByName.length);
|
||||
var blobByIndex = tuple.getResultByIndex(3);
|
||||
|
@ -199,6 +203,7 @@ function test_get_data()
|
|||
do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_BLOB,
|
||||
tuple.getTypeOfIndex(3));
|
||||
|
||||
do_check_false(tuple.getIsNull(4));
|
||||
do_check_eq(tuple.getResultByName("id"), tuple.getResultByIndex(4));
|
||||
do_check_eq(INTEGER, tuple.getResultByName("id"));
|
||||
do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER,
|
||||
|
|
Загрузка…
Ссылка в новой задаче