Hi,
Maybe works in Linux, too (set #Windows to 0 and try). I hope you find it useful.
Code: Select all
UseSQLiteDatabase()
#Windows = 1
Procedure Error(message$)
CompilerIf #Windows
wError = GetLastError_()
If wError
*ErrorBuffer = AllocateMemory(1024)
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, wError, 0, *ErrorBuffer, 1024, 0)
message$+Chr(10)+PeekS(*ErrorBuffer)
FreeMemory(*ErrorBuffer)
EndIf
CompilerEndIf
MessageRequester("Error", message$)
EndProcedure
Procedure ValH(hs$)
ByteValue = PeekB(@hs$+1)
If ByteValue>'9'
If ByteValue>'F'
ByteValue-87
Else
ByteValue-55
EndIf
Else
ByteValue-48
EndIf
ch = PeekB(@hs$)
If ch>'9'
If ch>'F'
ch-87
Else
ch-55
EndIf
Else
ch-48
EndIf
ByteValue+(ch*16)
ProcedureReturn ByteValue
EndProcedure
#g = 4
#lh = 24
Enumeration
#DBTitle
#DBName
#UserTitle
#UserName
#PwdTitle
#PwdName
#Connect
#Panel
EndEnumeration
If UseODBCDatabase()=0:Error("InitDatabase() failed"):EndIf
NewList tables.s()
NewList coltype()
If OpenWindow(0, 0, 0, 640, (#g*4)+(#lh*2), "DB View", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
WindowID = WindowID(0)
CompilerIf #Windows
SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE)|#WS_CLIPCHILDREN)
CompilerEndIf
StartDrawing(WindowOutput(0))
WDataBase = TextWidth(" DataBase ")
WUser = TextWidth(" User ")
WPassword = TextWidth(" Password ")
WConnect = TextWidth("Reading tables...")
StopDrawing()
SWidth = (WindowWidth(0)-(WDataBase+WUser+WPassword)-(#g*7))/3
TextGadget(#DBTitle, #g, #g, WDataBase, #lh, " DataBase ")
StringGadget(#DBName, (#g*2)+WDataBase, #g, SWidth, #lh, "MyODBC")
TextGadget(#UserTitle, (#g*3)+SWidth+WDataBase, #g, WUser, #lh, " User ")
StringGadget(#UserName, (#g*4)+SWidth+WDataBase+WUser, #g, SWidth, #lh, "root")
TextGadget(#PwdTitle, (#g*5)+(SWidth*2)+WDataBase+WUser, #g, WPassword, #lh, " Password ")
StringGadget(#PwdName, (#g*6)+(SWidth*2)+WDataBase+WUser+WPassword, #g, SWidth, #lh, "")
ButtonGadget(#Connect, #g, (#g*2)+#lh, WConnect, #lh+#g, "Connect")
Connected = 0
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case #Connect
DisableGadget(#Connect, #True)
If Connected
Connected = 0
ResizeWindow(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), (#g*4)+(#lh*2))
HideGadget(#Panel, #True)
ClearGadgetItems(#Panel)
FreeGadget(#Panel)
ClearList(tables())
ClearList(coltype())
SetGadgetText(#Connect, "Connect")
Else
If OpenDatabase(0, GetGadgetText(#DBName), GetGadgetText(#UserName), GetGadgetText(#PwdName))
If DatabaseQuery(0, "SHOW TABLES")
SetGadgetText(#Connect, "Reading tables...")
Connected = 1
ResetList(tables())
While NextDatabaseRow(0)
AddElement(tables())
tables() = GetDatabaseString(0,0)
Wend
PanelHeight = WindowHeight(0)-((#g*5)+(#lh*2))
PanelGadget(#Panel, #g, (#g*4)+(#lh*2), WindowWidth(0), PanelHeight)
ForEach tables()
ResetList(coltype())
If DatabaseQuery(0, "DESCRIBE "+tables())
While NextDatabaseRow(0)
AddElement(coltype())
If GetDatabaseString(0, 1)="longblob"
coltype() = 1
EndIf
Wend
Else
Error("SQL Query error: "+Chr(10)+Chr(10)+"DESCRIBE "+tables()+Chr(10)+Chr(10)+DatabaseError())
EndIf
If DatabaseQuery(0, "SELECT * FROM "+tables())
AddGadgetItem(#Panel, ListIndex(tables()), tables())
ThisGadget = (#Panel+1)+ListIndex(tables())
ListIconGadget(ThisGadget, #g, #g, WindowWidth(0)-(#g*4), PanelHeight-(#g*8), DatabaseColumnName(0, 0), 50, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
cols = DatabaseColumns(0)
For i=2 To cols
AddGadgetColumn(ThisGadget, i-1, DatabaseColumnName(0, i-1), 50)
Next i
While NextDatabaseRow(0)
Row$ = ""
For i=0 To cols-1
Select DatabaseColumnType(0, i)
Case 1
SelectElement(coltype(), i)
If coltype()
BinaryBlob$ = GetDatabaseString(0,i)
lb = Len(BinaryBlob$)
For p=1 To lb Step 2
Row$+Chr(ValH(Mid(BinaryBlob$, p, 2)))
Next p
Row$+Chr(10)
Else
Row$+Str(GetDatabaseLong(0, i))+Chr(10)
EndIf
Case 2
Row$+GetDatabaseString(0, i)+Chr(10)
Case 3
Row$+StrF(GetDatabaseLong(0, i), 2)+Chr(10)
EndSelect
Next i
AddGadgetItem(ThisGadget, -1, Left(Row$, Len(Row$)-1))
Wend
Else
Error("SQL Query error: "+Chr(10)+Chr(10)+"SELECT * FROM "+tables()+Chr(10)+Chr(10)+DatabaseError())
EndIf
Next
CloseDatabase(0)
SetGadgetText(#Connect, "Close view")
ResizeWindow(0, #PB_Ignore,#PB_Ignore,WindowWidth(0), 512)
Else
Error("SQL Query error: "+Chr(10)+Chr(10)+"SHOW TABLES"+Chr(10)+Chr(10)+DatabaseError())
EndIf
Else
Error("Could not connect to DataBase: "+GetGadgetText(3)+Chr(10)+DatabaseError())
EndIf
EndIf
DisableGadget(#Connect, #False)
EndSelect
Case #PB_Event_SizeWindow
If Connected
PanelHeight = WindowHeight(0)-((#g*5)+(#lh*2))
ResizeGadget(#Panel, -1, -1, WindowWidth(0), PanelHeight)
ForEach tables()
ResizeGadget((#Panel+1)+ListIndex(tables()), -1, -1, WindowWidth(0)-(#g*4), PanelHeight-(#g*8))
Next
EndIf
SWidth = (WindowWidth(0)-(WDataBase+WUser+WPassword)-(#g*7))/3
ResizeGadget(#DBName, (#g*2)+WDataBase, -1, -1, -1)
ResizeGadget(#UserTitle, (#g*3)+SWidth+WDataBase, -1, -1, -1)
ResizeGadget(#UserName, (#g*4)+SWidth+WDataBase+WUser, -1, -1, -1)
ResizeGadget(#PwdTitle, (#g*5)+(SWidth*2)+WDataBase+WUser, -1, -1, -1)
ResizeGadget(#PwdName, (#g*6)+(SWidth*2)+WDataBase+WUser+WPassword, -1, -1, -1)
EndSelect
Until EventID=#PB_Event_CloseWindow
EndIf
End