Skip to content

Commit 84a9880

Browse files
committed
Initial release
0 parents  commit 84a9880

File tree

5 files changed

+277
-0
lines changed

5 files changed

+277
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Simple-SQLite-Studio
2+
3+
Simple user-interface to administrate SQLite-databases.
4+
5+
![Screenshot](screenshot.png)
6+
7+
## Releases
8+
![Releases](releases/latest)
9+
10+
## License and Copyright
11+
This software is Copyright (c) 2017 by alexgit2k.
12+
13+
This is free software, licensed under MIT License.

icon.ico

5.3 KB
Binary file not shown.

screenshot.png

12.5 KB
Loading

simple-sqlite-studio-window.pbf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; Form Designer for Purebasic - 5.60
2+
; Warning: this file uses a strict syntax, if you edit it, make sure to respect the Form Designer limitation or it won't be opened again.
3+
4+
;
5+
; This code is automatically generated by the FormDesigner.
6+
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
7+
; Event procedures needs to be put in another source file.
8+
;
9+
10+
Global WindowMain
11+
12+
Global Output, ButtonOpen, ButtonExecute, Query
13+
14+
Declare ResizeGadgetsWindowMain()
15+
16+
17+
Procedure OpenWindowMain(x = 0, y = 0, width = 600, height = 400)
18+
WindowMain = OpenWindow(#PB_Any, x, y, width, height, "Simple SQLite Studio", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
19+
Output = ListIconGadget(#PB_Any, 10, 50, 580, 340, "", 0, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
20+
DisableGadget(Output, 1)
21+
ButtonOpen = ButtonGadget(#PB_Any, 10, 10, 50, 25, "Open...")
22+
GadgetToolTip(ButtonOpen, "Open SQLite database")
23+
ButtonExecute = ButtonGadget(#PB_Any, 490, 10, 100, 25, "Execute")
24+
GadgetToolTip(ButtonExecute, "Execute Query")
25+
DisableGadget(ButtonExecute, 1)
26+
Query = ComboBoxGadget(#PB_Any, 70, 10, 410, 25, #PB_ComboBox_Editable)
27+
GadgetToolTip(Query, "Database query")
28+
DisableGadget(Query, 1)
29+
EndProcedure
30+
31+
Procedure ResizeGadgetsWindowMain()
32+
Protected FormWindowWidth, FormWindowHeight
33+
FormWindowWidth = WindowWidth(WindowMain)
34+
FormWindowHeight = WindowHeight(WindowMain)
35+
ResizeGadget(Output, 10, 50, FormWindowWidth - 20, FormWindowHeight - 60)
36+
ResizeGadget(ButtonExecute, FormWindowWidth - 110, 10, 100, 25)
37+
ResizeGadget(Query, 70, 10, FormWindowWidth - 190, 25)
38+
EndProcedure
39+
40+
Procedure WindowMain_Events(event)
41+
Select event
42+
Case #PB_Event_SizeWindow
43+
ResizeGadgetsWindowMain()
44+
Case #PB_Event_CloseWindow
45+
ProcedureReturn #False
46+
47+
Case #PB_Event_Menu
48+
Select EventMenu()
49+
EndSelect
50+
51+
Case #PB_Event_Gadget
52+
Select EventGadget()
53+
EndSelect
54+
EndSelect
55+
ProcedureReturn #True
56+
EndProcedure
57+

simple-sqlite-studio.pb

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
; SQLite Simple Studio
2+
; Alex, 2017/09/02
3+
4+
; Variables
5+
Global db = 0
6+
7+
; Procedures
8+
Declare OpenSQLiteDB(File$ = "")
9+
Declare ExecuteAndShow(handle)
10+
Declare AddToGadgetOnce(Gadget, Text$)
11+
Declare ShowResult(Handle)
12+
Declare Connect(Database$)
13+
Declare Disconnect(Database)
14+
Declare ExecuteQuery(Handle, Query$)
15+
Declare StartWindow(Width, Height, Maximized)
16+
Declare ResizeColumns(Gadget)
17+
Declare MenuShow()
18+
Declare MenuCopySelection()
19+
20+
; GUI
21+
XIncludeFile "simple-sqlite-studio-window.pbf"
22+
23+
; Window
24+
StartWindow(600, 400, 0)
25+
26+
; Wait for event
27+
Repeat
28+
Event = WaitWindowEvent()
29+
If EventWindow() = WindowMain
30+
WindowMain_Events(Event)
31+
EndIf
32+
; Gadgets
33+
If Event = #PB_Event_Gadget And EventType() = #PB_EventType_LeftClick
34+
Select EventGadget()
35+
; Open database
36+
Case ButtonOpen
37+
db = OpenSQLiteDB()
38+
; Execute query
39+
Case ButtonExecute
40+
ExecuteAndShow(db)
41+
EndSelect
42+
EndIf
43+
; Enter in Query-field
44+
If Event = #PB_Event_Menu And EventMenu() = 10000
45+
ExecuteAndShow(db)
46+
EndIf
47+
; Right click in output
48+
If Event = #PB_Event_Gadget And EventType() = #PB_EventType_RightClick
49+
MenuShow()
50+
EndIf
51+
If Event = #PB_Event_Menu And EventMenu() = 1
52+
MenuCopySelection()
53+
EndIf
54+
; Resize columns
55+
If Event = #PB_Event_SizeWindow
56+
ResizeColumns(Output)
57+
EndIf
58+
; Get file
59+
If Event = #PB_Event_WindowDrop
60+
db = OpenSQLiteDB(EventDropFiles())
61+
EndIf
62+
Until Event = #PB_Event_CloseWindow
63+
64+
; Prolog
65+
If db <> 0
66+
Disconnect(db)
67+
EndIf
68+
End
69+
70+
; ------------------------------------------------------------------------------------------------
71+
72+
Procedure OpenSQLiteDB(File$ = "")
73+
; Choose file
74+
If File$ = ""
75+
File$ = OpenFileRequester("Please choose SQLite database", "", "SQLite database (*.db,*.sqlite)|*.db;*.sqlite|All files (*.*)|*.*", 0)
76+
If File$ = ""
77+
ProcedureReturn db ; return old handle
78+
EndIf
79+
EndIf
80+
81+
; Close old database
82+
If db <> 0
83+
Disconnect(db)
84+
EndIf
85+
86+
; Open database
87+
handle = Connect(File$)
88+
If handle = 0
89+
ProcedureReturn 0
90+
EndIf
91+
92+
; Enable gadgets
93+
DisableGadget(Query, 0)
94+
DisableGadget(ButtonExecute, 0)
95+
DisableGadget(Output, 0)
96+
97+
; Initial Query
98+
SetGadgetText(Query,"SELECT name AS tables, sql FROM sqlite_master WHERE type=" + Chr(34) + "table" + Chr(34))
99+
ExecuteAndShow(handle)
100+
101+
ProcedureReturn handle
102+
EndProcedure
103+
104+
Procedure ExecuteAndShow(handle)
105+
If ExecuteQuery(handle,GetGadgetText(Query))
106+
AddToGadgetOnce(Query, GetGadgetText(Query))
107+
ShowResult(handle)
108+
EndIf
109+
EndProcedure
110+
111+
Procedure AddToGadgetOnce(Gadget, Text$)
112+
; Remove double entries
113+
For i=0 To CountGadgetItems(Gadget)-1
114+
If GetGadgetItemText(Gadget,i) = Text$
115+
RemoveGadgetItem(Gadget,i)
116+
EndIf
117+
Next
118+
; Add
119+
AddGadgetItem(Query, 0, Text$)
120+
SetGadgetText(Query, Text$)
121+
EndProcedure
122+
123+
Procedure ShowResult(Handle)
124+
; Get columns
125+
RemoveGadgetColumn(Output,#PB_All)
126+
For i=0 To DatabaseColumns(Handle)-1
127+
AddGadgetColumn(Output, i, DatabaseColumnName(Handle, i), GadgetWidth(Output)/DatabaseColumns(Handle))
128+
Next
129+
130+
; Get result
131+
ClearGadgetItems(Output)
132+
While NextDatabaseRow(Handle)
133+
; Get each column
134+
content$ = GetDatabaseString(Handle,0)
135+
For i=1 To DatabaseColumns(Handle)-1
136+
content$ = content$ + Chr(10) + GetDatabaseString(Handle,i)
137+
Next
138+
AddGadgetItem(Output, -1, content$)
139+
Wend
140+
FinishDatabaseQuery(Handle)
141+
EndProcedure
142+
143+
Procedure Connect(Database$)
144+
UseSQLiteDatabase()
145+
handle = OpenDatabase(#PB_Any, Database$, "", "")
146+
If (handle = 0)
147+
MessageRequester("Error", "Can not open database: " + DatabaseError())
148+
EndIf
149+
ProcedureReturn handle
150+
EndProcedure
151+
152+
Procedure Disconnect(Database)
153+
CloseDatabase(Database)
154+
EndProcedure
155+
156+
Procedure ExecuteQuery(Handle, Query$)
157+
If FindString(Query$,"SELECT ",0,#PB_String_NoCase)=1 Or FindString(Query$,"EXPLAIN ",0,#PB_String_NoCase)=1 Or FindString(Query$,"PRAGMA ",0,#PB_String_NoCase)=1
158+
result=DatabaseQuery(Handle, Query$)
159+
Else
160+
result=DatabaseUpdate(Handle, Query$)
161+
EndIf
162+
If result=0
163+
MessageRequester("Error", "Can not execute: "+DatabaseError())
164+
EndIf
165+
ProcedureReturn result
166+
EndProcedure
167+
168+
Procedure StartWindow(Width, Height, Maximized)
169+
OpenWindowMain(0, 0, Width, Height)
170+
If Maximized = 1
171+
ShowWindow_(WindowID(WindowMain),#SW_MAXIMIZE)
172+
EndIf
173+
ResizeGadgetsWindowMain()
174+
AddKeyboardShortcut(WindowMain, #PB_Shortcut_Return, 10000)
175+
EnableWindowDrop(WindowMain, #PB_Drop_Files, #PB_Drag_Copy)
176+
EndProcedure
177+
178+
Procedure ResizeColumns(Gadget)
179+
For i=0 To GetGadgetAttribute(Gadget,#PB_ListIcon_ColumnCount)-1
180+
SetGadgetItemAttribute(Output, 0, #PB_ListIcon_ColumnWidth, GadgetWidth(Gadget)/GetGadgetAttribute(Gadget,#PB_ListIcon_ColumnCount), i)
181+
Next
182+
EndProcedure
183+
184+
Procedure MenuShow()
185+
If CreatePopupMenu(0)
186+
MenuItem(1, "Copy")
187+
EndIf
188+
DisplayPopupMenu(0, WindowID(WindowMain))
189+
EndProcedure
190+
191+
Procedure MenuCopySelection()
192+
content$ = ""
193+
For i=0 To GetGadgetAttribute(Output,#PB_ListIcon_ColumnCount)-1
194+
content$ = content$ + ", " + GetGadgetItemText(Output,GetGadgetState(Output),i)
195+
Next
196+
SetClipboardText(Trim(Trim(content$,",")))
197+
EndProcedure
198+
199+
; IDE Options = PureBasic 5.60 (Windows - x86)
200+
; CursorPosition = 91
201+
; FirstLine = 57
202+
; Folding = --
203+
; EnableXP
204+
; UseIcon = icon.ico
205+
; Executable = ..\simple-sqlite-studio.exe
206+
; CPU = 1
207+
; DisableDebugger

0 commit comments

Comments
 (0)