1
0
forked from cheng/wallet

window refreshed on add username

but the overhead and screen flash
of destroying and recreating every
little window is annoying.

I should use something like:
SELECT COUNT(*) FROM UserZookoIDs
WHERE LOWER("name")<LOWER(?1) AND "name"<?1);
and insert a new item at that position
This commit is contained in:
Cheng 2023-11-11 02:10:36 +00:00
parent 35a3be9aa7
commit f819b98d9e
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
3 changed files with 11 additions and 45 deletions

View File

@ -180,45 +180,13 @@ public:
}; };
class sql_insert_name { class sql_insert_name {
ro::sql csql_begin;
ro::sql csql_into_names; ro::sql csql_into_names;
ro::sql csql_namekey_into_keys;
ro::sql csql_commit;
ro::sql csql_rollback;
public: public:
sql_insert_name(ISqlite3* p) : sql_insert_name(ISqlite3* p) :
csql_begin(p, R"|(BEGIN IMMEDIATE;)|"), csql_into_names(p, R"|(INSERT OR FAIL INTO "UserZookoIDs" VALUES(?1, ?2);)|"){}
csql_into_names(p, R"|(INSERT OR FAIL INTO "Names" VALUES(NULL, ?1);)|"),
csql_namekey_into_keys(p, R"|(INSERT OR FAIL INTO "Keys" VALUES(NULL, ?1, last_insert_rowid(), 1);)|"),
/* NULL triggers special nonstandard Sqlite behavior to autogenerate a unique ROWID
Because we explicitly make the ROWID a named field in the table to avoid too much
non standard SQlite behavior, we must explicitly provide a placeholder in the INSERT
statement. So at least we only get special SQlite3 behavior when we deliberately
invoke it. */
csql_commit(p, R"|(COMMIT;)|"),
csql_rollback(p, R"|(ROLLBACK;)|")
{}
sql_insert_name(const std::unique_ptr<ISqlite3>& p) : sql_insert_name(p.get()) {} sql_insert_name(const std::unique_ptr<ISqlite3>& p) : sql_insert_name(p.get()) {}
void operator()(const char* psz, const ristretto255::point& pt) { void operator()(const char* psz, const ristretto255::point& pt) {
csql_begin.do_one(); csql_into_names.do_one(psz,pt);
try {
csql_into_names.do_one(psz);
csql_namekey_into_keys.do_one(pt);
}
catch (const MyException& e) {
csql_rollback.do_one();
if (e.what_num() == 19) {
throw MyException("Name already in database");
}
else {
throw;
}
}
catch (const std::exception &) {
csql_rollback.do_one();
throw;
}
csql_commit.do_one();
} }
}; };
@ -234,7 +202,5 @@ public:
} }
}; };
constexpr auto WALLET_FILE_IDENTIFIER (0x56d34bc5a655dd1fi64); constexpr auto WALLET_FILE_IDENTIFIER (0x56d34bc5a655dd1fi64);
constexpr auto WALLET_FILE_SCHEMA_VERSION_0_0(1); constexpr auto WALLET_FILE_SCHEMA_VERSION_0_0(1);

View File

@ -94,12 +94,13 @@ void display_wallet::OnClose(wxCloseEvent& event) {
void display_wallet::refresh_from_database() { void display_wallet::refresh_from_database() {
auto sizer = this->GetSizer(); auto sizer = this->GetSizer();
auto dirty_area = sizer->ComputeFittingClientSize(singletonFrame);
auto m_lsizer = sizer->GetItem((size_t)0)->GetSizer(); auto m_lsizer = sizer->GetItem((size_t)0)->GetSizer();
assert(m_lsizer); assert(m_lsizer);
auto m_rsizer = sizer->GetItem(1)->GetSizer(); auto m_rsizer = sizer->GetItem(1)->GetSizer();
assert(m_rsizer); assert(m_rsizer);
m_lsizer->Clear(); m_lsizer->Clear(true);
m_rsizer->Clear(); m_rsizer->Clear(true);
try { try {
m_read_names_and_keys->reset(); m_read_names_and_keys->reset();
while (m_read_names_and_keys->step() == Icompiled_sql::ROW) { while (m_read_names_and_keys->step() == Icompiled_sql::ROW) {
@ -111,7 +112,7 @@ void display_wallet::refresh_from_database() {
this, this,
wxID_ANY, wxID_ANY,
name, name,
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_ELLIPSIZE_END wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxEXPAND| wxFIXED_MINSIZE| wxST_ELLIPSIZE_END
), ),
10, 10,
wxALL, // and make border all around wxALL, // and make border all around
@ -121,7 +122,7 @@ void display_wallet::refresh_from_database() {
this, this,
wxID_ANY, wxID_ANY,
"#" + base58(pubkey).operator std::string(), "#" + base58(pubkey).operator std::string(),
wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxEXPAND | wxFIXED_MINSIZE | wxST_ELLIPSIZE_END
), ),
10, 10,
wxALL, // and make border all around wxALL, // and make border all around
@ -141,12 +142,11 @@ void display_wallet::refresh_from_database() {
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename); throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
} }
auto desired_size = sizer->ComputeFittingClientSize(singletonFrame); auto desired_size = sizer->ComputeFittingClientSize(singletonFrame);
singletonFrame->SetMinClientSize(desired_size); dirty_area.IncTo(desired_size);
//singletonFrame->SetMinClientSize(desired_size);
auto clientSize = singletonFrame->GetClientSize(); auto clientSize = singletonFrame->GetClientSize();
desired_size.IncTo(clientSize); desired_size.IncTo(clientSize);
if (desired_size.GetHeight() > clientSize.GetHeight() if (desired_size.GetHeight() > clientSize.GetHeight()
|| desired_size.GetWidth() > clientSize.GetWidth() || desired_size.GetWidth() > clientSize.GetWidth()
)singletonFrame->SetClientSize(desired_size); )singletonFrame->SetClientSize(desired_size);
} }

View File

@ -391,11 +391,11 @@ COMMIT;
BEGIN IMMEDIATE TRANSACTION; BEGIN IMMEDIATE TRANSACTION;
CREATE TRIGGER InsertUserZookoID INSTEAD OF INSERT ON UserZookoIDs FOR EACH ROW BEGIN CREATE TRIGGER InsertUserZookoID INSTEAD OF INSERT ON UserZookoIDs FOR EACH ROW BEGIN
INSERT OR FAIL INTO "Names" VALUES( INSERT OR ROLLBACK INTO "Names" VALUES(
NULL, NULL,
NEW."name" NEW."name"
); );
INSERT OR FAIL INTO "Keys" VALUES( INSERT OR ROLLBACK INTO "Keys" VALUES(
NULL, NULL,
NEW."pubkey", NEW."pubkey",
last_insert_rowid(), last_insert_rowid(),