Skip to content

Commit

Permalink
Up to 1.1.3
Browse files Browse the repository at this point in the history
+ icu extension
* Hide unlinked tables in db diagram
* Improve autocomplete
  • Loading branch information
little-brother committed Sep 6, 2020
1 parent f7a0a25 commit 3a8c511
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 39 deletions.
51 changes: 51 additions & 0 deletions extensions/icu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
lower2(str)
upper2(str)
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
#include <windows.h>

char* transform(const char* in8, boolean isToLower) {
int len8 = strlen(in8) + 1;
char* res8 = malloc(sizeof(char) * len8);
memset(res8, 0, sizeof(char) * len8);

if (len8 > 1) {
int len16 = MultiByteToWideChar(CP_UTF8, 0, in8, -1, NULL, 0);
wchar_t* in16 = malloc(sizeof(wchar_t) * len16);
memset(in16, 0, sizeof(wchar_t) * len16);
MultiByteToWideChar(CP_UTF8, 0, in8, -1, in16, len16);

wchar_t* res16 = isToLower ? _wcslwr(in16) : _wcsupr(in16);

WideCharToMultiByte(CP_UTF8, 0, res16, -1, res8, len8, 0, 0);
free(res16);
}

return res8;
}

static void lower(sqlite3_context *context, int argc, sqlite3_value **argv){
const char* str = sqlite3_value_text(argv[0]);
char* res = (char*)transform(str, TRUE);
sqlite3_result_text(context, res, -1, SQLITE_TRANSIENT);
free(res);
}

static void upper(sqlite3_context *context, int argc, sqlite3_value **argv){
const char* str = sqlite3_value_text(argv[0]);
char* res = (char*)transform(str, FALSE);
sqlite3_result_text(context, res, -1, SQLITE_TRANSIENT);
free(res);
}


__declspec(dllexport) int sqlite3_icu_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) {
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
return sqlite3_create_function(db, "lower2", 1, SQLITE_UTF8, 0, lower, 0, 0) ||
sqlite3_create_function(db, "upper2", 1, SQLITE_UTF8, 0, upper, 0, 0);
}
6 changes: 3 additions & 3 deletions sqlite-gui.depend
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
1562796420 d:\codes\sqlite-gui\sqlite3.h
<stdarg.h>

1599074808 source:d:\codes\sqlite-gui\src\resource.rc
1599403208 source:d:\codes\sqlite-gui\src\resource.rc
<windows.h>
<commctrl.h>
<richedit.h>
Expand All @@ -43,7 +43,7 @@
1583506689 d:\codes\sqlite-gui\src\sqlite3.h
<stdarg.h>

1599074715 source:d:\codes\sqlite-gui\src\main.cpp
1599298392 source:d:\codes\sqlite-gui\src\main.cpp
"global.h"
"missing.h"
"resource.h"
Expand All @@ -67,7 +67,7 @@
<stdio.h>
"utils.h"

1599051949 source:d:\codes\sqlite-gui\src\tools.cpp
1599160642 source:d:\codes\sqlite-gui\src\tools.cpp
"global.h"
"missing.h"
"resource.h"
Expand Down
48 changes: 24 additions & 24 deletions sqlite-gui.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,54 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="src\resource.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\resource.rc" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4731" topLine="109" />
<Cursor1 position="19343" topLine="436" />
</Cursor>
</File>
<File name="ToDo.txt" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\tools.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="157" topLine="0" />
<Cursor1 position="49629" topLine="1330" />
</Cursor>
</File>
<File name="src\resource.rc" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\tools.h" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="19145" topLine="432" />
<Cursor1 position="553" topLine="0" />
</Cursor>
</File>
<File name="src\dialogs.cpp" open="1" top="0" tabpos="5" 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="1569" topLine="48" />
<Cursor1 position="3929" topLine="141" />
</Cursor>
</File>
<File name="src\tools.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\utils.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="35784" topLine="974" />
<Cursor1 position="617" topLine="0" />
</Cursor>
</File>
<File name="src\dialogs.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="ToDo.txt" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="306" topLine="0" />
<Cursor1 position="6074" topLine="63" />
</Cursor>
</File>
<File name="src\tools.h" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="553" topLine="0" />
<Cursor1 position="1569" topLine="48" />
</Cursor>
</File>
<File name="src\global.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1593" topLine="30" />
<Cursor1 position="306" topLine="0" />
</Cursor>
</File>
<File name="src\utils.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\global.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3929" topLine="141" />
<Cursor1 position="1593" topLine="30" />
</Cursor>
</File>
<File name="src\main.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="24499" topLine="610" />
</Cursor>
</File>
<File name="src\utils.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="617" topLine="0" />
<Cursor1 position="59835" topLine="1651" />
</Cursor>
</File>
<File name="src\missing.h" open="0" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand All @@ -72,4 +67,9 @@
<Cursor1 position="645" topLine="0" />
</Cursor>
</File>
<File name="src\resource.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4731" topLine="109" />
</Cursor>
</File>
</CodeBlocks_layout_file>
12 changes: 6 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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.1.2"));
SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)TEXT(" GUI: 1.1.3"));

hTreeWnd = CreateWindowEx(0, WC_TREEVIEW, NULL, WS_VISIBLE | WS_CHILD | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | WS_DISABLED | TVS_EDITLABELS /*| TVS_SHOWSELALWAYS*/, 0, 0, 100, 100, hMainWnd, (HMENU)IDC_TREE, hInstance, NULL);
hEditorWnd = CreateWindowEx(0, TEXT("RICHEDIT50W"), NULL, WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP | ES_NOHIDESEL, 100, 0, 100, 100, hMainWnd, (HMENU)IDC_EDITOR, hInstance, NULL);
Expand Down Expand Up @@ -463,7 +463,6 @@ LRESULT CALLBACK cbMainWindow (HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
if (!SendMessage(hToolbarWnd, TB_ISBUTTONHIDDEN, IDM_INTERRUPT, 0))
return SendMessage(hWnd, WM_COMMAND, IDM_INTERRUPT, 0);


if(prefs::get("exit-by-escape") && !IsWindowVisible(hAutoComplete))
SendMessage(hMainWnd, WM_CLOSE, 0, 0);
}
Expand Down Expand Up @@ -619,7 +618,6 @@ LRESULT CALLBACK cbMainWindow (HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
if (cmd == IDM_EDITOR_DELETE)
SendMessage (hEditorWnd, EM_REPLACESEL, TRUE, 0);


if (cmd == IDM_ABOUT || cmd == IDM_TIPS || cmd == IDM_EXTENSIONS) {
HMENU hMenu = GetSubMenu(hMainMenu, 3);
TCHAR title[255];
Expand All @@ -629,7 +627,6 @@ LRESULT CALLBACK cbMainWindow (HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
MessageBox(hMainWnd, buf, title, MB_OK);
}


if (cmd == IDM_HOMEPAGE)
ShellExecute(0, 0, TEXT("https://github.com/little-brother/sqlite-gui"), 0, 0 , SW_SHOW);

Expand Down Expand Up @@ -1685,7 +1682,6 @@ int setListViewData(HWND hListWnd, sqlite3_stmt *stmt) {
lvi.lParam = rowNo;
ListView_InsertItem(hListWnd, &lvi);


for (int i = 1; i <= colCount; i++) {
bool isNull = sqlite3_column_type(stmt, i - 1) == SQLITE_NULL;
char* name8 = (char *) sqlite3_column_text(stmt, i - 1);
Expand Down Expand Up @@ -2250,7 +2246,11 @@ bool processAutoComplete(HWND hEditorWnd, int key, bool isKeyDown) {
if (start > 6 && !_tcsnicmp(currLine + start - 7, TEXT("pragma "), 7)) {
for (int i = 0; PRAGMAS[i]; i++)
isExact += addString(PRAGMAS[i]);
} else if (start > 4 && (!_tcsnicmp(currLine + start - 5, TEXT("from "), 5) || !_tcsnicmp(currLine + start - 5, TEXT("join "), 5))) {
} else if ((start > 4 && (
!_tcsnicmp(currLine + start - 5, TEXT("from "), 5) ||
!_tcsnicmp(currLine + start - 5, TEXT("join "), 5) ||
!_tcsnicmp(currLine + start - 5, TEXT("into "), 5)
)) || (start > 6 && !_tcsnicmp(currLine + start - 7, TEXT("update "), 7))) {
bool isNoCheck = wLen == 1 && word[0] == TEXT(' ');
for (int i = 0; TABLES[i]; i++)
isExact += addString(TABLES[i], isNoCheck);
Expand Down
13 changes: 8 additions & 5 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "resource.h"

1 VERSIONINFO
FILEVERSION 1, 1, 2, 0
FILEVERSION 1, 1, 3, 0
FILEOS VOS_DOS_WINDOWS32
FILETYPE VFT_APP {
BLOCK "StringFileInfo" {
BLOCK "040904E4" {
VALUE "FileDescription", "SQLite GUI\000"
VALUE "FileVersion", "1.1.2\000"
VALUE "FileVersion", "1.1.3\000"
VALUE "ProductName", "sqlite-gui\000"
VALUE "ProductVersion", "1.1.2\000"
VALUE "ProductVersion", "1.1.3\000"
VALUE "LegalCopyright", "Copyright \251 Little Brother 2020\000"
VALUE "OriginalFilename", "sqlite-gui.exe\000"
}
Expand Down Expand Up @@ -455,10 +455,13 @@ BEGIN
"This extension implements uuid(), uuid_str(X) and uuid_blob(X) functions that handling RFC-4122 UUIDs\n\n" \
"Regexp\n"\
"Implements regexp(regexp, stringToMatch) function and ""B regexp A"" operator. This is a non-POSIX regexp.\n\n" \
"Rownum * \n"\
"* Rownum\n"\
"Add the rownum(start) function that providing row numbers in an query result\n" \
"Example: select rownum(1), t.* from t;\n\n" \
"Exec *\n"\
"* Icu\n"\
"Add lower2(str) and upper2(str) functions with national symbols support\n" \
"select lower2('�'); returns �\n\n"\
"* Exec\n"\
"Add the exec(cmd, maxOutputLength = 32000) function that allowed to execute shell command.\n" \
"Example: select exec('powershell -nologo ""Get-Content data.json""');\n\n"\
"* Custom extensions are available only in sqlite-gui"
Expand Down
30 changes: 29 additions & 1 deletion src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,13 @@ namespace tools {
if (msg == WM_LBUTTONDOWN) {
HWND hParentWnd = GetParent(hWnd);
SetWindowLong(hParentWnd, GWL_USERDATA, (LONG)hWnd);

int tblNo = 0;
while(HWND hTableWnd = GetDlgItem(hParentWnd, IDC_DATABASE_DIAGRAM_TABLE + tblNo)) {
ShowWindow(hTableWnd, hTableWnd == hWnd ? SW_SHOW : SW_HIDE);
tblNo++;
}

InvalidateRect(hParentWnd, NULL, true);
}

Expand Down Expand Up @@ -1128,7 +1135,14 @@ namespace tools {
cursor = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
isMove = wParam == MK_LBUTTON;
SetCapture(hWnd);
SetWindowLong(hWnd, GWL_USERDATA, 0);
if (GetWindowLong(hWnd, GWL_USERDATA)) {
SetWindowLong(hWnd, GWL_USERDATA, 0);
int tblNo = 0;
while(HWND hTableWnd = GetDlgItem(hWnd, IDC_DATABASE_DIAGRAM_TABLE + tblNo)) {
ShowWindow(hTableWnd, SW_SHOW);
tblNo++;
}
}
InvalidateRect(hWnd, NULL, true);
}
break;
Expand Down Expand Up @@ -1224,6 +1238,12 @@ namespace tools {
if ((type == LINK_FK && !isFk) || (type == LINK_VIEW && !isView) || (type == LINK_TRIGGER && !isTrigger))
continue;

if (hCurrWnd && (hCurrWnd != links[i].hWndFrom && hCurrWnd != links[i].hWndTo))
continue;

ShowWindow(links[i].hWndFrom, SW_SHOW);
ShowWindow(links[i].hWndTo, SW_SHOW);

RECT rcA{0}, rcB{0};
GetWindowRect(links[i].hWndFrom, &rcA);
GetWindowRect(links[i].hWndTo, &rcB);
Expand Down Expand Up @@ -1339,6 +1359,14 @@ namespace tools {
if (wParam == IDM_LINK_TRIGGER)
prefs::set("link-trigger", isChecked);

if (GetWindowLong(hWnd, GWL_USERDATA)) {
int tblNo = 0;
while(HWND hTableWnd = GetDlgItem(hWnd, IDC_DATABASE_DIAGRAM_TABLE + tblNo)) {
ShowWindow(hTableWnd, SW_HIDE);
tblNo++;
}
}

InvalidateRect(hWnd, NULL, true);
}

Expand Down

0 comments on commit 3a8c511

Please sign in to comment.