inc/mdssqlrow.h
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Abstract SQL connection class*
       
    15 */
       
    16 
       
    17 #ifndef __MDSSQLCONNECTION_H__
       
    18 #define __MDSSQLCONNECTION_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 #include "mdccommon.pan"
       
    22 
       
    23 #include "mdscommoninternal.h"
       
    24 
       
    25 
       
    26 // types of columns
       
    27 enum TColumnDataType
       
    28     {
       
    29     EColumnNotUsed,
       
    30     EColumnBool,
       
    31     EColumnInt32,
       
    32     EColumnUint32,
       
    33     EColumnInt64,
       
    34     EColumnReal32,
       
    35     EColumnReal64,
       
    36     EColumnTime,
       
    37     EColumnDes8,
       
    38     EColumnDes16,  // could be used as Unknown, because it checks the
       
    39                    // actual type from sqlite
       
    40     EColumnHBuf8,  // local pointer responsibility
       
    41     EColumnHBuf16, // local pointer responsibility
       
    42     EColumnNullDes8,
       
    43     EColumnNullDes16, // used when db column is null 
       
    44     //EColumnUnknown
       
    45     
       
    46     EColumnTItemId = EColumnUint32, // should be changed according to TItemId definition
       
    47     EColumnTDefId = EColumnUint32, // should be changed according to TDefId definition
       
    48     };
       
    49 
       
    50 /**
       
    51 * A class representing a database column.
       
    52 * The column contains a type and an untyped pointer, which can
       
    53 * be cast to represent various types.
       
    54 */
       
    55 NONSHARABLE_CLASS(TColumn)
       
    56     {
       
    57     public:
       
    58         /** Returns column type. */
       
    59         inline TColumnDataType Type() const;
       
    60 
       
    61         /** Constructs a column with data type only. Use for queries. */
       
    62         inline TColumn( TColumnDataType aType = EColumnNotUsed );
       
    63 
       
    64         /** frees allocated memory in this column */
       
    65         inline void Free();
       
    66 
       
    67         // constructors
       
    68 
       
    69         TColumn( TInt32 aVal ) { Set( aVal ); }
       
    70         TColumn( TUint32 aVal ) { Set( aVal ); }
       
    71         TColumn( TBool aVal ) { Set( aVal ); }
       
    72         TColumn( TInt64 aVal ) { Set( aVal ); }
       
    73         TColumn( TReal32 aVal ) { Set( aVal ); }
       
    74         TColumn( TReal64 aVal ) { Set( aVal ); }
       
    75         TColumn( TTime aVal ) { Set( aVal ); }
       
    76         TColumn( const TDesC8& aVal ) { Set( aVal ); }
       
    77         TColumn( const TDesC16& aVal ) { Set( aVal ); }
       
    78         TColumn( const HBufC8* aVal ) { Set( aVal ); }
       
    79         TColumn( const HBufC16* aVal ) { Set( aVal ); }
       
    80 
       
    81         // data setters & getters
       
    82         
       
    83         inline void Set( TInt32 aVal );
       
    84 
       
    85         inline void Set( TUint32 aVal );
       
    86 
       
    87         inline void Set( TBool aVal );
       
    88 
       
    89         inline void Set( TInt64 aVal );
       
    90 
       
    91         inline void Set( TReal32 aVal );
       
    92 
       
    93         inline void Set( TReal64 aVal );
       
    94 
       
    95         inline void Set( TTime aVal );
       
    96 
       
    97         inline void Set( const TDesC8& aVal );
       
    98 
       
    99         inline void Set( const TDesC16& aVal );
       
   100 
       
   101         inline void Set( const HBufC8* aVal );
       
   102 
       
   103         inline void Set( const HBufC16* aVal );
       
   104 
       
   105         inline void NotUsed();
       
   106 
       
   107         // data getters
       
   108 
       
   109         inline void Get( TInt32& aValue ) const;
       
   110 
       
   111         inline void Get( TUint32& aValue ) const;
       
   112 
       
   113         inline void Get( TBool& aValue ) const;
       
   114 
       
   115         inline void Get( TInt64& aValue ) const;
       
   116 
       
   117         inline void Get( TReal32& aValue ) const;
       
   118 
       
   119         inline void Get( TReal64& aValue ) const;
       
   120 
       
   121         inline void Get( TTime& aValue ) const;
       
   122 
       
   123         inline void Get( TPtrC8& aValue ) const;
       
   124 
       
   125         inline void Get( TPtrC16& aValue ) const;
       
   126 
       
   127         inline TBool IsNull();
       
   128 
       
   129         /**
       
   130         * type of data in this column
       
   131         */
       
   132         TColumnDataType iType;
       
   133 
       
   134         /**
       
   135         * a structure to store multi-typed data
       
   136         */
       
   137         union TMultiTypeData
       
   138             {
       
   139             /*struct
       
   140                 {
       
   141                 TUint32 iLow;
       
   142                 TUint32 iHigh;
       
   143                 } iInt64;*/
       
   144             TInt64 iInt64;
       
   145             
       
   146             TReal32 iReal32;
       
   147             TReal64 iReal64;
       
   148             TInt32 iInt32;
       
   149             TUint32 iUint32;
       
   150             struct
       
   151                 {
       
   152                 TAny* iPtr;
       
   153                 TInt iLen;
       
   154                 } iText;
       
   155             };
       
   156 
       
   157         /**
       
   158         * multi-use data in this column
       
   159         */
       
   160         TMultiTypeData iData;
       
   161     };
       
   162 
       
   163 /**
       
   164 * A class representing a database row.
       
   165 * The class describes each column type and the data in the column.
       
   166 * where column data is located. The class is provided during
       
   167 * query and is used when each row is read. Note that the
       
   168 * buffer class MAY be modified by the user during the query.
       
   169 * The same class is also used when replacing wildcards with
       
   170 * variable data.
       
   171 */
       
   172 class RRowData
       
   173     {
       
   174     public:
       
   175 
       
   176         /**
       
   177         * constructor
       
   178         */
       
   179         inline RRowData();
       
   180 
       
   181         /** Closes all the resources used by this object */
       
   182         inline void Close();
       
   183 
       
   184         /** frees allocated memory in this row */
       
   185         inline void Free();
       
   186 
       
   187         /** number of columns or variables */
       
   188         inline TInt Size() const;
       
   189 
       
   190         /** returns column by index */
       
   191         inline TColumn& Column( TInt aIndex );
       
   192 
       
   193         /** returns column by index */
       
   194         inline const TColumn& Column( TInt aIndex ) const;
       
   195 
       
   196         /** Appends a new column in row */
       
   197         inline TColumn& AppendL( const TColumn& aColumn );
       
   198 
       
   199         /** Resets the row */
       
   200         inline void Reset();
       
   201 
       
   202 		/** Copy all columns */
       
   203 		void AppendColumnTypesL( RRowData& aColumnTypeRow );
       
   204 
       
   205 		/** Receive space to row */
       
   206 		void ReserveL( TInt aColumnCount );
       
   207 		
       
   208     protected:
       
   209 
       
   210         /** The array of columns */
       
   211         RArray<TColumn> iColumns;
       
   212     };
       
   213 
       
   214 
       
   215 #include "mdssqlrow.inl" // inline methods
       
   216 
       
   217 #endif	// __MDSSQLCONNECTION_H__
       
   218 
       
   219 
       
   220 // End of File