コード例 #1
0
bool DatabaseForm::CreateDatabase(){

	Database pDatabase;
	String sql;
	String sql2;
	String statement;

	result r = E_SUCCESS;

	// create the database if it doesn't exist
	r = pDatabase.Construct(__databaseName, true);
	if (IsFailed(r)) return false;


	//pDatabase = new Database();
	//if (pDatabase == null) return false;
	//r = pDatabase->Construct(pDatabaseName,true);
	//if (IsFailed(r)) return false;

	// Create the main table
	sql.Append(L"CREATE TABLE IF NOT EXISTS movies (id INTEGER PRIMARY KEY AUTOINCREMENT, description TEXT)");
	r = pDatabase.ExecuteSql(sql, true);

	if (IsFailed(r)) return false;

	return true;
}
コード例 #2
0
void DatabaseForm::ReadItemsFromDatabase()
{
	Database pDatabase;
	DbEnumerator* pEnum;
  	String sql;
	String statement;

	result r = E_SUCCESS;

	r = pDatabase.Construct(__databaseName, false);

	sql.Append(L"select id, description from movies");
	pEnum = pDatabase.QueryN(sql);
	String description;
	int	   id;

   while( pEnum->MoveNext()== E_SUCCESS )
	{
		pEnum->GetIntAt(0, id);
		pEnum->GetStringAt(1, description);

		// Store the item in our data structure
		DatabaseItem* newItem = new DatabaseItem(description);
		newItem->SetIndex(id);
		// Display the item in our user interface using our own method
		AddItemToList(newItem);
		}
	if (pEnum != null)
		delete pEnum;
}