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 ...

Get Inside Symbian SQL: A Mobile Developer's Guide to SQLite now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.