C/C++ Examples

Home

MoSync SDK 3.2.1

DatabaseTest

This simple example application demonstrates how to use the MoSync Database API. This example works on all platforms supported by the API (see Feature/Platfom Support).

Initial screen (MoSync Emulator)After test (MoSync Emulator)


Getting the source code

Unfortunately, DatabaseTest is missing from the examples folder included with MoSync SDK. You can get the code for the example from GitHub. The most recent version is here:https://github.com/MoSync/MoSync/blob/master/examples/cpp/DatabaseTest/main.cpp

But unless you are using nightly builds, it is recommended to use this version:https://github.com/MoSync/MoSync/blob/ThreeOne/examples/cpp/DatabaseTest/main.cpp

This version is written to work with the current release (3.1). The latest version uses maDBExecSQLParams, which not yet in the release version of MoSync SDK. If you create a new C++ project in the MoSync IDE and paste that code, it should work to run the example.

Behaviour

  • The program has one screen that displays textual output.
  • Touch the screen to start running the database tests (or click on the screen in the MoSync Emulator).
  • A database file will be created on the device, in the local file system of the application.
  • If the test is successful, the text "Database test passed successfully" is displayed at the end of the output.
  • The program exits with a panic message if a test fails.
  • Quit the program by pressing back (on Android) or key zero (in the MoSync Emulator).

In the code

The project consists of one file, main.cpp, which contains commented source code to help understand the Database API. The example database used has a table called "pet" which contains data about pets. The database is created by the program. The tests made include making queries and checking that the results match the expected values.

 

Copyright © 2013 MoSync AB
www.mosync.com