94 _LIT( KMdsSecurityCheckFail, "Security check fail" ); |
94 _LIT( KMdsSecurityCheckFail, "Security check fail" ); |
95 TraceAndLeaveL( KMdsSecurityCheckFail, err ); |
95 TraceAndLeaveL( KMdsSecurityCheckFail, err ); |
96 } |
96 } |
97 /** |
97 /** |
98 * Open database: |
98 * Open database: |
99 * First we try to create new db. If this fails check if db already exists and |
99 * First we try to open db. If this fails because db not creater yer, then |
100 * try to open it. Otherwise we cannot open it and we leave |
100 * try to create it. Otherwise we cannot open it and we leave |
101 */ |
101 */ |
102 err = iMdeSqlDb.Create( *iDbFileName, sqlSecurityPolicy, &KMdsSqlDbaConfig ); |
102 err = iMdeSqlDb.Open( *iDbFileName, &KMdsSqlDbaConfig ); |
103 if ( err != KErrNone ) |
103 if ( err != KErrNone ) |
104 { |
104 { |
105 // it could fail because database exists |
105 __LOG1( ELogDb, "Cannot open database %d", err ); |
106 if ( err == KErrAlreadyExists ) |
106 |
107 { |
107 if( err == KErrNotFound ) |
108 err = iMdeSqlDb.Open( *iDbFileName, &KMdsSqlDbaConfig ); |
108 { |
109 if ( err != KErrNone ) |
109 __LOG1( ELogDb, "Cannot find database %d", err ); |
110 { |
110 err = iMdeSqlDb.Create( *iDbFileName, sqlSecurityPolicy, &KMdsSqlDbaConfig ); |
111 __LOG1( ELogDb, "Cannot open database %d", err ); |
111 if( err != KErrNone ) |
112 } |
112 { |
113 } |
113 __LOG1( ELogDb, "Unknown error while creating %d", err ); |
114 else |
114 User::LeaveIfError( err ); |
115 { |
115 } |
116 __LOG1( ELogDb, "Unknown error while creating %d", err ); |
116 } |
117 } |
117 else if( err == KErrCorrupt || |
118 |
118 err == KSqlErrCorrupt ) |
119 User::LeaveIfError( err ); |
119 { |
120 } |
120 __LOGLB( ELogDb, "Warning: Database is corrupted, will delete and re-create it." ); |
|
121 err = DeleteAndReCreateDB( iDbFileName, sqlSecurityPolicy, &KMdsSqlDbaConfig ); |
|
122 |
|
123 if ( KErrNone == err ) |
|
124 { |
|
125 err = iMdeSqlDb.Open( *iDbFileName, &KMdsSqlDbaConfig ); |
|
126 if ( err != KErrNone ) |
|
127 { |
|
128 __LOG1( ELogDb, "Cannot open database again after delete and re-create %d", err ); |
|
129 User::LeaveIfError( err ); |
|
130 } |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 __LOG1( ELogDb, "Unknown error while accessing database %d", err ); |
|
136 User::LeaveIfError( err ); |
|
137 } |
|
138 } |
121 CleanupStack::PopAndDestroy( &sqlSecurityPolicy ); |
139 CleanupStack::PopAndDestroy( &sqlSecurityPolicy ); |
122 } |
140 } |
123 |
141 |
124 TInt CMdSSqLiteConnection::ExecuteL( const TDesC& aCommand, |
142 TInt CMdSSqLiteConnection::ExecuteL( const TDesC& aCommand, |
125 const RRowData& aVariables, |
143 const RRowData& aVariables, |
331 else |
349 else |
332 { |
350 { |
333 _LIT( KMdsNoProcessableRow, "Wrong row to process" ); |
351 _LIT( KMdsNoProcessableRow, "Wrong row to process" ); |
334 TraceAndLeaveL( KMdsNoProcessableRow, KSqlErrNotFound ); |
352 TraceAndLeaveL( KMdsNoProcessableRow, KSqlErrNotFound ); |
335 } |
353 } |
|
354 } |
|
355 |
|
356 TItemId CMdSSqLiteConnection::LastInsertedRowId() |
|
357 { |
|
358 return iMdeSqlDb.LastInsertedRowId(); |
336 } |
359 } |
337 |
360 |
338 void CMdSSqLiteConnection::ColumnsL( const RSqlStatement& aStatement, RRowData& aRow ) |
361 void CMdSSqLiteConnection::ColumnsL( const RSqlStatement& aStatement, RRowData& aRow ) |
339 { |
362 { |
340 const TInt count( aRow.Size() ); |
363 const TInt count( aRow.Size() ); |
578 // save current find operation which will continue when diable transaction |
601 // save current find operation which will continue when diable transaction |
579 iNotFinishFindQuery = &aQuery; |
602 iNotFinishFindQuery = &aQuery; |
580 } |
603 } |
581 } |
604 } |
582 |
605 |
|
606 |
|
607 TInt CMdSSqLiteConnection::DeleteAndReCreateDB( const HBufC* aDbFileName, |
|
608 const RSqlSecurityPolicy& asqlSecurityPolicy, |
|
609 const TDesC8* aKMdsSqlDbaConfig ) |
|
610 { |
|
611 TInt err = iMdeSqlDb.Delete( *aDbFileName ); |
|
612 if( err!= KErrNone ) |
|
613 { |
|
614 __LOG1( ELogDb, "delete database err=%d.", err ); |
|
615 return err; |
|
616 } |
|
617 |
|
618 err = iMdeSqlDb.Create( *aDbFileName, asqlSecurityPolicy, aKMdsSqlDbaConfig ); |
|
619 |
|
620 return err; |
|
621 } |
|
622 |