mozIStorageValueArray

  • Revision slug: mozIStorageValueArray
  • Revision title: mozIStorageValueArray
  • Revision id: 137594
  • Created:
  • Creator: Arehman4
  • Is current revision? No
  • Comment New page: <breadcrumbs></breadcrumbs> __TOC__ == Summary == <code>mozIStorageValueArray</code> wraps an array of SQL values, such as a single database row. {{InterfaceStatus|mozIStorageValueArray|s...

Revision Content

Summary

mozIStorageValueArray wraps an array of SQL values, such as a single database row.

{{template.InterfaceStatus("mozIStorageValueArray", "storage/public/mozIStorageValueArray.idl", "unfrozen", "Mozilla 2.0 alpha 2", "yes")}}

Inherits from: nsISupports

JavaScript example of opening a connection to "asdf.sqlite" in the user's profile directory:


Note: The OpenDatabase function is subject to change. It will likely be enhanced/simplified to make it more difficult to get into trouble.

Interface Code

[scriptable, uuid(07b5b93e-113c-4150-863c-d247b003a55d)]
interface mozIStorageValueArray : nsISupports {
{
  /* Type Values */
  const long VALUE_TYPE_NULL = 0;
  const long VALUE_TYPE_INTEGER = 1;
  const long VALUE_TYPE_FLOAT = 2;
  const long VALUE_TYPE_TEXT = 3;
  const long VALUE_TYPE_BLOB = 4;

  /* Attributes */
  readonly attribute unsigned long numEntries;
  
  /* Methods */
  long getTypeOfIndex(in unsigned long aIndex);
  long getInt32(in unsigned long aIndex);
  long long getInt64(in unsigned long aIndex);
  double getDouble(in unsigned long aIndex);
  AUTF8String getUTF8String(in unsigned long aIndex);
  AString getString(in unsigned long aIndex);
  void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
  boolean getIsNull(in unsigned long aIndex);
  [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult);
  [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult);
  [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult);

%{C++
  inline PRInt32 AsInt32(PRUint32 idx) {
    PRInt32 v;
    GetInt32(idx, &v);
    return v;
  }
  
  inline PRInt64 AsInt64(PRUint32 idx) {
    PRInt64 v;
    GetInt64(idx, &v);
    return v;
  }
  
  inline double AsDouble(PRUint32 idx) {
    double v;
    GetDouble(idx, &v);
    return v;
  }
 
  inline const char* AsSharedUTF8String(PRUint32 idx, PRUint32 *len) {
    const char *str = nsnull;
    GetSharedUTF8String(idx, len, &str);
    return str;
  }
  
 inline const PRUnichar* AsSharedWString(PRUint32 idx, PRUint32 *len) {
   const PRUnichar *str = nsnull;
   GetSharedString(idx, len, &str);
   return str;
 }
  
 inline const PRUint8* AsSharedBlob(PRUint32 idx, PRUint32 *len) {
   const PRUint8 *blob = nsnull;
   GetSharedBlob(idx, len, &blob);
   return blob;
 }
  
 inline PRBool IsNull(PRUint32 idx) {
   PRBool b = PR_FALSE;
   GetIsNull(idx, &b);
   return b;
 }
%}
};

Methods

openSpecialDatabase

  mozIStorageConnection openSpecialDatabase(in string aStorageKey);

openSpecialDatabase returns a new mozIStorageConnection for the requested storage database. It retrieves a connection to a named special database storage by the use of aStorageKey parameter which is a string key that identifies the type of storage requested. Valid values for aStorageKey parameter includes "profile" and "memory" strings as defined through the preprocessor macros "MOZ_STORAGE_MEMORY_STORAGE_KEY", "MOZ_STORAGE_PROFILE_STORAGE_KEY".

If aStorageKey string key holds invalid value, then the NS_ERROR_INVALID_ARG exception is thrown.

Note: Read the summary of this Interface to understand the restrictions on how database connections may be used. For this profile database, you should only access it from the main thread since other callers may also have connections.

openDatabase

  mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);

openDatabase returns a new mozIStorageConnection for the requested database file. It Open a database connection to the specified file by the use of aDatabaseFile parameter which is a nsIFile of the database to open.

If the operation fails while opening the database, then the NS_ERROR_FAILURE exception is thrown.

Warning: If you have more than one connection to a file, you MUST use the EXACT SAME NAME for the file each time, including case. The sqlite code uses a simple string compare to see if there is already a connection. Opening a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. Opening connections from more than one thread to the same database will also CORRUPT YOUR DATABASE. All connections share the same sqlite cache, and the cache is not threadsafe. The connection object returned by this function is not threadsafe. You must use it only from the thread you created it from.

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p><code>mozIStorageValueArray</code> wraps an array of SQL values, such as a single database row.
</p><p>{{template.InterfaceStatus("mozIStorageValueArray", "storage/public/mozIStorageValueArray.idl", "unfrozen", "Mozilla 2.0 alpha 2", "yes")}}
</p><p>Inherits from: <a href="en/NsISupports">nsISupports</a>
</p><p>JavaScript example of opening a connection to "asdf.sqlite" in the user's profile directory:
</p>
<pre></pre>
<dl><dd><div class="note">Note: The OpenDatabase function is subject to change. It will likely be enhanced/simplified to make it more difficult to get into trouble.</div>
</dd></dl>
<h3 name="Interface_Code"> Interface Code </h3>
<pre>[scriptable, uuid(07b5b93e-113c-4150-863c-d247b003a55d)]
interface mozIStorageValueArray : nsISupports {
{
  /* Type Values */
  const long VALUE_TYPE_NULL = 0;
  const long VALUE_TYPE_INTEGER = 1;
  const long VALUE_TYPE_FLOAT = 2;
  const long VALUE_TYPE_TEXT = 3;
  const long VALUE_TYPE_BLOB = 4;

  /* Attributes */
  readonly attribute unsigned long numEntries;
  
  /* Methods */
  long getTypeOfIndex(in unsigned long aIndex);
  long getInt32(in unsigned long aIndex);
  long long getInt64(in unsigned long aIndex);
  double getDouble(in unsigned long aIndex);
  AUTF8String getUTF8String(in unsigned long aIndex);
  AString getString(in unsigned long aIndex);
  void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
  boolean getIsNull(in unsigned long aIndex);
  [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult);
  [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult);
  [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult);

%{C++
  inline PRInt32 AsInt32(PRUint32 idx) {
    PRInt32 v;
    GetInt32(idx, &amp;v);
    return v;
  }
  
  inline PRInt64 AsInt64(PRUint32 idx) {
    PRInt64 v;
    GetInt64(idx, &amp;v);
    return v;
  }
  
  inline double AsDouble(PRUint32 idx) {
    double v;
    GetDouble(idx, &amp;v);
    return v;
  }
 
  inline const char* AsSharedUTF8String(PRUint32 idx, PRUint32 *len) {
    const char *str = nsnull;
    GetSharedUTF8String(idx, len, &amp;str);
    return str;
  }
  
 inline const PRUnichar* AsSharedWString(PRUint32 idx, PRUint32 *len) {
   const PRUnichar *str = nsnull;
   GetSharedString(idx, len, &amp;str);
   return str;
 }
  
 inline const PRUint8* AsSharedBlob(PRUint32 idx, PRUint32 *len) {
   const PRUint8 *blob = nsnull;
   GetSharedBlob(idx, len, &amp;blob);
   return blob;
 }
  
 inline PRBool IsNull(PRUint32 idx) {
   PRBool b = PR_FALSE;
   GetIsNull(idx, &amp;b);
   return b;
 }
%}
};
</pre>
<h2 name="Methods"> Methods </h2>
<h3 name="openSpecialDatabase"> openSpecialDatabase </h3>
<pre>  mozIStorageConnection openSpecialDatabase(in string aStorageKey);
</pre>
<p><code>openSpecialDatabase</code> returns a new <a class="external" href="http://developer.mozilla.org/en/docs/mozIStorageConnection">mozIStorageConnection</a> for the requested storage database. It retrieves a connection to a named special database storage by the use of <code>aStorageKey</code> parameter which is a string key that identifies the type of storage requested. Valid values for <code>aStorageKey</code> parameter includes "profile" and "memory" strings as defined through the preprocessor macros <code>"MOZ_STORAGE_MEMORY_STORAGE_KEY", "MOZ_STORAGE_PROFILE_STORAGE_KEY".</code>
</p><p>If <code>aStorageKey</code> string key holds invalid value, then the <code>NS_ERROR_INVALID_ARG</code> exception is thrown.
</p>
<dl><dd><div class="note">Note: Read the summary of this Interface to understand the restrictions on how database connections may be used. For this profile database, you should only access it from the main thread since other callers may also have connections.</div>
</dd></dl>
<h3 name="openDatabase"> openDatabase </h3>
<pre>  mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
</pre>
<p><code>openDatabase</code> returns a new <a class="external" href="http://developer.mozilla.org/en/docs/mozIStorageConnection">mozIStorageConnection</a> for the requested database file. It Open a database connection to the specified file by the use of <code>aDatabaseFile</code> parameter which is a <a class="external" href="http://developer.mozilla.org/en/docs/nsIFile">nsIFile</a> of the database to open.
</p><p>If the operation fails while opening the database, then the <code>NS_ERROR_FAILURE</code> exception is thrown.
</p>
<dl><dd><div class="note">Warning: If you have more than one connection to a file, you MUST use the EXACT SAME NAME for the file each time, including case. The sqlite code uses a simple string compare to see if there is already a connection. Opening a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. Opening connections from more than one thread to the same database will also CORRUPT YOUR DATABASE. All connections share the same sqlite cache, and the cache is not threadsafe. The connection object returned by this function is not threadsafe. You must use it only from the thread you created it from.</div>
</dd></dl>
Revert to this revision