1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #include "mozStoragePrivateHelpers.h"
12 #include "mozStorageArgValueArray.h"
17 ////////////////////////////////////////////////////////////////////////////////
20 ArgValueArray::ArgValueArray(int32_t aArgc
, sqlite3_value
** aArgv
)
21 : mArgc(aArgc
), mArgv(aArgv
) {}
23 NS_IMPL_ISUPPORTS(ArgValueArray
, mozIStorageValueArray
)
25 ////////////////////////////////////////////////////////////////////////////////
26 //// mozIStorageValueArray
29 ArgValueArray::GetNumEntries(uint32_t* _size
) {
35 ArgValueArray::GetTypeOfIndex(uint32_t aIndex
, int32_t* _type
) {
36 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
38 int t
= ::sqlite3_value_type(mArgv
[aIndex
]);
41 *_type
= VALUE_TYPE_INTEGER
;
44 *_type
= VALUE_TYPE_FLOAT
;
47 *_type
= VALUE_TYPE_TEXT
;
50 *_type
= VALUE_TYPE_BLOB
;
53 *_type
= VALUE_TYPE_NULL
;
56 return NS_ERROR_FAILURE
;
63 ArgValueArray::GetInt32(uint32_t aIndex
, int32_t* _value
) {
64 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
66 *_value
= ::sqlite3_value_int(mArgv
[aIndex
]);
71 ArgValueArray::GetInt64(uint32_t aIndex
, int64_t* _value
) {
72 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
74 *_value
= ::sqlite3_value_int64(mArgv
[aIndex
]);
79 ArgValueArray::GetDouble(uint32_t aIndex
, double* _value
) {
80 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
82 *_value
= ::sqlite3_value_double(mArgv
[aIndex
]);
87 ArgValueArray::GetUTF8String(uint32_t aIndex
, nsACString
& _value
) {
88 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
90 if (::sqlite3_value_type(mArgv
[aIndex
]) == SQLITE_NULL
) {
91 // NULL columns should have IsVoid set to distinguish them from an empty
93 _value
.SetIsVoid(true);
96 reinterpret_cast<const char*>(::sqlite3_value_text(mArgv
[aIndex
])),
97 ::sqlite3_value_bytes(mArgv
[aIndex
]));
103 ArgValueArray::GetString(uint32_t aIndex
, nsAString
& _value
) {
104 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
106 if (::sqlite3_value_type(mArgv
[aIndex
]) == SQLITE_NULL
) {
107 // NULL columns should have IsVoid set to distinguish them from an empty
109 _value
.SetIsVoid(true);
111 const char16_t
* string
=
112 static_cast<const char16_t
*>(::sqlite3_value_text16(mArgv
[aIndex
]));
113 _value
.Assign(string
,
114 ::sqlite3_value_bytes16(mArgv
[aIndex
]) / sizeof(char16_t
));
120 ArgValueArray::GetBlob(uint32_t aIndex
, uint32_t* _size
, uint8_t** _blob
) {
121 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
123 int size
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
124 void* blob
= moz_xmemdup(::sqlite3_value_blob(mArgv
[aIndex
]), size
);
125 *_blob
= static_cast<uint8_t*>(blob
);
131 ArgValueArray::GetBlobAsString(uint32_t aIndex
, nsAString
& aValue
) {
132 return DoGetBlobAsString(this, aIndex
, aValue
);
136 ArgValueArray::GetBlobAsUTF8String(uint32_t aIndex
, nsACString
& aValue
) {
137 return DoGetBlobAsString(this, aIndex
, aValue
);
141 ArgValueArray::GetIsNull(uint32_t aIndex
, bool* _isNull
) {
142 // GetTypeOfIndex will check aIndex for us, so we don't have to.
144 nsresult rv
= GetTypeOfIndex(aIndex
, &type
);
145 NS_ENSURE_SUCCESS(rv
, rv
);
147 *_isNull
= (type
== VALUE_TYPE_NULL
);
152 ArgValueArray::GetSharedUTF8String(uint32_t aIndex
, uint32_t* _byteLength
,
153 const char** _string
) {
154 *_string
= reinterpret_cast<const char*>(::sqlite3_value_text(mArgv
[aIndex
]));
156 *_byteLength
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
162 ArgValueArray::GetSharedString(uint32_t aIndex
, uint32_t* _byteLength
,
163 const char16_t
** _string
) {
165 static_cast<const char16_t
*>(::sqlite3_value_text16(mArgv
[aIndex
]));
167 *_byteLength
= ::sqlite3_value_bytes16(mArgv
[aIndex
]);
173 ArgValueArray::GetSharedBlob(uint32_t aIndex
, uint32_t* _byteLength
,
174 const uint8_t** _blob
) {
175 *_blob
= static_cast<const uint8_t*>(::sqlite3_value_blob(mArgv
[aIndex
]));
177 *_byteLength
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
182 } // namespace storage
183 } // namespace mozilla