|
1 /* |
|
2 * Copyright (c) 2005-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: This is Metadata engine server file* |
|
15 */ |
|
16 |
|
17 // INCLUDE FILES |
|
18 #include <e32std.h> |
|
19 #include "mdsindexer.h" |
|
20 #include "mdsdbconnectionpool.h" |
|
21 #include "mdssqliteconnection.h" |
|
22 |
|
23 // ========================= MEMBER FUNCTIONS ================================== |
|
24 |
|
25 |
|
26 TItemId MMdSIndexer::StartIndexL() |
|
27 { |
|
28 GetLastItemIdL(); |
|
29 return iId; |
|
30 } |
|
31 |
|
32 TItemId MMdSIndexer::GetIndex( ) |
|
33 { |
|
34 return ++iId; |
|
35 } |
|
36 |
|
37 void MMdSIndexer::RevertIndex( ) |
|
38 { |
|
39 --iId; |
|
40 } |
|
41 |
|
42 void MMdSIndexer::GetLastItemIdL() |
|
43 { |
|
44 _LIT( KGetLastMaxId, "SELECT max(seq) FROM SQLITE_SEQUENCE WHERE name!='symbian_security';" ); |
|
45 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
|
46 |
|
47 RRowData getData; |
|
48 CleanupClosePushL(getData); |
|
49 |
|
50 RMdsStatement selectObject; |
|
51 CleanupClosePushL(selectObject); |
|
52 |
|
53 //Get one row and set first column to id |
|
54 connection.ExecuteQueryL( KGetLastMaxId, selectObject, getData ); |
|
55 |
|
56 getData.AppendL( TColumn( iId ) ); |
|
57 if (connection.NextRowL(selectObject, getData)) |
|
58 { |
|
59 getData.Column(0).Get( iId ); |
|
60 } |
|
61 |
|
62 CleanupStack::PopAndDestroy(2, &getData); |
|
63 } |
|
64 |
|
65 TItemId MMdSIndexer::GetIndexL() |
|
66 { |
|
67 _LIT( KIndexerQuery, "SELECT last_insert_rowid();" ); |
|
68 |
|
69 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
|
70 |
|
71 RRowData getData; |
|
72 CleanupClosePushL(getData); |
|
73 |
|
74 RMdsStatement selectObject; |
|
75 CleanupClosePushL(selectObject); |
|
76 |
|
77 TItemId id = KNoId; |
|
78 //Get one row and set first column to id |
|
79 connection.ExecuteQueryL(KIndexerQuery,selectObject,getData); |
|
80 getData.AppendL(TColumn(id)); |
|
81 if (connection.NextRowL(selectObject, getData)) |
|
82 { |
|
83 getData.Column(0).Get(id); |
|
84 } |
|
85 |
|
86 CleanupStack::PopAndDestroy(2, &getData); |
|
87 return id; |
|
88 } |
|
89 |
|
90 TItemId MMdSIndexer::ExecuteAndGetIndexL( const TDesC &aSqlClause, |
|
91 const RRowData& aRowData ) |
|
92 { |
|
93 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
|
94 |
|
95 const TInt queryResult = connection.ExecuteL( aSqlClause, aRowData ); |
|
96 |
|
97 if (queryResult == 0) |
|
98 { |
|
99 return KNoId; |
|
100 } |
|
101 |
|
102 return MMdSIndexer::GetIndexL(); |
|
103 } |
|
104 |
|
105 |
|
106 RSQLIndex::RSQLIndex() |
|
107 : iId(MMdSIndexer::GetIndex()), iCommit(EFalse) |
|
108 { |
|
109 } |
|
110 |
|
111 const TItemId& RSQLIndex::GetId() const |
|
112 { |
|
113 return iId; |
|
114 } |
|
115 |
|
116 void RSQLIndex::Commit() |
|
117 { |
|
118 iCommit = ETrue; |
|
119 } |
|
120 |
|
121 void RSQLIndex::Close() |
|
122 { |
|
123 if (!iCommit) |
|
124 { |
|
125 MMdSIndexer::RevertIndex(); |
|
126 } |
|
127 } |
|
128 |
|
129 |
|
130 // --------------------------------------------------------------- |
|
131 // -----------------INITIALIZE STATIC DATA------------------------ |
|
132 // --------------------------------------------------------------- |
|
133 |
|
134 TItemId MMdSIndexer::iId = KNoId; |