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/. */
10 #include "mozStoragePrivateHelpers.h"
11 #include "mozStorageArgValueArray.h"
16 ////////////////////////////////////////////////////////////////////////////////
19 ArgValueArray::ArgValueArray(int32_t aArgc
, sqlite3_value
** aArgv
)
20 : mArgc(aArgc
), mArgv(aArgv
) {}
22 NS_IMPL_ISUPPORTS(ArgValueArray
, mozIStorageValueArray
)
24 ////////////////////////////////////////////////////////////////////////////////
25 //// mozIStorageValueArray
28 ArgValueArray::GetNumEntries(uint32_t* _size
) {
34 ArgValueArray::GetTypeOfIndex(uint32_t aIndex
, int32_t* _type
) {
35 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
37 int t
= ::sqlite3_value_type(mArgv
[aIndex
]);
40 *_type
= VALUE_TYPE_INTEGER
;
43 *_type
= VALUE_TYPE_FLOAT
;
46 *_type
= VALUE_TYPE_TEXT
;
49 *_type
= VALUE_TYPE_BLOB
;
52 *_type
= VALUE_TYPE_NULL
;
55 return NS_ERROR_FAILURE
;
62 ArgValueArray::GetInt32(uint32_t aIndex
, int32_t* _value
) {
63 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
65 *_value
= ::sqlite3_value_int(mArgv
[aIndex
]);
70 ArgValueArray::GetInt64(uint32_t aIndex
, int64_t* _value
) {
71 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
73 *_value
= ::sqlite3_value_int64(mArgv
[aIndex
]);
78 ArgValueArray::GetDouble(uint32_t aIndex
, double* _value
) {
79 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
81 *_value
= ::sqlite3_value_double(mArgv
[aIndex
]);
86 ArgValueArray::GetUTF8String(uint32_t aIndex
, nsACString
& _value
) {
87 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
89 if (::sqlite3_value_type(mArgv
[aIndex
]) == SQLITE_NULL
) {
90 // NULL columns should have IsVoid set to distinguish them from an empty
92 _value
.SetIsVoid(true);
95 reinterpret_cast<const char*>(::sqlite3_value_text(mArgv
[aIndex
])),
96 ::sqlite3_value_bytes(mArgv
[aIndex
]));
102 ArgValueArray::GetString(uint32_t aIndex
, nsAString
& _value
) {
103 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
105 if (::sqlite3_value_type(mArgv
[aIndex
]) == SQLITE_NULL
) {
106 // NULL columns should have IsVoid set to distinguish them from an empty
108 _value
.SetIsVoid(true);
110 const char16_t
* string
=
111 static_cast<const char16_t
*>(::sqlite3_value_text16(mArgv
[aIndex
]));
112 _value
.Assign(string
,
113 ::sqlite3_value_bytes16(mArgv
[aIndex
]) / sizeof(char16_t
));
119 ArgValueArray::GetBlob(uint32_t aIndex
, uint32_t* _size
, uint8_t** _blob
) {
120 ENSURE_INDEX_VALUE(aIndex
, mArgc
);
122 int size
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
123 void* blob
= moz_xmemdup(::sqlite3_value_blob(mArgv
[aIndex
]), size
);
124 *_blob
= static_cast<uint8_t*>(blob
);
130 ArgValueArray::GetBlobAsString(uint32_t aIndex
, nsAString
& aValue
) {
131 return DoGetBlobAsString(this, aIndex
, aValue
);
135 ArgValueArray::GetBlobAsUTF8String(uint32_t aIndex
, nsACString
& aValue
) {
136 return DoGetBlobAsString(this, aIndex
, aValue
);
140 ArgValueArray::GetIsNull(uint32_t aIndex
, bool* _isNull
) {
141 // GetTypeOfIndex will check aIndex for us, so we don't have to.
143 nsresult rv
= GetTypeOfIndex(aIndex
, &type
);
144 NS_ENSURE_SUCCESS(rv
, rv
);
146 *_isNull
= (type
== VALUE_TYPE_NULL
);
151 ArgValueArray::GetSharedUTF8String(uint32_t aIndex
, uint32_t* _byteLength
,
152 const char** _string
) {
153 *_string
= reinterpret_cast<const char*>(::sqlite3_value_text(mArgv
[aIndex
]));
155 *_byteLength
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
161 ArgValueArray::GetSharedString(uint32_t aIndex
, uint32_t* _byteLength
,
162 const char16_t
** _string
) {
164 static_cast<const char16_t
*>(::sqlite3_value_text16(mArgv
[aIndex
]));
166 *_byteLength
= ::sqlite3_value_bytes16(mArgv
[aIndex
]);
172 ArgValueArray::GetSharedBlob(uint32_t aIndex
, uint32_t* _byteLength
,
173 const uint8_t** _blob
) {
174 *_blob
= static_cast<const uint8_t*>(::sqlite3_value_blob(mArgv
[aIndex
]));
176 *_byteLength
= ::sqlite3_value_bytes(mArgv
[aIndex
]);
181 } // namespace storage
182 } // namespace mozilla