Appendix A. Troubleshooting
In this appendix, we discuss troubleshooting SQL statements and language, memory and disk usage, transactions, and error handling.
Executing SQL Statements
RSqlStatement::Next() returns KSqlErrMisuse following the preparation and execution of a SELECT statement:
_LIT(KSelectStmt, "SELECT * FROM MyTable");
RSqlStatement stmt;
CleanupClosePushL(stmt);
// RSqlDatabase iDatabase already connected
stmt.PrepareL(iDatabase, KSelectStmt);
User::LeaveIfError(stmt.Exec());
TInt err = stmt.Next();
if (err == KSqlAtRow)
{
// Do something
// ...
}
CleanupStack::PopAndDestroy(&stmt);The call to Exec() is unnecessary; it would only be necessary when binding values. In this case, Next() can be called directly after PrepareL() as it executes the statement itself and moves to the next row.
stmt.PrepareL(iDatabase, KSelectStmt); TInt err = stmt.Next(); if (err == KSqlAtRow)
{
// Do something
}
CleanupStack::PopAndDestroy(&stmt);RSqlStatement::Next() should only be called after SELECT statements. It panics[8] after preparing INSERT, UPDATE or DELETE statements:[9]
_LIT(KInsertStmt, "INSERT INTO MyTable (id, data)
VALUES (1, 'Record 1')");
RSqlStatement stmt;
CleanupClosePushL(stmt);
// RSqlDatabase iDatabase already connected
stmt.PrepareL(iDatabase, KInsertStmt);
User::LeaveIfError(stmt.Next());
CleanupStack::PopAndDestroy(&stmt);It is incorrect to call Next() for INSERT, UPDATE or DELETE statements as they do not return any records. Exec() should be called instead.
Panics can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access