Use the ULDatabaseManager object to create or connect to an UltraLite database named sample.udb.
Prérequis
There are no prerequisites for this task.
Initialize the ULDatabaseManager object and enable features in UltraLite using the following code:
if( !ULDatabaseManager::Init() ) { return 0; } ULDatabaseManager::EnableAesDBEncryption(); // Use ULDatabaseManager.Fini() when terminating the app. |
Open a connection to an existing database or create a new database if the specified database file does not exist using the following code:
ULConnection * conn; ULError ulerr; conn = ULDatabaseManager::OpenConnection( "dbf=sample.udb;dbkey=aBcD1234", &ulerr ); if( conn == NULL ) { if( ulerr.GetSQLCode() == SQLE_ULTRALITE_DATABASE_NOT_FOUND ) { conn = ULDatabaseManager::CreateDatabase( "dbf=sample.udb;dbkey=aBcD1234", &ulerr ); if( conn == NULL ) { // write code that uses ulerr to determine what happened return 0; } // add code to create the schema for your database } else { // write code that uses ulerr to determine what happened return 0; } } assert( conn != NULL ); |
In this step, you declare a ULError object that contains error information in case the connection is not successful.
![]() |
Discuter à propos de cette page dans DocCommentXchange.
|
Copyright © 2013, SAP AG ou société affiliée SAP - SAP Sybase SQL Anywhere 16.0 |