LCOV - code coverage report
Current view: directory - storage/src - mozStorageArgValueArray.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 78 36 46.2 %
Date: 2012-06-02 Functions: 16 10 62.5 %

       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                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Oracle Corporation code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  *  Oracle Corporation
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2004
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "nsError.h"
      41                 : #include "nsMemory.h"
      42                 : #include "nsString.h"
      43                 : 
      44                 : #include "mozStoragePrivateHelpers.h"
      45                 : #include "mozStorageArgValueArray.h"
      46                 : 
      47                 : namespace mozilla {
      48                 : namespace storage {
      49                 : 
      50                 : ////////////////////////////////////////////////////////////////////////////////
      51                 : //// ArgValueArray
      52                 : 
      53           45327 : ArgValueArray::ArgValueArray(PRInt32 aArgc,
      54                 :                              sqlite3_value **aArgv)
      55                 : : mArgc(aArgc)
      56           45327 : , mArgv(aArgv)
      57                 : {
      58           45327 : }
      59                 : 
      60          136281 : NS_IMPL_ISUPPORTS1(
      61                 :   ArgValueArray,
      62                 :   mozIStorageValueArray
      63                 : )
      64                 : 
      65                 : ////////////////////////////////////////////////////////////////////////////////
      66                 : //// mozIStorageValueArray
      67                 : 
      68                 : NS_IMETHODIMP
      69            4922 : ArgValueArray::GetNumEntries(PRUint32 *_size)
      70                 : {
      71            4922 :   *_size = mArgc;
      72            4922 :   return NS_OK;
      73                 : }
      74                 : 
      75                 : NS_IMETHODIMP
      76               0 : ArgValueArray::GetTypeOfIndex(PRUint32 aIndex,
      77                 :                               PRInt32 *_type)
      78                 : {
      79               0 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
      80                 : 
      81               0 :   int t = ::sqlite3_value_type(mArgv[aIndex]);
      82               0 :   switch (t) {
      83                 :     case SQLITE_INTEGER:
      84               0 :       *_type = VALUE_TYPE_INTEGER;
      85               0 :       break;
      86                 :     case SQLITE_FLOAT:
      87               0 :       *_type = VALUE_TYPE_FLOAT;
      88               0 :       break;
      89                 :     case SQLITE_TEXT:
      90               0 :       *_type = VALUE_TYPE_TEXT;
      91               0 :       break;
      92                 :     case SQLITE_BLOB:
      93               0 :       *_type = VALUE_TYPE_BLOB;
      94               0 :       break;
      95                 :     case SQLITE_NULL:
      96               0 :       *_type = VALUE_TYPE_NULL;
      97               0 :       break;
      98                 :     default:
      99               0 :       return NS_ERROR_FAILURE;
     100                 :   }
     101                 : 
     102               0 :   return NS_OK;
     103                 : }
     104                 : 
     105                 : NS_IMETHODIMP
     106           12333 : ArgValueArray::GetInt32(PRUint32 aIndex,
     107                 :                         PRInt32 *_value)
     108                 : {
     109           12333 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     110                 : 
     111           12333 :   *_value = ::sqlite3_value_int(mArgv[aIndex]);
     112           12333 :   return NS_OK;
     113                 : }
     114                 : 
     115                 : NS_IMETHODIMP
     116            4921 : ArgValueArray::GetInt64(PRUint32 aIndex,
     117                 :                         PRInt64 *_value)
     118                 : {
     119            4921 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     120                 : 
     121            4921 :   *_value = ::sqlite3_value_int64(mArgv[aIndex]);
     122            4921 :   return NS_OK;
     123                 : }
     124                 : 
     125                 : NS_IMETHODIMP
     126               0 : ArgValueArray::GetDouble(PRUint32 aIndex,
     127                 :                          double *_value)
     128                 : {
     129               0 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     130                 : 
     131               0 :   *_value = ::sqlite3_value_double(mArgv[aIndex]);
     132               0 :   return NS_OK;
     133                 : }
     134                 : 
     135                 : NS_IMETHODIMP
     136            8118 : ArgValueArray::GetUTF8String(PRUint32 aIndex,
     137                 :                              nsACString &_value)
     138                 : {
     139            8118 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     140                 : 
     141            8118 :   if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
     142                 :     // NULL columns should have IsVoid set to distinguish them from an empty
     143                 :     // string.
     144            1529 :     _value.Truncate(0);
     145            1529 :     _value.SetIsVoid(true);
     146                 :   }
     147                 :   else {
     148            6589 :     _value.Assign(reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex])),
     149           13178 :                   ::sqlite3_value_bytes(mArgv[aIndex]));
     150                 :   }
     151            8118 :   return NS_OK;
     152                 : }
     153                 : 
     154                 : NS_IMETHODIMP
     155           33201 : ArgValueArray::GetString(PRUint32 aIndex,
     156                 :                          nsAString &_value)
     157                 : {
     158           33201 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     159                 : 
     160           33201 :   if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
     161                 :     // NULL columns should have IsVoid set to distinguish them from an empty
     162                 :     // string.
     163              57 :     _value.Truncate(0);
     164              57 :     _value.SetIsVoid(true);
     165                 :   } else {
     166           33144 :     _value.Assign(static_cast<const PRUnichar *>(::sqlite3_value_text16(mArgv[aIndex])),
     167           66288 :                   ::sqlite3_value_bytes16(mArgv[aIndex]) / 2);
     168                 :   }
     169           33201 :   return NS_OK;
     170                 : }
     171                 : 
     172                 : NS_IMETHODIMP
     173               0 : ArgValueArray::GetBlob(PRUint32 aIndex,
     174                 :                        PRUint32 *_size,
     175                 :                        PRUint8 **_blob)
     176                 : {
     177               0 :   ENSURE_INDEX_VALUE(aIndex, mArgc);
     178                 : 
     179               0 :   int size = ::sqlite3_value_bytes(mArgv[aIndex]);
     180               0 :   void *blob = nsMemory::Clone(::sqlite3_value_blob(mArgv[aIndex]), size);
     181               0 :   NS_ENSURE_TRUE(blob, NS_ERROR_OUT_OF_MEMORY);
     182                 : 
     183               0 :   *_blob = static_cast<PRUint8 *>(blob);
     184               0 :   *_size = size;
     185               0 :   return NS_OK;
     186                 : }
     187                 : 
     188                 : NS_IMETHODIMP
     189               0 : ArgValueArray::GetIsNull(PRUint32 aIndex,
     190                 :                          bool *_isNull)
     191                 : {
     192                 :   // GetTypeOfIndex will check aIndex for us, so we don't have to.
     193                 :   PRInt32 type;
     194               0 :   nsresult rv = GetTypeOfIndex(aIndex, &type);
     195               0 :   NS_ENSURE_SUCCESS(rv, rv);
     196                 : 
     197               0 :   *_isNull = (type == VALUE_TYPE_NULL);
     198               0 :   return NS_OK;
     199                 : }
     200                 : 
     201                 : NS_IMETHODIMP
     202               1 : ArgValueArray::GetSharedUTF8String(PRUint32 aIndex,
     203                 :                                    PRUint32 *_length,
     204                 :                                    const char **_string)
     205                 : {
     206               1 :   if (_length)
     207               1 :     *_length = ::sqlite3_value_bytes(mArgv[aIndex]);
     208                 : 
     209               1 :   *_string = reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex]));
     210               1 :   return NS_OK;
     211                 : }
     212                 : 
     213                 : NS_IMETHODIMP
     214               0 : ArgValueArray::GetSharedString(PRUint32 aIndex,
     215                 :                                PRUint32 *_length,
     216                 :                                const PRUnichar **_string)
     217                 : {
     218               0 :   if (_length)
     219               0 :     *_length = ::sqlite3_value_bytes(mArgv[aIndex]);
     220                 : 
     221               0 :   *_string = static_cast<const PRUnichar *>(::sqlite3_value_text16(mArgv[aIndex]));
     222               0 :   return NS_OK;
     223                 : }
     224                 : 
     225                 : NS_IMETHODIMP
     226               0 : ArgValueArray::GetSharedBlob(PRUint32 aIndex,
     227                 :                              PRUint32 *_size,
     228                 :                              const PRUint8 **_blob)
     229                 : {
     230               0 :   *_size = ::sqlite3_value_bytes(mArgv[aIndex]);
     231               0 :   *_blob = static_cast<const PRUint8 *>(::sqlite3_value_blob(mArgv[aIndex]));
     232               0 :   return NS_OK;
     233                 : }
     234                 : 
     235                 : } // namespace storage
     236                 : } // namespace mozilla

Generated by: LCOV version 1.7