O'Reilly logo

Inside Symbian SQL: A Mobile Developer's Guide to SQLite by Richard Maynard, Ivan Litovski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required