Skip to content

Commit e416896

Browse files
committed
0.8.0.10: Implemented row deletion by Delete key in Schema Explorer table editor
1 parent bfedeeb commit e416896

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/sqlite-ce-edit/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ BOOL WINAPI GetSaveFileNameW(CE_OPENFILENAME*);
8282
** Version
8383
**============================================================================*/
8484

85-
#define SQLITECEDIT_VERSION L"0.8.0.8"
85+
#define SQLITECEDIT_VERSION L"0.8.0.10"
8686

8787
/*============================================================================
8888
** Menu IDs

src/sqlite-ce-edit/grid.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static int g_editCol = -1; /* Display column being edited */
2323
static void StartCellEdit(int row, int col);
2424
static void CommitCellEdit(void);
2525
static void CancelCellEdit(void);
26+
static void DeleteSelectedRow(void);
2627

2728
void CreateGridView(HWND hwndParent, int x, int y, int cx, int cy) {
2829
HIMAGELIST hIml;
@@ -159,6 +160,11 @@ LRESULT CALLBACK GridProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
159160
if (sel >= 0) StartCellEdit(sel, 0);
160161
return 0;
161162
}
163+
/* Delete - Delete selected row (only in edit mode) */
164+
if (wParam == VK_DELETE && g_editMode) {
165+
DeleteSelectedRow();
166+
return 0;
167+
}
162168
}
163169
return CallWindowProc(g_pfnGridProc, hwnd, msg, wParam, lParam);
164170
}
@@ -559,6 +565,65 @@ static void CancelCellEdit(void) {
559565
SetFocus(g_hwndGrid);
560566
}
561567

568+
static void DeleteSelectedRow(void) {
569+
int sel, dataRow, rowidIdx;
570+
char *rowid;
571+
char sql[256];
572+
char tableName[128];
573+
char *p;
574+
const char *s;
575+
char *errmsg = NULL;
576+
int rc;
577+
578+
sel = ListView_GetNextItem(g_hwndGrid, -1, LVNI_SELECTED);
579+
if (sel < 0) return;
580+
581+
/* Save table name before it gets cleared */
582+
s = g_editTableName;
583+
p = tableName;
584+
while (*s) *p++ = *s++;
585+
*p = '\0';
586+
587+
/* Confirm deletion */
588+
if (MessageBoxW(g_hwndMain, L"Delete this row?", L"Confirm Delete",
589+
MB_YESNO | MB_ICONQUESTION) != IDYES)
590+
return;
591+
592+
/* Get rowid */
593+
dataRow = g_sortIndex ? g_sortIndex[sel] : sel;
594+
rowidIdx = (dataRow + 1) * g_lastResultCols;
595+
rowid = g_lastResult[rowidIdx];
596+
597+
if (!rowid) return;
598+
599+
/* Build DELETE statement */
600+
p = sql;
601+
s = "DELETE FROM \"";
602+
while (*s) *p++ = *s++;
603+
s = tableName;
604+
while (*s) *p++ = *s++;
605+
s = "\" WHERE rowid = ";
606+
while (*s) *p++ = *s++;
607+
s = rowid;
608+
while (*s) *p++ = *s++;
609+
*p++ = ';';
610+
*p = '\0';
611+
612+
/* Execute DELETE */
613+
rc = sqlite_exec(g_db, sql, NULL, NULL, &errmsg);
614+
615+
if (rc != SQLITE_OK) {
616+
wchar_t wmsg[256];
617+
MultiByteToWideChar(CP_ACP, 0, errmsg ? errmsg : "Unknown error", -1, wmsg, 256);
618+
MessageBoxW(g_hwndMain, wmsg, L"Delete Failed", MB_OK | MB_ICONERROR);
619+
if (errmsg) sqlite_freemem(errmsg);
620+
return;
621+
}
622+
623+
/* Re-query to refresh grid */
624+
OpenTableForEditing(tableName);
625+
}
626+
562627
static void CommitCellEdit(void) {
563628
wchar_t wval[256];
564629
char newVal[512];

0 commit comments

Comments
 (0)