我正在尝试使用Windows Store C++ 应用程序中的sqlite-winrt。我想专门使用这个包中的 Windows 运行时包装器,而不是这个包中的常规 C API。我正在尝试查看 codeplex 页面上给出的 C# 示例:
C# 代码
// Get the file from the install location
var file = await Package.Current.InstalledLocation.GetFileAsync("cities.db");
// Create a new SQLite instance for the file
var db = new Database(file);
// Open the database asynchronously
await db.OpenAsync(SqliteOpenMode.OpenRead);
// Prepare a SQL statement to be executed
var statement = awaitdb.PrepareStatementAsync(
"SELECT rowid, CityName FROM Cities;");
// Loop through all the results and add to the collection
while (awaitstatement.StepAsync())
items.Add(statement.GetIntAt(0) + ": "+ statement.GetTextAt(1));
但我无法弄清楚该代码的确切 C++ 等价物。这是我到目前为止所拥有的:
C++ 代码
auto installLoc = Windows::ApplicationModel::Package::Current->InstalledLocation;
task<Windows::Storage::StorageFile^>(installLoc->GetFileAsync("cities.db")).then([](Windows::Storage::StorageFile^ file){
auto db = ref new SQLiteWinRT::Database(file);
task<void>(db->OpenAsync(SQLiteWinRT::SqliteOpenMode::OpenRead)).then([db](){
task<SQLiteWinRT::Statement^>(db->PrepareStatementAsync("SELECT rowid, CityName FROM Cities;")).then([](SQLiteWinRT::Statement^ stmt){
// Don't know how to simulate the while loop
//task<bool>(stmt->StepAsync()).then([](bool ret){
//});
});
});
});
我不太能弄清楚如何像在 C# 中使用 while 循环那样模拟迭代的行为。任何指针?