Skip to content

Commit

Permalink
Up to 1.3.6
Browse files Browse the repository at this point in the history
* Improve terminal output
* Minor changes
  • Loading branch information
little-brother committed Dec 27, 2020
1 parent 0f4e58d commit 22c4485
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 95 deletions.
10 changes: 5 additions & 5 deletions sqlite-gui.depend
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
1562796420 d:\codes\sqlite-gui\sqlite3.h
<stdarg.h>

1608912636 source:d:\codes\sqlite-gui\src\resource.rc
1609009038 source:d:\codes\sqlite-gui\src\resource.rc
<windows.h>
<commctrl.h>
<richedit.h>
"resource.h"

1608464169 d:\codes\sqlite-gui\src\resource.h
1608992353 d:\codes\sqlite-gui\src\resource.h

1608543484 source:d:\codes\sqlite-gui\src\prefs.cpp
<ctime>
Expand All @@ -43,7 +43,7 @@
1583506689 d:\codes\sqlite-gui\src\sqlite3.h
<stdarg.h>

1608912507 source:d:\codes\sqlite-gui\src\main.cpp
1609054363 source:d:\codes\sqlite-gui\src\main.cpp
"global.h"
"missing.h"
"resource.h"
Expand All @@ -69,7 +69,7 @@
<ctype.h>
"utils.h"

1608116861 source:d:\codes\sqlite-gui\src\tools.cpp
1609012211 source:d:\codes\sqlite-gui\src\tools.cpp
"global.h"
"missing.h"
"resource.h"
Expand Down Expand Up @@ -97,7 +97,7 @@
1599763781 d:\codes\sqlite-gui\src\dialogs.h
<windows.h>

1607610357 source:d:\codes\sqlite-gui\src\dialogs.cpp
1608992726 source:d:\codes\sqlite-gui\src\dialogs.cpp
"resource.h"
"global.h"
"prefs.h"
Expand Down
56 changes: 28 additions & 28 deletions sqlite-gui.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,74 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="ToDo.txt" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\prefs.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="5" topLine="0" />
<Cursor1 position="2318" topLine="60" />
</Cursor>
</File>
<File name="src\dialogs.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\prefs.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="33241" topLine="876" />
<Cursor1 position="182" topLine="0" />
</Cursor>
</File>
<File name="src\dialogs.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\resource.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="263" topLine="0" />
<Cursor1 position="2790" topLine="37" />
</Cursor>
</File>
<File name="src\global.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\resource.rc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2016" topLine="47" />
<Cursor1 position="27561" topLine="631" />
</Cursor>
</File>
<File name="src\main.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="src\tools.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="71557" topLine="1854" />
<Cursor1 position="57154" topLine="1468" />
</Cursor>
</File>
<File name="src\missing.h" open="0" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\tools.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="261" topLine="0" />
<Cursor1 position="850" topLine="0" />
</Cursor>
</File>
<File name="src\prefs.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\utils.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="887" topLine="0" />
<Cursor1 position="3130" topLine="161" />
</Cursor>
</File>
<File name="src\prefs.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\utils.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="182" topLine="0" />
<Cursor1 position="255" topLine="0" />
</Cursor>
</File>
<File name="src\resource.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="ToDo.txt" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2467" topLine="4" />
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="src\resource.rc" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="26060" topLine="631" />
<Cursor1 position="58641" topLine="1607" />
</Cursor>
</File>
<File name="src\tools.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="62983" topLine="1619" />
<Cursor1 position="263" topLine="0" />
</Cursor>
</File>
<File name="src\tools.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\global.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="850" topLine="0" />
<Cursor1 position="2016" topLine="47" />
</Cursor>
</File>
<File name="src\utils.cpp" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\main.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="3130" topLine="161" />
<Cursor1 position="67205" topLine="1729" />
</Cursor>
</File>
<File name="src\utils.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\missing.h" open="0" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="412" topLine="0" />
<Cursor1 position="261" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
6 changes: 6 additions & 0 deletions src/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,9 @@ namespace dialogs {
_stprintf(buf, TEXT("%i"), prefs::get("row-limit"));
SetDlgItemText(hWnd, IDC_DLG_ROW_LIMIT, buf);

_stprintf(buf, TEXT("%i"), prefs::get("cli-row-limit"));
SetDlgItemText(hWnd, IDC_DLG_CLI_ROW_LIMIT, buf);

char* startup8 = prefs::get("startup", "");
TCHAR* startup16 = utils::utf8to16(startup8);
SetDlgItemText(hWnd, IDC_DLG_STARTUP, startup16);
Expand Down Expand Up @@ -1637,6 +1640,9 @@ namespace dialogs {
GetDlgItemText(hWnd, IDC_DLG_ROW_LIMIT, buf, 255);
prefs::set("row-limit", (int)_tcstod(buf, NULL));

GetDlgItemText(hWnd, IDC_DLG_CLI_ROW_LIMIT, buf, 255);
prefs::set("cli-row-limit", (int)_tcstod(buf, NULL));

setEditorFont(hEditorWnd);
setTreeFont(hTreeWnd);
sqlite3_exec(db, prefs::get("use-legacy-rename") ? "pragma legacy_alter_table = 1" : "pragma legacy_alter_table = 0", 0, 0, 0);
Expand Down
140 changes: 92 additions & 48 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
TCHAR* version16 = utils::utf8to16(version8);
SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)version16);
delete [] version16;
SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)TEXT(" GUI: 1.3.5"));
SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)TEXT(" GUI: 1.3.6"));

hTreeWnd = CreateWindowEx(0, WC_TREEVIEW, NULL, WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | WS_DISABLED | TVS_EDITLABELS, 0, 0, 100, 100, hMainWnd, (HMENU)IDC_TREE, hInstance, NULL);
hMainTabWnd = CreateWindowEx(0, WC_STATIC, NULL, WS_VISIBLE | WS_CHILD | SS_NOTIFY, 100, 0, 100, 100, hMainWnd, (HMENU)IDC_MAINTAB, hInstance, NULL);
Expand Down Expand Up @@ -1366,44 +1366,81 @@ int executeCLIQuery(bool isPlan) {
int colCount = sqlite3_column_count(stmt);

if (colCount && (rc == SQLITE_ROW || rc == SQLITE_DONE || rc == SQLITE_OK)) {
HWND hListWnd = CreateWindow(WC_LISTBOX, NULL, WS_CHILD, 0, 0, 150, 200, hCLIResultWnd, (HMENU)0, GetModuleHandle(0), NULL);
size_t maxWidths[colCount]{0};

for (int i = 0; i < colCount; i++) {
TCHAR* name16 = utils::utf8to16(sqlite3_column_name(stmt, i));
TCHAR buf16[255];
_stprintf(buf16, TEXT("%-20s"), name16);
_tcscat(result16, buf16);
delete [] name16;
_tcscat(result16, i == colCount - 1 ? TEXT("\n") : TEXT(" | "));
ListBox_AddString(hListWnd, name16);
maxWidths[i] = _tcslen(name16);
}

TCHAR line16[colCount * 30 + 1]{0};
_tcscpy(line16, result16);
_tcsset(line16, TEXT('-'));
_tcscat(result16, line16);
_tcscat(result16, TEXT("\n"));

int rowLimit = prefs::get("cli-row-limit");
while (rc == SQLITE_ROW && (rowCount < rowLimit || rowLimit <= 0)) {
for (int i = 0; i < colCount; i++) {
TCHAR* value16 = utils::utf8to16((const char*)sqlite3_column_text(stmt, i));
TCHAR buf16[255], vbuf16[32];
_tcsncpy(vbuf16, value16, 20);
_stprintf(buf16, TEXT("%-20s"), vbuf16);
_tcscat(result16, buf16);
delete [] value16;
_tcscat(result16, i == colCount - 1 ? TEXT("\n") : TEXT(" | "));
if (sqlite3_column_type(stmt, i) != SQLITE_BLOB) {
TCHAR* value16 = utils::utf8to16((const char*)sqlite3_column_text(stmt, i));
TCHAR* tvalue16 = utils::replaceAll(value16, TEXT("\r\n"), TEXT(" "));
TCHAR trimmed16[256]{0};
_tcsncpy(trimmed16, tvalue16, 255);
delete [] tvalue16;
delete [] value16;
if (maxWidths[i] < _tcslen(trimmed16))
maxWidths[i] = _tcslen(trimmed16);

ListBox_AddString(hListWnd, trimmed16);
} else {
if (maxWidths[i] < 6)
maxWidths[i] = 6;
ListBox_AddString(hListWnd, TEXT("(BLOB)"));
}
}

rowCount++;
rc = sqlite3_step(stmt);
}

int w = (colCount - 1) * 3;
for (int i = 0; i < colCount; i++)
w += maxWidths[i];

TCHAR line16[w + 1]{0};
for (int i = 0; i < w; i++)
line16[i] = TEXT('-');
_tcscat(result16, line16);
_tcscat(result16, TEXT("\n"));

for (int i = 0; i < colCount; i++) {
TCHAR name16[255]{0};
ListBox_GetText(hListWnd, i, name16);
TCHAR buf16[maxWidths[i] + 10]{0};
_stprintf(buf16, TEXT("%-*s"), maxWidths[i], name16);
_tcscat(result16, buf16);
_tcscat(result16, (i < colCount - 1) ? TEXT(" | ") : TEXT("\n"));
}
_tcscat(result16, line16);
_tcscat(result16, TEXT("\n"));

for (int rowNo = 0; rowNo < rowCount; rowNo++) {
for (int i = 0; i < colCount; i++) {
TCHAR value16[maxWidths[i] + 1]{0};
ListBox_GetText(hListWnd, i + (rowNo + 1) * colCount, value16);
TCHAR buf16[maxWidths[i] + 10]{0};
_stprintf(buf16, TEXT("%-*s"), maxWidths[i], value16);
_tcscat(result16, buf16);
_tcscat(result16, (i < colCount - 1) ? TEXT(" | ") : TEXT("\n"));
}
}

if (rc == SQLITE_ROW) {
_tcscat(result16, TEXT("... more rows available\n"));
rc = SQLITE_DONE;
}

if (rowCount)
_tcscat(result16, line16);

DestroyWindow(hListWnd);
}

if (rc == SQLITE_DONE) {
Expand All @@ -1424,36 +1461,38 @@ int executeCLIQuery(bool isPlan) {
delete [] msg16;
}

_tcscat(result16, TEXT("\n\n============================================================\n\n"));
SendMessage(hCLIResultWnd, EM_SETSEL, 0, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)result16);

if (rc == SQLITE_OK) {
SendMessage(hCLIResultWnd, EM_SETSEL, 0, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)TEXT("\n"));
if (_tcslen(result16)) {
_tcscat(result16, TEXT("\n\n============================================================\n\n"));
SendMessage(hCLIResultWnd, EM_SETSEL, 0, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)sql16);
SetWindowText(hCLIEditorWnd, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)result16);

if(SQLITE_OK == sqlite3_prepare_v2(db, "insert into preferences.cli (time, dbname, query, elapsed, result) values (strftime('%s', 'now'), ?1, ?2, ?3, ?4)", -1, &stmt, 0)) {
char* dbname8 = utils::getFileName(sqlite3_db_filename(db, 0));
sqlite3_bind_text(stmt, 1, dbname8, strlen(dbname8), SQLITE_TRANSIENT);
delete [] dbname8;
if (rc == SQLITE_OK) {
SendMessage(hCLIResultWnd, EM_SETSEL, 0, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)TEXT("\n"));
SendMessage(hCLIResultWnd, EM_SETSEL, 0, 0);
SendMessage(hCLIResultWnd, EM_REPLACESEL, 0, (LPARAM)sql16);
SetWindowText(hCLIEditorWnd, 0);

char* sql8 = utils::utf16to8(sql16);
sqlite3_bind_text(stmt, 2, sql8, strlen(sql8), SQLITE_TRANSIENT);
delete [] sql8;
if(SQLITE_OK == sqlite3_prepare_v2(db, "insert into preferences.cli (time, dbname, query, elapsed, result) values (strftime('%s', 'now'), ?1, ?2, ?3, ?4)", -1, &stmt, 0)) {
char* dbname8 = utils::getFileName(sqlite3_db_filename(db, 0));
sqlite3_bind_text(stmt, 1, dbname8, strlen(dbname8), SQLITE_TRANSIENT);
delete [] dbname8;

sqlite3_bind_int(stmt, 3, elapsed);
char* sql8 = utils::utf16to8(sql16);
sqlite3_bind_text(stmt, 2, sql8, strlen(sql8), SQLITE_TRANSIENT);
delete [] sql8;

char* result8 = utils::utf16to8(result16);
sqlite3_bind_text(stmt, 4, result8, strlen(result8), SQLITE_TRANSIENT);
delete [] result8;
sqlite3_bind_int(stmt, 3, elapsed);

if (SQLITE_DONE != sqlite3_step(stmt))
showDbError(hMainWnd);
char* result8 = utils::utf16to8(result16);
sqlite3_bind_text(stmt, 4, result8, strlen(result8), SQLITE_TRANSIENT);
delete [] result8;

if (SQLITE_DONE != sqlite3_step(stmt))
showDbError(hMainWnd);
}
sqlite3_finalize(stmt);
}
sqlite3_finalize(stmt);
}

delete [] sql8;
Expand All @@ -1462,6 +1501,7 @@ int executeCLIQuery(bool isPlan) {
SetWindowLong(hCLIEditorWnd, GWL_USERDATA, 0);

enableMainMenu();
updateTransactionState();
return 1;
}

Expand Down Expand Up @@ -1692,11 +1732,17 @@ void suggestCLIQuery(int key) {
sqlite3_stmt *stmt;
char* dbname8 = utils::getFileName(sqlite3_db_filename(db, 0));

int size = GetWindowTextLength(hCLIEditorWnd);
TCHAR sql16[size + 1] = {0};
GetWindowText(hCLIEditorWnd, sql16, size + 1);
char *sql8 = utils::utf16to8(sql16);

int rc = SQLITE_OK == sqlite3_prepare_v2(db,
key == VK_UP ? "select time, query from preferences.cli where dbname = ?1 and time < coalesce(?2, time + 1) order by time desc limit 1" :
key == VK_DOWN ? "select time, query from preferences.cli where dbname = ?1 and time > coalesce(?2, time - 1) order by time asc limit 1" :
key == VK_TAB ? "select time, query from preferences.cli where dbname = ?1 and query like '%' || ?2 || '%' limit 1" : "", -1, &stmt, 0);
key == VK_UP ? "select time, query from preferences.cli where dbname = ?1 and time < coalesce(?2, time + 1) and query <> ?3 order by time desc limit 1" :
key == VK_DOWN ? "select time, query from preferences.cli where dbname = ?1 and time > coalesce(?2, time - 1) and query <> ?3 order by time asc limit 1" :
key == VK_TAB ? "select time, query from preferences.cli where dbname = ?1 and query like '%' || ?2 || '%' and query <> ?3 limit 1" : "", -1, &stmt, 0);
sqlite3_bind_text(stmt, 1, dbname8, strlen(dbname8), SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, sql8, strlen(sql8), SQLITE_TRANSIENT);

if (rc && (key == VK_UP || key == VK_DOWN)) {
int time = GetWindowLong(hCLIEditorWnd, GWL_USERDATA);
Expand Down Expand Up @@ -1731,6 +1777,7 @@ void suggestCLIQuery(int key) {

sqlite3_finalize(stmt);
delete [] dbname8;
delete [] sql8;
}

void openDb(const TCHAR* path) {
Expand Down Expand Up @@ -2026,9 +2073,6 @@ void enableMainMenu() {
for (int i = 0; i < GetMenuItemCount(hMenu); i++)
EnableMenuItem(hMenu, i, MF_BYPOSITION | MF_ENABLED);

hMenu = GetSubMenu(hMainMenu, 2);
EnableMenuItem(hMenu, IDM_GENERATE_DATA, isQueryValid("select rownum(1) from generate_series(1,1,1)") ? MF_BYCOMMAND | MF_ENABLED : MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);

setToolbarButtonState(IDM_CLOSE, TBSTATE_ENABLED);
setToolbarButtonState(IDM_PLAN, TBSTATE_ENABLED);
setToolbarButtonState(IDM_EXECUTE, TBSTATE_ENABLED);
Expand Down
1 change: 1 addition & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#define IDC_DLG_ISUNIQUE 144
#define IDC_DLG_ISNOTNULL 145
#define IDC_DLG_EXAMPLE 146
#define IDC_DLG_CLI_ROW_LIMIT 147

#define IDC_DLG_ROW_ADD 150
#define IDC_DLG_ROW_DEL 151
Expand Down
Loading

0 comments on commit 22c4485

Please sign in to comment.