Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Unifiy lastError message fetching and do not set last error message i…
Browse files Browse the repository at this point in the history
…f nothing SQLite specific went wrong.
  • Loading branch information
pke committed Mar 22, 2013
1 parent 02431a6 commit 60b1f72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 17 additions & 4 deletions SQLite3Component/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ namespace SQLite3 {
bool Database::sharedCache = false;

IAsyncOperation<Database^>^ Database::OpenAsync(Platform::String^ dbPath) {
if (!dbPath->Length()) {
throw ref new Platform::COMException(E_INVALIDARG, L"You must specify a path or :memory:");
}

// Need to remember the current thread for later callbacks into JS
CoreDispatcher^ dispatcher = CoreWindow::GetForCurrentThread()->Dispatcher;

return Concurrency::create_async([dbPath, dispatcher]() {
Expand Down Expand Up @@ -222,7 +227,7 @@ namespace SQLite3 {
statement->Run();
return sqlite3_changes(sqlite);
} catch (Platform::Exception^ e) {
lastErrorMsg = (WCHAR*)sqlite3_errmsg16(sqlite);
saveLastErrorMessage();
throw;
}
});
Expand All @@ -243,7 +248,7 @@ namespace SQLite3 {
StatementPtr statement = PrepareAndBind(sql, params);
return statement->One();
} catch (Platform::Exception^ e) {
lastErrorMsg = (WCHAR*)sqlite3_errmsg16(sqlite);
saveLastErrorMessage();
throw;
}
});
Expand All @@ -264,7 +269,7 @@ namespace SQLite3 {
StatementPtr statement = PrepareAndBind(sql, params);
return statement->All();
} catch (Platform::Exception^ e) {
lastErrorMsg = (WCHAR*)sqlite3_errmsg16(sqlite);
saveLastErrorMessage();
throw;
}
});
Expand All @@ -285,7 +290,7 @@ namespace SQLite3 {
StatementPtr statement = PrepareAndBind(sql, params);
statement->Each(callback, dispatcher);
} catch (Platform::Exception^ e) {
lastErrorMsg = (WCHAR*)sqlite3_errmsg16(sqlite);
saveLastErrorMessage();
throw;
}
});
Expand All @@ -297,4 +302,12 @@ namespace SQLite3 {
statement->Bind(params);
return statement;
}

void Database::saveLastErrorMessage() {
if (sqlite3_errcode(sqlite) != SQLITE_OK) {
lastErrorMessage = (WCHAR*)sqlite3_errmsg16(sqlite);
} else {
lastErrorMessage.clear();
}
}
}
6 changes: 4 additions & 2 deletions SQLite3Component/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace SQLite3 {

property Platform::String^ LastError {
Platform::String^ get() {
return ref new Platform::String(lastErrorMsg.c_str());
return ref new Platform::String(lastErrorMessage.c_str());
};
}

Expand Down Expand Up @@ -136,7 +136,9 @@ namespace SQLite3 {
Platform::String^ collationLanguage;
Windows::UI::Core::CoreDispatcher^ dispatcher;
sqlite3* sqlite;
std::wstring lastErrorMsg;
std::wstring lastErrorMessage;

void saveLastErrorMessage();

event ChangeHandler^ _Insert;
int insertChangeHandlers;
Expand Down

0 comments on commit 60b1f72

Please sign in to comment.