storage/public/mozIStorageStatement.idl

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 sts=2 expandtab
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "mozIStorageBaseStatement.idl"
michael@0 8 %{C++
michael@0 9 #include "mozilla/DebugOnly.h"
michael@0 10 %}
michael@0 11
michael@0 12 [ptr] native octetPtr(uint8_t);
michael@0 13
michael@0 14 /**
michael@0 15 * A SQL statement that can be used for both synchronous and asynchronous
michael@0 16 * purposes.
michael@0 17 */
michael@0 18 [scriptable, uuid(b3c4476e-c490-4e3b-9db1-e2d3a6f0287c)]
michael@0 19 interface mozIStorageStatement : mozIStorageBaseStatement {
michael@0 20 /**
michael@0 21 * Create a clone of this statement, by initializing a new statement
michael@0 22 * with the same connection and same SQL statement as this one. It
michael@0 23 * does not preserve statement state; that is, if a statement is
michael@0 24 * being executed when it is cloned, the new statement will not be
michael@0 25 * executing.
michael@0 26 */
michael@0 27 mozIStorageStatement clone();
michael@0 28
michael@0 29 /*
michael@0 30 * Number of parameters
michael@0 31 */
michael@0 32 readonly attribute unsigned long parameterCount;
michael@0 33
michael@0 34 /**
michael@0 35 * Name of nth parameter, if given
michael@0 36 */
michael@0 37 AUTF8String getParameterName(in unsigned long aParamIndex);
michael@0 38
michael@0 39 /**
michael@0 40 * Returns the index of the named parameter.
michael@0 41 *
michael@0 42 * @param aName
michael@0 43 * The name of the parameter you want the index for. This does not
michael@0 44 * include the leading ':'.
michael@0 45 * @return the index of the named parameter.
michael@0 46 */
michael@0 47 unsigned long getParameterIndex(in AUTF8String aName);
michael@0 48
michael@0 49 /**
michael@0 50 * Number of columns returned
michael@0 51 */
michael@0 52 readonly attribute unsigned long columnCount;
michael@0 53
michael@0 54 /**
michael@0 55 * Name of nth column
michael@0 56 */
michael@0 57 AUTF8String getColumnName(in unsigned long aColumnIndex);
michael@0 58
michael@0 59 /**
michael@0 60 * Obtains the index of the column with the specified name.
michael@0 61 *
michael@0 62 * @param aName
michael@0 63 * The name of the column.
michael@0 64 * @return The index of the column with the specified name.
michael@0 65 */
michael@0 66 unsigned long getColumnIndex(in AUTF8String aName);
michael@0 67
michael@0 68 /**
michael@0 69 * Obtains the declared column type of a prepared statement.
michael@0 70 *
michael@0 71 * @param aParamIndex
michael@0 72 * The zero-based index of the column who's declared type we are
michael@0 73 * interested in.
michael@0 74 * @return the declared index type.
michael@0 75 */
michael@0 76 AUTF8String getColumnDecltype(in unsigned long aParamIndex);
michael@0 77
michael@0 78 /**
michael@0 79 * Reset parameters/statement execution
michael@0 80 */
michael@0 81 void reset();
michael@0 82
michael@0 83 /**
michael@0 84 * Execute the query, ignoring any results. This is accomplished by
michael@0 85 * calling executeStep() once, and then calling reset().
michael@0 86 *
michael@0 87 * Error and last insert info, etc. are available from
michael@0 88 * the mozStorageConnection.
michael@0 89 */
michael@0 90 void execute();
michael@0 91
michael@0 92 /**
michael@0 93 * Execute a query, using any currently-bound parameters. Reset
michael@0 94 * must be called on the statement after the last call of
michael@0 95 * executeStep.
michael@0 96 *
michael@0 97 * @return a boolean indicating whether there are more rows or not;
michael@0 98 * row data may be accessed using mozIStorageValueArray methods on
michael@0 99 * the statement.
michael@0 100 */
michael@0 101 boolean executeStep();
michael@0 102
michael@0 103 /**
michael@0 104 * Execute a query, using any currently-bound parameters. Reset is called
michael@0 105 * when no more data is returned. This method is only available to JavaScript
michael@0 106 * consumers.
michael@0 107 *
michael@0 108 * @deprecated As of Mozilla 1.9.2 in favor of executeStep().
michael@0 109 *
michael@0 110 * @return a boolean indicating whether there are more rows or not.
michael@0 111 *
michael@0 112 * [deprecated] boolean step();
michael@0 113 */
michael@0 114
michael@0 115 /**
michael@0 116 * Obtains the current list of named parameters, which are settable. This
michael@0 117 * property is only available to JavaScript consumers.
michael@0 118 *
michael@0 119 * readonly attribute mozIStorageStatementParams params;
michael@0 120 */
michael@0 121
michael@0 122 /**
michael@0 123 * Obtains the current row, with access to all the data members by name. This
michael@0 124 * property is only available to JavaScript consumers.
michael@0 125 *
michael@0 126 * readonly attribute mozIStorageStatementRow row;
michael@0 127 */
michael@0 128
michael@0 129 //////////////////////////////////////////////////////////////////////////////
michael@0 130 //// Copied contents of mozIStorageValueArray
michael@0 131
michael@0 132 /**
michael@0 133 * These type values are returned by getTypeOfIndex
michael@0 134 * to indicate what type of value is present at
michael@0 135 * a given column.
michael@0 136 */
michael@0 137 const long VALUE_TYPE_NULL = 0;
michael@0 138 const long VALUE_TYPE_INTEGER = 1;
michael@0 139 const long VALUE_TYPE_FLOAT = 2;
michael@0 140 const long VALUE_TYPE_TEXT = 3;
michael@0 141 const long VALUE_TYPE_BLOB = 4;
michael@0 142
michael@0 143 /**
michael@0 144 * The number of entries in the array (each corresponding to a column in the
michael@0 145 * database row)
michael@0 146 */
michael@0 147 readonly attribute unsigned long numEntries;
michael@0 148
michael@0 149 /**
michael@0 150 * Indicate the data type of the current result row for the the given column.
michael@0 151 * SQLite will perform type conversion if you ask for a value as a different
michael@0 152 * type than it is stored as.
michael@0 153 *
michael@0 154 * @param aIndex
michael@0 155 * 0-based column index.
michael@0 156 * @return The type of the value at the given column index; one of
michael@0 157 * VALUE_TYPE_NULL, VALUE_TYPE_INTEGER, VALUE_TYPE_FLOAT,
michael@0 158 * VALUE_TYPE_TEXT, VALUE_TYPE_BLOB.
michael@0 159 */
michael@0 160 long getTypeOfIndex(in unsigned long aIndex);
michael@0 161
michael@0 162 /**
michael@0 163 * Retrieve the contents of a column from the current result row as an
michael@0 164 * integer.
michael@0 165 *
michael@0 166 * @param aIndex
michael@0 167 * 0-based colummn index.
michael@0 168 * @return Column value interpreted as an integer per type conversion rules.
michael@0 169 * @{
michael@0 170 */
michael@0 171 long getInt32(in unsigned long aIndex);
michael@0 172 long long getInt64(in unsigned long aIndex);
michael@0 173 /** @} */
michael@0 174 /**
michael@0 175 * Retrieve the contents of a column from the current result row as a
michael@0 176 * floating point double.
michael@0 177 *
michael@0 178 * @param aIndex
michael@0 179 * 0-based colummn index.
michael@0 180 * @return Column value interpreted as a double per type conversion rules.
michael@0 181 */
michael@0 182 double getDouble(in unsigned long aIndex);
michael@0 183 /**
michael@0 184 * Retrieve the contents of a column from the current result row as a
michael@0 185 * string.
michael@0 186 *
michael@0 187 * @param aIndex
michael@0 188 * 0-based colummn index.
michael@0 189 * @return The value for the result column interpreted as a string. If the
michael@0 190 * stored value was NULL, you will get an empty string with IsVoid set
michael@0 191 * to distinguish it from an explicitly set empty string.
michael@0 192 * @{
michael@0 193 */
michael@0 194 AUTF8String getUTF8String(in unsigned long aIndex);
michael@0 195 AString getString(in unsigned long aIndex);
michael@0 196 /** @} */
michael@0 197
michael@0 198 /**
michael@0 199 * Retrieve the contents of a column from the current result row as a
michael@0 200 * blob.
michael@0 201 *
michael@0 202 * @param aIndex
michael@0 203 * 0-based colummn index.
michael@0 204 * @param[out] aDataSize
michael@0 205 * The number of bytes in the blob.
michael@0 206 * @param[out] aData
michael@0 207 * The contents of the BLOB. This will be NULL if aDataSize == 0.
michael@0 208 */
michael@0 209 void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
michael@0 210 /**
michael@0 211 * Check whether the given column in the current result row is NULL.
michael@0 212 *
michael@0 213 * @param aIndex
michael@0 214 * 0-based colummn index.
michael@0 215 * @return true if the value for the result column is null.
michael@0 216 */
michael@0 217 boolean getIsNull(in unsigned long aIndex);
michael@0 218
michael@0 219 /**
michael@0 220 * Returns a shared string pointer
michael@0 221 */
michael@0 222 [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult);
michael@0 223 [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult);
michael@0 224 [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult);
michael@0 225
michael@0 226 %{C++
michael@0 227 /**
michael@0 228 * Getters for native code that return their values as
michael@0 229 * the return type, for convenience and sanity.
michael@0 230 *
michael@0 231 * Not virtual; no vtable bloat.
michael@0 232 */
michael@0 233
michael@0 234 inline int32_t AsInt32(uint32_t idx) {
michael@0 235 int32_t v = 0;
michael@0 236 mozilla::DebugOnly<nsresult> rv = GetInt32(idx, &v);
michael@0 237 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 238 "Getting value failed, wrong column index?");
michael@0 239 return v;
michael@0 240 }
michael@0 241
michael@0 242 inline int64_t AsInt64(uint32_t idx) {
michael@0 243 int64_t v = 0;
michael@0 244 mozilla::DebugOnly<nsresult> rv = GetInt64(idx, &v);
michael@0 245 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 246 "Getting value failed, wrong column index?");
michael@0 247 return v;
michael@0 248 }
michael@0 249
michael@0 250 inline double AsDouble(uint32_t idx) {
michael@0 251 double v = 0.0;
michael@0 252 mozilla::DebugOnly<nsresult> rv = GetDouble(idx, &v);
michael@0 253 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 254 "Getting value failed, wrong column index?");
michael@0 255 return v;
michael@0 256 }
michael@0 257
michael@0 258 inline const char* AsSharedUTF8String(uint32_t idx, uint32_t *len) {
michael@0 259 const char *str = nullptr;
michael@0 260 *len = 0;
michael@0 261 mozilla::DebugOnly<nsresult> rv = GetSharedUTF8String(idx, len, &str);
michael@0 262 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 263 "Getting value failed, wrong column index?");
michael@0 264 return str;
michael@0 265 }
michael@0 266
michael@0 267 inline const char16_t* AsSharedWString(uint32_t idx, uint32_t *len) {
michael@0 268 const char16_t *str = nullptr;
michael@0 269 *len = 0;
michael@0 270 mozilla::DebugOnly<nsresult> rv = GetSharedString(idx, len, &str);
michael@0 271 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 272 "Getting value failed, wrong column index?");
michael@0 273 return str;
michael@0 274 }
michael@0 275
michael@0 276 inline const uint8_t* AsSharedBlob(uint32_t idx, uint32_t *len) {
michael@0 277 const uint8_t *blob = nullptr;
michael@0 278 *len = 0;
michael@0 279 mozilla::DebugOnly<nsresult> rv = GetSharedBlob(idx, len, &blob);
michael@0 280 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
michael@0 281 "Getting value failed, wrong column index?");
michael@0 282 return blob;
michael@0 283 }
michael@0 284
michael@0 285 inline bool IsNull(uint32_t idx) {
michael@0 286 bool b = false;
michael@0 287 mozilla::DebugOnly<nsresult> rv = GetIsNull(idx, &b);
michael@0 288 NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv),
michael@0 289 "Getting value failed, wrong column index?");
michael@0 290 return b;
michael@0 291 }
michael@0 292
michael@0 293 %}
michael@0 294 };

mercurial