michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 sts=2 expandtab michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozIStorageBaseStatement.idl" michael@0: %{C++ michael@0: #include "mozilla/DebugOnly.h" michael@0: %} michael@0: michael@0: [ptr] native octetPtr(uint8_t); michael@0: michael@0: /** michael@0: * A SQL statement that can be used for both synchronous and asynchronous michael@0: * purposes. michael@0: */ michael@0: [scriptable, uuid(b3c4476e-c490-4e3b-9db1-e2d3a6f0287c)] michael@0: interface mozIStorageStatement : mozIStorageBaseStatement { michael@0: /** michael@0: * Create a clone of this statement, by initializing a new statement michael@0: * with the same connection and same SQL statement as this one. It michael@0: * does not preserve statement state; that is, if a statement is michael@0: * being executed when it is cloned, the new statement will not be michael@0: * executing. michael@0: */ michael@0: mozIStorageStatement clone(); michael@0: michael@0: /* michael@0: * Number of parameters michael@0: */ michael@0: readonly attribute unsigned long parameterCount; michael@0: michael@0: /** michael@0: * Name of nth parameter, if given michael@0: */ michael@0: AUTF8String getParameterName(in unsigned long aParamIndex); michael@0: michael@0: /** michael@0: * Returns the index of the named parameter. michael@0: * michael@0: * @param aName michael@0: * The name of the parameter you want the index for. This does not michael@0: * include the leading ':'. michael@0: * @return the index of the named parameter. michael@0: */ michael@0: unsigned long getParameterIndex(in AUTF8String aName); michael@0: michael@0: /** michael@0: * Number of columns returned michael@0: */ michael@0: readonly attribute unsigned long columnCount; michael@0: michael@0: /** michael@0: * Name of nth column michael@0: */ michael@0: AUTF8String getColumnName(in unsigned long aColumnIndex); michael@0: michael@0: /** michael@0: * Obtains the index of the column with the specified name. michael@0: * michael@0: * @param aName michael@0: * The name of the column. michael@0: * @return The index of the column with the specified name. michael@0: */ michael@0: unsigned long getColumnIndex(in AUTF8String aName); michael@0: michael@0: /** michael@0: * Obtains the declared column type of a prepared statement. michael@0: * michael@0: * @param aParamIndex michael@0: * The zero-based index of the column who's declared type we are michael@0: * interested in. michael@0: * @return the declared index type. michael@0: */ michael@0: AUTF8String getColumnDecltype(in unsigned long aParamIndex); michael@0: michael@0: /** michael@0: * Reset parameters/statement execution michael@0: */ michael@0: void reset(); michael@0: michael@0: /** michael@0: * Execute the query, ignoring any results. This is accomplished by michael@0: * calling executeStep() once, and then calling reset(). michael@0: * michael@0: * Error and last insert info, etc. are available from michael@0: * the mozStorageConnection. michael@0: */ michael@0: void execute(); michael@0: michael@0: /** michael@0: * Execute a query, using any currently-bound parameters. Reset michael@0: * must be called on the statement after the last call of michael@0: * executeStep. michael@0: * michael@0: * @return a boolean indicating whether there are more rows or not; michael@0: * row data may be accessed using mozIStorageValueArray methods on michael@0: * the statement. michael@0: */ michael@0: boolean executeStep(); michael@0: michael@0: /** michael@0: * Execute a query, using any currently-bound parameters. Reset is called michael@0: * when no more data is returned. This method is only available to JavaScript michael@0: * consumers. michael@0: * michael@0: * @deprecated As of Mozilla 1.9.2 in favor of executeStep(). michael@0: * michael@0: * @return a boolean indicating whether there are more rows or not. michael@0: * michael@0: * [deprecated] boolean step(); michael@0: */ michael@0: michael@0: /** michael@0: * Obtains the current list of named parameters, which are settable. This michael@0: * property is only available to JavaScript consumers. michael@0: * michael@0: * readonly attribute mozIStorageStatementParams params; michael@0: */ michael@0: michael@0: /** michael@0: * Obtains the current row, with access to all the data members by name. This michael@0: * property is only available to JavaScript consumers. michael@0: * michael@0: * readonly attribute mozIStorageStatementRow row; michael@0: */ michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Copied contents of mozIStorageValueArray michael@0: michael@0: /** michael@0: * These type values are returned by getTypeOfIndex michael@0: * to indicate what type of value is present at michael@0: * a given column. michael@0: */ michael@0: const long VALUE_TYPE_NULL = 0; michael@0: const long VALUE_TYPE_INTEGER = 1; michael@0: const long VALUE_TYPE_FLOAT = 2; michael@0: const long VALUE_TYPE_TEXT = 3; michael@0: const long VALUE_TYPE_BLOB = 4; michael@0: michael@0: /** michael@0: * The number of entries in the array (each corresponding to a column in the michael@0: * database row) michael@0: */ michael@0: readonly attribute unsigned long numEntries; michael@0: michael@0: /** michael@0: * Indicate the data type of the current result row for the the given column. michael@0: * SQLite will perform type conversion if you ask for a value as a different michael@0: * type than it is stored as. michael@0: * michael@0: * @param aIndex michael@0: * 0-based column index. michael@0: * @return The type of the value at the given column index; one of michael@0: * VALUE_TYPE_NULL, VALUE_TYPE_INTEGER, VALUE_TYPE_FLOAT, michael@0: * VALUE_TYPE_TEXT, VALUE_TYPE_BLOB. michael@0: */ michael@0: long getTypeOfIndex(in unsigned long aIndex); michael@0: michael@0: /** michael@0: * Retrieve the contents of a column from the current result row as an michael@0: * integer. michael@0: * michael@0: * @param aIndex michael@0: * 0-based colummn index. michael@0: * @return Column value interpreted as an integer per type conversion rules. michael@0: * @{ michael@0: */ michael@0: long getInt32(in unsigned long aIndex); michael@0: long long getInt64(in unsigned long aIndex); michael@0: /** @} */ michael@0: /** michael@0: * Retrieve the contents of a column from the current result row as a michael@0: * floating point double. michael@0: * michael@0: * @param aIndex michael@0: * 0-based colummn index. michael@0: * @return Column value interpreted as a double per type conversion rules. michael@0: */ michael@0: double getDouble(in unsigned long aIndex); michael@0: /** michael@0: * Retrieve the contents of a column from the current result row as a michael@0: * string. michael@0: * michael@0: * @param aIndex michael@0: * 0-based colummn index. michael@0: * @return The value for the result column interpreted as a string. If the michael@0: * stored value was NULL, you will get an empty string with IsVoid set michael@0: * to distinguish it from an explicitly set empty string. michael@0: * @{ michael@0: */ michael@0: AUTF8String getUTF8String(in unsigned long aIndex); michael@0: AString getString(in unsigned long aIndex); michael@0: /** @} */ michael@0: michael@0: /** michael@0: * Retrieve the contents of a column from the current result row as a michael@0: * blob. michael@0: * michael@0: * @param aIndex michael@0: * 0-based colummn index. michael@0: * @param[out] aDataSize michael@0: * The number of bytes in the blob. michael@0: * @param[out] aData michael@0: * The contents of the BLOB. This will be NULL if aDataSize == 0. michael@0: */ michael@0: void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData); michael@0: /** michael@0: * Check whether the given column in the current result row is NULL. michael@0: * michael@0: * @param aIndex michael@0: * 0-based colummn index. michael@0: * @return true if the value for the result column is null. michael@0: */ michael@0: boolean getIsNull(in unsigned long aIndex); michael@0: michael@0: /** michael@0: * Returns a shared string pointer michael@0: */ michael@0: [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult); michael@0: [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult); michael@0: [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult); michael@0: michael@0: %{C++ michael@0: /** michael@0: * Getters for native code that return their values as michael@0: * the return type, for convenience and sanity. michael@0: * michael@0: * Not virtual; no vtable bloat. michael@0: */ michael@0: michael@0: inline int32_t AsInt32(uint32_t idx) { michael@0: int32_t v = 0; michael@0: mozilla::DebugOnly rv = GetInt32(idx, &v); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return v; michael@0: } michael@0: michael@0: inline int64_t AsInt64(uint32_t idx) { michael@0: int64_t v = 0; michael@0: mozilla::DebugOnly rv = GetInt64(idx, &v); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return v; michael@0: } michael@0: michael@0: inline double AsDouble(uint32_t idx) { michael@0: double v = 0.0; michael@0: mozilla::DebugOnly rv = GetDouble(idx, &v); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return v; michael@0: } michael@0: michael@0: inline const char* AsSharedUTF8String(uint32_t idx, uint32_t *len) { michael@0: const char *str = nullptr; michael@0: *len = 0; michael@0: mozilla::DebugOnly rv = GetSharedUTF8String(idx, len, &str); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return str; michael@0: } michael@0: michael@0: inline const char16_t* AsSharedWString(uint32_t idx, uint32_t *len) { michael@0: const char16_t *str = nullptr; michael@0: *len = 0; michael@0: mozilla::DebugOnly rv = GetSharedString(idx, len, &str); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return str; michael@0: } michael@0: michael@0: inline const uint8_t* AsSharedBlob(uint32_t idx, uint32_t *len) { michael@0: const uint8_t *blob = nullptr; michael@0: *len = 0; michael@0: mozilla::DebugOnly rv = GetSharedBlob(idx, len, &blob); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx), michael@0: "Getting value failed, wrong column index?"); michael@0: return blob; michael@0: } michael@0: michael@0: inline bool IsNull(uint32_t idx) { michael@0: bool b = false; michael@0: mozilla::DebugOnly rv = GetIsNull(idx, &b); michael@0: NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), michael@0: "Getting value failed, wrong column index?"); michael@0: return b; michael@0: } michael@0: michael@0: %} michael@0: };