summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cntsqldbstructure.h
blob: 6bce88cf2a933823cae6ab34d8c765b734aca0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: An  object representing a sql database table information. 
* All the tables and their column information is stored in the source code. 
* While checking compatibility, this information is compared with the tables and columns in the database.
* This class is used for checking if the database contains all the columns. If not, then
* it may be needed to add those columns (To maintain compatibility across releases)
* 
*/



/**
@internalComponent
@released
*/

#ifndef __CNTSQLDBSTRUCTURE_H__
#define __CNTSQLDBSTRUCTURE_H__

#include <e32base.h>
#include <sqldb.h>

class CPplContactItemManager;

/*
* Class provide information about columns in a table
*/
class CCntSqlDbTableColumn:public CBase
    {
    public:
    
    /*
    * Creates a new CCntSqlDbTableColumn obj
    * @param aColumnName - Mandatory
    * @param aColType - Mandatory
    * @param aNotNullValue 
    * @param aAdditionalInfo
    * @return - obj of CCntSqlDbTableColumn
    */
    static CCntSqlDbTableColumn* NewLC(
            const TDesC& aColumnName,
            const TDesC& aColType,
            TBool aNotNullValue = EFalse,
            const TDesC& aAdditionalInfo = KNullDesC() );
    
    /*
    * Returns the column Name
    */
    const TDesC& ColumnName() const;
    
    /*
    * Returns the column type i.e INTEGER, VARCHAR etc
    */
    const TDesC& ColumnType() const;
    
    /*
    * Returns true if NOTNULL constrain set
    */
    TBool NotNullValue() const ;
    
    /*
    * Any addition information such as default value etc
    */
    const TDesC& AdditionalInfo() const;
    
    /*
    * Returns NOTNULL string if NOTNULL constrain set
    * else returns KNullDesC()
    */
    const TDesC& NotNullString() const;
    
    /*
    * Destructor
    */
    ~CCntSqlDbTableColumn();
    
private:
    
    CCntSqlDbTableColumn(TBool aNotNullValue);
    void ConstructL(const TDesC& aColumnName, const TDesC& aColType,const TDesC& aAdditionalInfo);
    
private:
    
    HBufC* iColumnName; //own, column name
    HBufC* iColumnType; //own, column type
    TBool iNotNullValue; //own , notnull value
    HBufC* iAdditionalInfo; //own, additional information
    HBufC* iNotNullStr; //Own, Not NULL String
    };


/*
* Class provide information about the table
*/
NONSHARABLE_CLASS(CCntSqlDbTable) : public CBase
    {
public:
     static CCntSqlDbTable* NewLC (const TDesC& aTableName,  RSqlDatabase& aDbInstance, CPplContactItemManager& aItemManager);
public:
    /*
    * Returns the table name
    */
    const TDesC& TableName() const;
    /*
    * Checks the database table and verifies if all columns are present. If not, 
    * then the missing columns are added in the database table
    */
    void MakeTableStructureCompatibleL();
    /*
    * Add a column to this table
    * @param aColumnName - Mandatory
    * @param aColType - Mandatory
    * @param aNotNullValue 
    * @param aAdditionalInfo    
     */
    void AddColumnToColumnInfoL( const TDesC& aColumnName,
            const TDesC& aColType,
            TBool aNotNullValue = EFalse,
            const TDesC& aAdditionalInfo = KNullDesC() );

    /*
    * destructor
    */
    ~CCntSqlDbTable();
    
protected:
    void ConstructL(const TDesC& aTableName);

private:
    CCntSqlDbTable(RSqlDatabase& aDbInstance, CPplContactItemManager& aItemManager);
    void GetMissingColumns(RPointerArray<CCntSqlDbTableColumn>& aColumnsToAdd);
    void GetExistingColumnsFromDatabaseL(RPointerArray<CCntSqlDbTableColumn>& aExistingColumnsFromOldDb);
    void AlterTableToAddColumnL( CCntSqlDbTableColumn* aColInfo);
    void FillFavoritesColumnL();

protected:
    HBufC* iTableName; // holds the table name, own
    RPointerArray<CCntSqlDbTableColumn> iColumnInfo;  // own,List of columns this table should have
    RSqlDatabase& iDatabase; // not own
    CPplContactItemManager& iItemManager; //not own
    };

/*
 * This class holds the actual table structure that should be. If the databsse does not have 
 * this structure then it needs to be modified to make it compatible 
 */
NONSHARABLE_CLASS(CCntSqlDbStructure) : public CBase
    {
public:
    static CCntSqlDbStructure* NewL( RSqlDatabase& aDbInstance, CPplContactItemManager& aItemManager);
    ~CCntSqlDbStructure();    
    /*
    *  Checks the database and verifies if all tables and columns are present. If not,
    *  then the missing columns are added in the database 
    */
    void MakeDatabaseCompatibleL();
    
    /*
    * Returns the List of Tables present in this DB 
    */
    const RPointerArray<CCntSqlDbTable>& Tables();

private:
    CCntSqlDbStructure( RSqlDatabase& aDbInstance, CPplContactItemManager& aItemManager);
    void InitializeL();
    void InitializeContactsTableInfoL();
    void InitializeGroupsTableInfoL();
    void InitializeCommAddrTableInfoL();
    
private:
    RPointerArray<CCntSqlDbTable> iTables;  //own, list of tables
    RSqlDatabase& iDatabase; // not own, handle to the database
    CPplContactItemManager& iItemManager; //not own
    };
#endif //__CNTSQLDBSTRUCTURE_H__