sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "UT_STD.H"
|
sl@0
|
17 |
|
sl@0
|
18 |
// Class CDbTableDatabase::CInterface
|
sl@0
|
19 |
|
sl@0
|
20 |
//
|
sl@0
|
21 |
// ctor. Add the initial reference to the database engine
|
sl@0
|
22 |
//
|
sl@0
|
23 |
CDbTableDatabase::CInterface::CInterface(CDbTableDatabase& aDatabase)
|
sl@0
|
24 |
:iDatabase(aDatabase)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
aDatabase.Open();
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
//
|
sl@0
|
30 |
// dtor. remove our reference from the database engine
|
sl@0
|
31 |
//
|
sl@0
|
32 |
CDbTableDatabase::CInterface::~CInterface()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
if (Database().Transaction().InTransaction(*this))
|
sl@0
|
35 |
Rollback(); // release the lock if we have it
|
sl@0
|
36 |
Database().Close();
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
void CDbTableDatabase::CInterface::PrepareDDLL()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
Database().Transaction().DDLPrepareL(*this);
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
//
|
sl@0
|
45 |
// destroy the database (database must be empty)
|
sl@0
|
46 |
//
|
sl@0
|
47 |
TInt CDbTableDatabase::CInterface::Destroy()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
__ASSERT(Database().Schema().IsEmpty());
|
sl@0
|
50 |
TRAPD(r,Database().DestroyL());
|
sl@0
|
51 |
return r;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
//
|
sl@0
|
55 |
// Initiate a transaction on the database
|
sl@0
|
56 |
//
|
sl@0
|
57 |
TInt CDbTableDatabase::CInterface::Begin()
|
sl@0
|
58 |
{
|
sl@0
|
59 |
TRAPD(r,Database().Transaction().BeginL(*this));
|
sl@0
|
60 |
return r;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
//
|
sl@0
|
64 |
// Commit a transaction on the database
|
sl@0
|
65 |
//
|
sl@0
|
66 |
TInt CDbTableDatabase::CInterface::Commit()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
TRAPD(r,Database().Transaction().CommitL(*this));
|
sl@0
|
69 |
return r;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
//
|
sl@0
|
73 |
// Rollback a failed transaction on the database
|
sl@0
|
74 |
//
|
sl@0
|
75 |
void CDbTableDatabase::CInterface::Rollback()
|
sl@0
|
76 |
{
|
sl@0
|
77 |
Database().Transaction().Rollback(*this);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
//
|
sl@0
|
81 |
// Report a requested property
|
sl@0
|
82 |
//
|
sl@0
|
83 |
TInt CDbTableDatabase::CInterface::Property(CDbDatabase::TProperty aProperty)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
if (aProperty==EInTransaction)
|
sl@0
|
86 |
return Database().Transaction().InTransaction(*this) ? 1 : 0;
|
sl@0
|
87 |
//
|
sl@0
|
88 |
return Database().Property(aProperty);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
void CDbTableDatabase::CInterface::CreateTableL(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
PrepareDDLL();
|
sl@0
|
94 |
Database().DoCreateTableL(aName,aColSet,aPrimaryKey);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
CDbCursor* CDbTableDatabase::CInterface::PrepareViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess anAccess)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
return Database().PrepareViewL(aQuery,aWindow,anAccess);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
CDbCursor* CDbTableDatabase::CInterface::OpenTableL(const TDesC& aName,RDbRowSet::TAccess anAccess)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
return Database().PrepareTableL(aName,anAccess);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
CDbIncremental* CDbTableDatabase::CInterface::OpenDropTableL(const TDesC& aTable,TInt& aStep)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
PrepareDDLL();
|
sl@0
|
110 |
return Database().OpenDropTableL(aTable,aStep);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
CDbIncremental* CDbTableDatabase::CInterface::OpenAlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
PrepareDDLL();
|
sl@0
|
116 |
return Database().OpenAlterTableL(aTable,aNewDef,aStep);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
CDbIncremental* CDbTableDatabase::CInterface::OpenCreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
PrepareDDLL();
|
sl@0
|
122 |
return Database().OpenCreateIndexL(aName,aTable,aKey,aStep);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
CDbIncremental* CDbTableDatabase::CInterface::OpenDropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
PrepareDDLL();
|
sl@0
|
128 |
return Database().OpenDropIndexL(aName,aTable,aStep);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
//
|
sl@0
|
132 |
// Create a database utility. Check the corresponding property to see if it is viable
|
sl@0
|
133 |
//
|
sl@0
|
134 |
CDbIncremental* CDbTableDatabase::CInterface::OpenUtilityL(CDbDatabase::TUtility aType,TInt& aStep)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
if (!Property(TProperty(-aType)))
|
sl@0
|
137 |
{ // nothing to do, or not capable
|
sl@0
|
138 |
aStep=0;
|
sl@0
|
139 |
return 0;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
RDbTransaction& t=Database().Transaction();
|
sl@0
|
142 |
t.UtilityPrepareL(*this);
|
sl@0
|
143 |
if (aType==ERecover)
|
sl@0
|
144 |
Database().Release(); // must not have any tables open during recovery
|
sl@0
|
145 |
return CUtility::NewL(t,aType,aStep);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
CDbIncremental* CDbTableDatabase::CInterface::OpenExecuteL(const TDesC& aSql,TDbTextComparison aComparison,TInt& aInit)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
switch (Sql::Type(aSql))
|
sl@0
|
151 |
{
|
sl@0
|
152 |
default:
|
sl@0
|
153 |
__ASSERT(0);
|
sl@0
|
154 |
case Sql::ENone:
|
sl@0
|
155 |
__LEAVE(KErrArgument);
|
sl@0
|
156 |
case Sql::EDDL:
|
sl@0
|
157 |
{
|
sl@0
|
158 |
CDbIncremental* inc=Sql::ParseDDLStatementLC(aSql)->ExecuteL(*this,aComparison,aInit);
|
sl@0
|
159 |
CleanupStack::PopAndDestroy(); // statement
|
sl@0
|
160 |
return inc;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
case Sql::EDML:
|
sl@0
|
163 |
{
|
sl@0
|
164 |
CSqlDMLStatement* statement=Sql::ParseDMLStatementLC(aSql);
|
sl@0
|
165 |
RDbTransaction& t=Database().Transaction();
|
sl@0
|
166 |
t.DMLCheckL(); // ensure we can open a cursor
|
sl@0
|
167 |
t.DMLPrepareL(*this);
|
sl@0
|
168 |
CDbIncremental* inc=statement->ExecuteL(Database(),aComparison,aInit);
|
sl@0
|
169 |
CleanupStack::PopAndDestroy(); // statement
|
sl@0
|
170 |
return inc;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
}
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
//
|
sl@0
|
176 |
// Open a client-side notifier object
|
sl@0
|
177 |
//
|
sl@0
|
178 |
CDbNotifier* CDbTableDatabase::CInterface::OpenNotifierL()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
return Database().Transaction().NotifierL();
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
//
|
sl@0
|
184 |
// list the tables on the database
|
sl@0
|
185 |
//
|
sl@0
|
186 |
void CDbTableDatabase::CInterface::TablesL(CDbTableNames& aNames)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
TSglQueIterC<CDbTableDef> iter(Database().SchemaL());
|
sl@0
|
189 |
for (const CDbTableDef* def;(def=iter++)!=0;)
|
sl@0
|
190 |
aNames.AddL(def->Name());
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
//
|
sl@0
|
194 |
// build a column set for the table
|
sl@0
|
195 |
//
|
sl@0
|
196 |
void CDbTableDatabase::CInterface::ColumnsL(CDbColSet& aColSet,const TDesC& aName)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TDbCol col;
|
sl@0
|
199 |
const HDbColumnSet& set=Database().SchemaL().FindL(aName).Columns();
|
sl@0
|
200 |
HDbColumnSet::TIteratorC iter=set.Begin();
|
sl@0
|
201 |
const HDbColumnSet::TIteratorC end=set.End();
|
sl@0
|
202 |
do
|
sl@0
|
203 |
{
|
sl@0
|
204 |
iter->AsTDbCol(col);
|
sl@0
|
205 |
aColSet.AddL(col);
|
sl@0
|
206 |
} while (++iter<end);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
//
|
sl@0
|
210 |
// List the indexes on a table
|
sl@0
|
211 |
//
|
sl@0
|
212 |
void CDbTableDatabase::CInterface::IndexesL(CDbIndexNames& aNames,const TDesC& aTable)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
TSglQueIterC<CDbTableIndexDef> iter(Database().SchemaL().FindL(aTable).Indexes().AsQue());
|
sl@0
|
215 |
for (const CDbTableIndexDef* def;(def=iter++)!=0;)
|
sl@0
|
216 |
aNames.AddL(def->Name());
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
//
|
sl@0
|
220 |
// build a key for the index
|
sl@0
|
221 |
//
|
sl@0
|
222 |
void CDbTableDatabase::CInterface::KeysL(CDbKey& aKey,const TDesC& aName,const TDesC& aTable)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
const CDbKey& key=Database().SchemaL().FindL(aTable).Indexes().FindL(aName).Key();
|
sl@0
|
225 |
TInt max=key.Count();
|
sl@0
|
226 |
for (TInt ii=0;ii<max;++ii)
|
sl@0
|
227 |
aKey.AddL(key[ii]);
|
sl@0
|
228 |
if (key.IsUnique())
|
sl@0
|
229 |
aKey.MakeUnique();
|
sl@0
|
230 |
if (key.IsPrimary())
|
sl@0
|
231 |
aKey.MakePrimary();
|
sl@0
|
232 |
aKey.SetComparison(key.Comparison());
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
// Class CDbTableDatabase::CSource
|
sl@0
|
236 |
|
sl@0
|
237 |
//
|
sl@0
|
238 |
// ctor. Add a reference to the database engine
|
sl@0
|
239 |
//
|
sl@0
|
240 |
CDbTableDatabase::CSource::CSource(CDbTableDatabase& aDatabase)
|
sl@0
|
241 |
:iDatabase(aDatabase)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
aDatabase.Open();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
//
|
sl@0
|
247 |
// dtor. remove our reference from the database engine
|
sl@0
|
248 |
//
|
sl@0
|
249 |
CDbTableDatabase::CSource::~CSource()
|
sl@0
|
250 |
{
|
sl@0
|
251 |
Database().Close();
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
|
sl@0
|
255 |
//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method
|
sl@0
|
256 |
CDbDatabase* CDbTableDatabase::CSource::AuthenticateL()
|
sl@0
|
257 |
{
|
sl@0
|
258 |
Database().AuthenticateL();
|
sl@0
|
259 |
return Database().InterfaceL();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
|
sl@0
|
263 |
CDbNotifier* CDbTableDatabase::CSource::OpenNotifierL()
|
sl@0
|
264 |
{
|
sl@0
|
265 |
return Database().Transaction().NotifierL();
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
// Class CDbTableDatabase
|
sl@0
|
269 |
|
sl@0
|
270 |
EXPORT_C CDbTableDatabase::CDbTableDatabase()
|
sl@0
|
271 |
{
|
sl@0
|
272 |
iCache.Open();
|
sl@0
|
273 |
iTransaction.Open(*this);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
EXPORT_C CDbTableDatabase::~CDbTableDatabase()
|
sl@0
|
277 |
{
|
sl@0
|
278 |
__ASSERT(iRef==0);
|
sl@0
|
279 |
iTransaction.Close();
|
sl@0
|
280 |
iTables.Close();
|
sl@0
|
281 |
iSchema.Close();
|
sl@0
|
282 |
iCache.Close();
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
void CDbTableDatabase::Close()
|
sl@0
|
286 |
{
|
sl@0
|
287 |
__ASSERT(iRef>0);
|
sl@0
|
288 |
if (--iRef==0)
|
sl@0
|
289 |
delete this;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
//
|
sl@0
|
293 |
// Construct the implementation interface for the database framework
|
sl@0
|
294 |
// On success, the interface takes an owning reference to this
|
sl@0
|
295 |
//
|
sl@0
|
296 |
EXPORT_C CDbDatabase* CDbTableDatabase::InterfaceL()
|
sl@0
|
297 |
{
|
sl@0
|
298 |
return new(ELeave) CInterface(*this);
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
//
|
sl@0
|
302 |
// Construct the implementation interface for the database framework
|
sl@0
|
303 |
// On success, the interface takes an owning reference to this
|
sl@0
|
304 |
//
|
sl@0
|
305 |
EXPORT_C CDbSource* CDbTableDatabase::SourceL()
|
sl@0
|
306 |
{
|
sl@0
|
307 |
return new(ELeave) CSource(*this);
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
//
|
sl@0
|
311 |
// Load the schema if required
|
sl@0
|
312 |
//
|
sl@0
|
313 |
EXPORT_C RDbTableSchema& CDbTableDatabase::SchemaL()
|
sl@0
|
314 |
{
|
sl@0
|
315 |
RDbTableSchema& schema=Schema();
|
sl@0
|
316 |
if (!schema.IsLoaded())
|
sl@0
|
317 |
{
|
sl@0
|
318 |
schema.Discard();
|
sl@0
|
319 |
LoadSchemaL();
|
sl@0
|
320 |
schema.Loaded();
|
sl@0
|
321 |
}
|
sl@0
|
322 |
return schema;
|
sl@0
|
323 |
}
|
sl@0
|
324 |
|
sl@0
|
325 |
//
|
sl@0
|
326 |
// Find any tables which are now idle, and cache them
|
sl@0
|
327 |
// Caching such a table can result in *any* table being deleted
|
sl@0
|
328 |
// and so the iteration must restart every time an idle table is cached
|
sl@0
|
329 |
//
|
sl@0
|
330 |
void CDbTableDatabase::CheckIdle()
|
sl@0
|
331 |
{
|
sl@0
|
332 |
while (!iTables.IsEmpty())
|
sl@0
|
333 |
{
|
sl@0
|
334 |
for (TSglQueIter<CDbTable> iter(iTables);;)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
CDbTable* table=iter++;
|
sl@0
|
337 |
if (table==0) // no more idle tables
|
sl@0
|
338 |
return;
|
sl@0
|
339 |
if (table->IsIdle())
|
sl@0
|
340 |
{ // idle->cache transition can modify the collection
|
sl@0
|
341 |
table->Idle();
|
sl@0
|
342 |
break;
|
sl@0
|
343 |
}
|
sl@0
|
344 |
}
|
sl@0
|
345 |
}
|
sl@0
|
346 |
// If there are no tables left open, then the database can go idle
|
sl@0
|
347 |
Idle();
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
//
|
sl@0
|
351 |
// Does nothing by default
|
sl@0
|
352 |
//
|
sl@0
|
353 |
EXPORT_C void CDbTableDatabase::Idle()
|
sl@0
|
354 |
{
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
//
|
sl@0
|
358 |
// default implementation
|
sl@0
|
359 |
//
|
sl@0
|
360 |
EXPORT_C TInt CDbTableDatabase::Property(CDbDatabase::TProperty aProperty)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
if (aProperty<0)
|
sl@0
|
363 |
return 0; // utilities are not available with table database
|
sl@0
|
364 |
__ASSERT(aProperty!=CDbDatabase::EInTransaction);
|
sl@0
|
365 |
return KErrNotSupported;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
//
|
sl@0
|
369 |
// default implementation, should never be invoked
|
sl@0
|
370 |
//
|
sl@0
|
371 |
EXPORT_C CDbTableDatabase::CStepper* CDbTableDatabase::UtilityL(CDbDatabase::TUtility,TInt&)
|
sl@0
|
372 |
{
|
sl@0
|
373 |
__ASSERT(0);
|
sl@0
|
374 |
return 0;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
void CDbTableDatabase::FlushL(TDbLockType aLock)
|
sl@0
|
378 |
{
|
sl@0
|
379 |
if (aLock>=EDbWriteLock)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TSglQueIter<CDbTable> iter(iTables);
|
sl@0
|
382 |
for (CDbTable* table;(table=iter++)!=0;)
|
sl@0
|
383 |
table->FlushL();
|
sl@0
|
384 |
}
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
void CDbTableDatabase::Abandon(TDbLockType aLock)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
if (aLock>=EDbWriteLock)
|
sl@0
|
390 |
{
|
sl@0
|
391 |
TSglQueIter<CDbTable> iter(iTables);
|
sl@0
|
392 |
for (CDbTable* table;(table=iter++)!=0;)
|
sl@0
|
393 |
table->Abandon();
|
sl@0
|
394 |
}
|
sl@0
|
395 |
if (aLock==EDbSchemaLock)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
Release(); // ensure no-one is using the old schema
|
sl@0
|
398 |
Schema().Discard();
|
sl@0
|
399 |
}
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
//
|
sl@0
|
403 |
// Discard a table if it is using this definition
|
sl@0
|
404 |
//
|
sl@0
|
405 |
void CDbTableDatabase::Release(const CDbTableDef& aDef)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
TSglQueIter<CDbTable> iter(iTables);
|
sl@0
|
408 |
for (CDbTable* table;(table=iter++)!=0;)
|
sl@0
|
409 |
{
|
sl@0
|
410 |
if (&table->Def()==&aDef)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
table->Release();
|
sl@0
|
413 |
break;
|
sl@0
|
414 |
}
|
sl@0
|
415 |
}
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
//
|
sl@0
|
419 |
// Discard all open tables as the schema has been modified or discarded
|
sl@0
|
420 |
//
|
sl@0
|
421 |
void CDbTableDatabase::Release()
|
sl@0
|
422 |
{
|
sl@0
|
423 |
TSglQueIter<CDbTable> iter(iTables);
|
sl@0
|
424 |
for (CDbTable* table;(table=iter++)!=0;)
|
sl@0
|
425 |
table->Release();
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
//
|
sl@0
|
429 |
// Remove a table from the open set
|
sl@0
|
430 |
//
|
sl@0
|
431 |
void CDbTableDatabase::RemoveTable(CDbTable& aTable)
|
sl@0
|
432 |
{
|
sl@0
|
433 |
iTables.Remove(aTable);
|
sl@0
|
434 |
if (!Transaction().IsLocked() && iTables.IsEmpty())
|
sl@0
|
435 |
Idle();
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
CDbTableSource* CDbTableDatabase::TableSourceL(const TDesC& aTableName)
|
sl@0
|
439 |
{
|
sl@0
|
440 |
CDbTableSource* rec=new(ELeave) CDbTableSource;
|
sl@0
|
441 |
CDbTable* table=iTables.Find(aTableName);
|
sl@0
|
442 |
if (table)
|
sl@0
|
443 |
table->Open(); // a new reference to it
|
sl@0
|
444 |
else
|
sl@0
|
445 |
{
|
sl@0
|
446 |
CleanupStack::PushL(rec);
|
sl@0
|
447 |
table=TableL(SchemaL().FindL(aTableName));
|
sl@0
|
448 |
CleanupStack::Pop(); // table source
|
sl@0
|
449 |
}
|
sl@0
|
450 |
rec->Construct(table);
|
sl@0
|
451 |
iCache.Flush(); // check-point for object cache membership
|
sl@0
|
452 |
return rec;
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
//
|
sl@0
|
456 |
// Prepare the data pipeline
|
sl@0
|
457 |
//
|
sl@0
|
458 |
CDbCursor* CDbTableDatabase::PrepareViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess aAccess)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
Transaction().DMLCheckL(); // ensure we can open a cursor
|
sl@0
|
461 |
CSqlQuery *query=Sql::ParseQueryLC(aQuery.Query());
|
sl@0
|
462 |
RDbAccessPlan plan(query,aQuery.Comparison());
|
sl@0
|
463 |
plan.BuildLC(*this,aAccess,aWindow);
|
sl@0
|
464 |
CDbTableCursor* cursor=CDbTableCursor::NewL(plan,aAccess);
|
sl@0
|
465 |
CleanupStack::Pop(); // the plan
|
sl@0
|
466 |
CleanupStack::PopAndDestroy(); // the query
|
sl@0
|
467 |
return cursor;
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
//
|
sl@0
|
471 |
// Prepare the data pipeline
|
sl@0
|
472 |
//
|
sl@0
|
473 |
CDbCursor* CDbTableDatabase::PrepareTableL(const TDesC& aTable,RDbRowSet::TAccess aAccess)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
Transaction().DMLCheckL(); // ensure we can open a cursor
|
sl@0
|
476 |
RDbAccessPlan plan;
|
sl@0
|
477 |
plan.BuildLC(*this,aTable,aAccess);
|
sl@0
|
478 |
CDbTableCursor* cursor=CDbTableCursor::NewL(plan,aAccess);
|
sl@0
|
479 |
CleanupStack::Pop(); // the plan
|
sl@0
|
480 |
return cursor;
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
void CDbTableDatabase::DoCreateTableL(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
if (SchemaL().Find(aName))
|
sl@0
|
486 |
__LEAVE(KErrAlreadyExists);
|
sl@0
|
487 |
// validate the colset set passed in
|
sl@0
|
488 |
Validate::NameL(aName);
|
sl@0
|
489 |
Validate::ColSetL(aColSet);
|
sl@0
|
490 |
Transaction().DDLBeginLC();
|
sl@0
|
491 |
iSchema.Add(CreateTableL(aName,aColSet,aPrimaryKey));
|
sl@0
|
492 |
Transaction().DDLCommitL();
|
sl@0
|
493 |
CleanupStack::Pop(); // rollback not required
|
sl@0
|
494 |
}
|
sl@0
|
495 |
|
sl@0
|
496 |
//
|
sl@0
|
497 |
// Create index definition and prepare to build it
|
sl@0
|
498 |
//
|
sl@0
|
499 |
CDbTableDatabase::CIncremental* CDbTableDatabase::OpenCreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep)
|
sl@0
|
500 |
{
|
sl@0
|
501 |
CDbTableDef& tDef=SchemaL().FindL(aTable);
|
sl@0
|
502 |
RDbIndexes& indexes=tDef.Indexes();
|
sl@0
|
503 |
if (indexes.Find(aName)!=NULL)
|
sl@0
|
504 |
__LEAVE(KErrAlreadyExists);
|
sl@0
|
505 |
if (indexes.Count()==KDbTableMaxIndexes)
|
sl@0
|
506 |
__LEAVE(KErrNotSupported);
|
sl@0
|
507 |
Validate::NameL(aName);
|
sl@0
|
508 |
Validate::KeyL(aKey,tDef.Columns());
|
sl@0
|
509 |
if (aKey.IsPrimary())
|
sl@0
|
510 |
__LEAVE(KErrArgument); // cannot create a primary index
|
sl@0
|
511 |
|
sl@0
|
512 |
CCreateIndex* builder=CCreateIndex::NewLC(Transaction());
|
sl@0
|
513 |
CDbTableIndexDef* xDef=CreateIndexL(tDef,aName,aKey);
|
sl@0
|
514 |
tDef.Indexes().Add(xDef);
|
sl@0
|
515 |
Release(tDef); // release any table using the old schema
|
sl@0
|
516 |
aStep=builder->ConstructL(tDef,*xDef);
|
sl@0
|
517 |
CleanupStack::Pop(); // builder
|
sl@0
|
518 |
return builder;
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|
sl@0
|
521 |
//
|
sl@0
|
522 |
// Remove index from schema first, then remove index data
|
sl@0
|
523 |
//
|
sl@0
|
524 |
CDbTableDatabase::CIncremental* CDbTableDatabase::OpenDropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep)
|
sl@0
|
525 |
{
|
sl@0
|
526 |
CDbTableDef& tDef=SchemaL().FindL(aTable);
|
sl@0
|
527 |
CDbTableIndexDef& xDef=tDef.Indexes().FindL(aName);
|
sl@0
|
528 |
//
|
sl@0
|
529 |
Release(tDef); // release any table using the old schema
|
sl@0
|
530 |
CDropIndex* drop=CDropIndex::NewL(Transaction(),tDef,&xDef,aStep);
|
sl@0
|
531 |
tDef.Indexes().Remove(&xDef);
|
sl@0
|
532 |
return drop;
|
sl@0
|
533 |
}
|
sl@0
|
534 |
|
sl@0
|
535 |
CDbTableDatabase::CIncremental* CDbTableDatabase::OpenDropTableL(const TDesC& aTable,TInt& aStep)
|
sl@0
|
536 |
{
|
sl@0
|
537 |
CDbTableDef& tDef=SchemaL().FindL(aTable);
|
sl@0
|
538 |
//
|
sl@0
|
539 |
Release(tDef); // release the tables using the old schema
|
sl@0
|
540 |
CDropTable* drop=CDropTable::NewL(Transaction(),&tDef,aStep);
|
sl@0
|
541 |
iSchema.Remove(&tDef);
|
sl@0
|
542 |
return drop;
|
sl@0
|
543 |
}
|
sl@0
|
544 |
|
sl@0
|
545 |
//
|
sl@0
|
546 |
// Create an incremental table altering object
|
sl@0
|
547 |
//
|
sl@0
|
548 |
CDbTableDatabase::CIncremental* CDbTableDatabase::OpenAlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
CDbTableDef& tDef=SchemaL().FindL(aTable);
|
sl@0
|
551 |
Validate::ColSetL(aNewDef);
|
sl@0
|
552 |
Release(tDef); // release the tables using the old schema
|
sl@0
|
553 |
return CAlterTable::NewL(Transaction(),tDef,aNewDef,aStep);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
|
sl@0
|
556 |
//
|
sl@0
|
557 |
// Reserved for future development
|
sl@0
|
558 |
//
|
sl@0
|
559 |
EXPORT_C void CDbTableDatabase::Reserved_1()
|
sl@0
|
560 |
{
|
sl@0
|
561 |
}
|
sl@0
|
562 |
|
sl@0
|
563 |
//
|
sl@0
|
564 |
// Reserved for future development
|
sl@0
|
565 |
//
|
sl@0
|
566 |
EXPORT_C void CDbTableDatabase::Reserved_2()
|
sl@0
|
567 |
{
|
sl@0
|
568 |
}
|