1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/public/mozIStorageValueArray.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsISupports.idl" 1.10 +%{C++ 1.11 +#include "mozilla/DebugOnly.h" 1.12 +%} 1.13 + 1.14 +[ptr] native octetPtr(uint8_t); 1.15 + 1.16 +/** 1.17 + * mozIStorageValueArray wraps an array of SQL values, such as a single database 1.18 + * row. 1.19 + */ 1.20 +[scriptable, uuid(07b5b93e-113c-4150-863c-d247b003a55d)] 1.21 +interface mozIStorageValueArray : nsISupports { 1.22 + /** 1.23 + * These type values are returned by getTypeOfIndex 1.24 + * to indicate what type of value is present at 1.25 + * a given column. 1.26 + */ 1.27 + const long VALUE_TYPE_NULL = 0; 1.28 + const long VALUE_TYPE_INTEGER = 1; 1.29 + const long VALUE_TYPE_FLOAT = 2; 1.30 + const long VALUE_TYPE_TEXT = 3; 1.31 + const long VALUE_TYPE_BLOB = 4; 1.32 + 1.33 + /** 1.34 + * numEntries 1.35 + * 1.36 + * number of entries in the array (each corresponding to a column 1.37 + * in the database row) 1.38 + */ 1.39 + readonly attribute unsigned long numEntries; 1.40 + 1.41 + /** 1.42 + * Returns the type of the value at the given column index; 1.43 + * one of VALUE_TYPE_NULL, VALUE_TYPE_INTEGER, VALUE_TYPE_FLOAT, 1.44 + * VALUE_TYPE_TEXT, VALUE_TYPE_BLOB. 1.45 + */ 1.46 + long getTypeOfIndex(in unsigned long aIndex); 1.47 + 1.48 + /** 1.49 + * Obtain a value for the given entry (column) index. 1.50 + * Due to SQLite's type conversion rules, any of these are valid 1.51 + * for any column regardless of the column's data type. However, 1.52 + * if the specific type matters, getTypeOfIndex should be used 1.53 + * first to identify the column type, and then the appropriate 1.54 + * get method should be called. 1.55 + * 1.56 + * If you ask for a string value for a NULL column, you will get an empty 1.57 + * string with IsVoid set to distinguish it from an explicitly set empty 1.58 + * string. 1.59 + */ 1.60 + long getInt32(in unsigned long aIndex); 1.61 + long long getInt64(in unsigned long aIndex); 1.62 + double getDouble(in unsigned long aIndex); 1.63 + AUTF8String getUTF8String(in unsigned long aIndex); 1.64 + AString getString(in unsigned long aIndex); 1.65 + 1.66 + // data will be NULL if dataSize = 0 1.67 + void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData); 1.68 + boolean getIsNull(in unsigned long aIndex); 1.69 + 1.70 + /** 1.71 + * Returns a shared string pointer 1.72 + */ 1.73 + [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult); 1.74 + [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult); 1.75 + [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult); 1.76 + 1.77 +%{C++ 1.78 + /** 1.79 + * Getters for native code that return their values as 1.80 + * the return type, for convenience and sanity. 1.81 + * 1.82 + * Not virtual; no vtable bloat. 1.83 + */ 1.84 + 1.85 + inline int32_t AsInt32(uint32_t idx) { 1.86 + int32_t v = 0; 1.87 + mozilla::DebugOnly<nsresult> rv = GetInt32(idx, &v); 1.88 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.89 + "Getting value failed, wrong column index?"); 1.90 + return v; 1.91 + } 1.92 + 1.93 + inline int64_t AsInt64(uint32_t idx) { 1.94 + int64_t v = 0; 1.95 + mozilla::DebugOnly<nsresult> rv = GetInt64(idx, &v); 1.96 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.97 + "Getting value failed, wrong column index?"); 1.98 + return v; 1.99 + } 1.100 + 1.101 + inline double AsDouble(uint32_t idx) { 1.102 + double v = 0.0; 1.103 + mozilla::DebugOnly<nsresult> rv = GetDouble(idx, &v); 1.104 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.105 + "Getting value failed, wrong column index?"); 1.106 + return v; 1.107 + } 1.108 + 1.109 + inline const char* AsSharedUTF8String(uint32_t idx, uint32_t *len) { 1.110 + const char *str = nullptr; 1.111 + *len = 0; 1.112 + mozilla::DebugOnly<nsresult> rv = GetSharedUTF8String(idx, len, &str); 1.113 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.114 + "Getting value failed, wrong column index?"); 1.115 + return str; 1.116 + } 1.117 + 1.118 + inline const char16_t* AsSharedWString(uint32_t idx, uint32_t *len) { 1.119 + const char16_t *str = nullptr; 1.120 + *len = 0; 1.121 + mozilla::DebugOnly<nsresult> rv = GetSharedString(idx, len, &str); 1.122 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.123 + "Getting value failed, wrong column index?"); 1.124 + return str; 1.125 + } 1.126 + 1.127 + inline const uint8_t* AsSharedBlob(uint32_t idx, uint32_t *len) { 1.128 + const uint8_t *blob = nullptr; 1.129 + *len = 0; 1.130 + mozilla::DebugOnly<nsresult> rv = GetSharedBlob(idx, len, &blob); 1.131 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), 1.132 + "Getting value failed, wrong column index?"); 1.133 + return blob; 1.134 + } 1.135 + 1.136 + inline bool IsNull(uint32_t idx) { 1.137 + bool b = false; 1.138 + mozilla::DebugOnly<nsresult> rv = GetIsNull(idx, &b); 1.139 + NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), 1.140 + "Getting value failed, wrong column index?"); 1.141 + return b; 1.142 + } 1.143 + 1.144 +%} 1.145 + 1.146 +};