RDbNamedDatabase execute leave -6 when update
| Wed, 2007-09-12 05:32 | |
|
Hi I am using the RDbNamedDatabase, everything seems be ok except the update field=field+1 SQLStatement:UPDATE filestore SET fseq=fseq+1 WHERE fid='20070912120624' AND fseq>0 The table is :CREATE TABLE filestore (fid CHAR (60) NOT NULL, fname CHAR (60) NOT NULL,fseq UNSIGNED INTEGER,fmname CHAR (60) NOT NULL,fprice CHAR (60) NOT NULL,ftype UNSIGNED INTEGER, fcategory CHAR (60), fstatus UNSIGNED INTEGER,fdes CHAR (60), fowner UNSIGNED INTEGER) TableIndex is :CREATE UNIQUE INDEX fstore_index ON filestore (fid, fname, fseq) when i change the sql to :UPDATE filestore SET fseq=1 WHERE fid='20070912120624' AND fseq>0, it can work. Is it the RDbNamedDatabase can not support field=filed +1 ??? |
|






Forum posts: 2009
Looks like it don't as -6 is generally returned when the query is invalid. Use the C++ interface to do the select, read the data and update it as per your need.
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 26
Hi ....
Please go through with this code ..
It may solve ur problem...
User::LeaveIfError(iTable.Open(iDbNamedDatabase, aTableName, iTable.EUpdatable));
CleanupClosePushL(iTable);
iTable.Reset();
CDbColSet* colset = iTable.ColSetL();
Count();i++)
CleanupStack::PushL(colset );
TInt rowCount = iTable.CountL();
for(TInt i=0;i
{
iTable.Reset();
iTable.InsertL();
iTable.SetColL(colset ->ColNo(_L("RowId") ), ++rowCount );
}
}
CleanupStack::PopAndDestroy(colset );
CleanupStack::Pop();
iTable.Close();
Ruchi.
Forum posts: 26
or you can make use your query like ..
_LIT( KText1,"UPDATE filestore SET fseq='" );
_LIT( KText2, " fid='20070912120624' AND fseq>0" );
TBuf<256> sqlQuery;
_LIT( KFormatString, "%S%D%S" );
sqlQuery.Format( KFormatString,&KText1,++fseq,&KText2);
sqlQuery.TrimAll();
iDbNamedDatabase.Execute( sqlQuery );
Hop this ll solve your problem...
Ruchi.
Forum posts: 46
Thanks, it is solved. code is here:
void CDBMSengine::UpdateOtherSeqsL(TInt aIncreaseDecrease)
{
TInt ret;
RDbs dbSession;
User::LeaveIfError( dbSession.Connect() );
CleanupClosePushL( dbSession );
RDbNamedDatabase database;
ret = database.Open( dbSession, KDatabaseName );
if ( ret != KErrNone )
{
CEikonEnv::Static()->InfoWinL( _L("Information"), _L("Please create database first!"));
CleanupStack::PopAndDestroy(); // dbSession
return;
}
CleanupClosePushL( database );
database.Begin();
RDbView Myview;
_LIT(KSQLQuery, "SELECT * FROM filestore WHERE fid = ");
_LIT( KAnd1, " AND fseq >= " );
_LIT( KOrder, " ORDER BY fseq" );
TBuf<KMaxSQLLength> SQLStatement;
SQLStatement = KSQLQuery;
SQLStatement.Append( KSQLQuote1 );
SQLStatement.Append( iFid );
SQLStatement.Append( KSQLQuote1 );
SQLStatement.Append( KAnd1 );
SQLStatement.AppendNum( iFSeq );
SQLStatement.Append( KOrder );
RDebug::Print(_L("SQLStatement:%s"),SQLStatement.Ptr());
Myview.Prepare(database, TDbQuery(SQLStatement));
CleanupClosePushL(Myview);
Myview.EvaluateAll();
Myview.FirstL();
TInt i = iFSeq;
while(Myview.AtRow())
{
if (aIncreaseDecrease == 1)
{
i++;
Myview.UpdateL();
Myview.SetColL(5, i);
}
else if (aIncreaseDecrease == 0)
{
Myview.UpdateL();
Myview.SetColL(5, i);
i++;
}
Myview.PutL();
Myview.NextL();
}
CleanupStack::PopAndDestroy(1); // Myview
User::LeaveIfError( database.Commit() );
User::LeaveIfError( database.Compact() );
CleanupStack::PopAndDestroy(); // pop and close database
CleanupStack::PopAndDestroy(); // pop and close dbSession
}