record – Integer Auto Increment
category CHAR (2)
cmd CHAR (50)
syntax CHAR (2000)
For the query I have tried,
Code: Select all
result = DatabaseUpdate(#dbaseID, "INSERT INTO command (category, cmd, syntax) VALUES ('"+ dbcat + "','"+ dbcmd +"', '"+ dbsyntax + "')")
Code: Select all
result = DatabaseUpdate(#dbaseID, "INSERT INTO command (category, cmd, syntax) VALUES (?, ?, ?);")
Here is my code:
Code: Select all
;-------------------------------------------------------
; Add Data to PB Manual Database
;-------------------------------------------------------
UseSQLiteDatabase()
;------------[ Enumeration ]------------
Enumeration
#mainWindow
#dbaseID
;----[ Buttons ]----
#submitBT
;----[ Header & Footer ]----
#header
#footer
;----[ Fonts ]----
#headerFont
#footerFont
;----[ Labels ]----
#categoryLBL
#commandLBL
#syntaxLBL
;----[ Gadgets ]----
#categoryFLD
#commandFLD
#syntaxFLD
EndEnumeration
;--------[ Global Variables ]---------
Global dbcat.s
Global dbcmd.s
Global dbsyntax.s
;--------[ Load Fonts ]---------
LoadFont(#headerFont, "Arial", 10)
LoadFont(#footerFont, "Arial", 9)
Procedure setupMainScreen()
;------------[ Header ]------------
TextGadget(#header, 0, 0, 780, 40, header$, #SS_CENTERIMAGE)
SetGadgetFont(#header, FontID(#headerFont))
SetGadgetColor(#header, #PB_Gadget_BackColor, RGB(4,43,97))
SetGadgetColor(#header, #PB_Gadget_FrontColor, RGB(124,173,221))
;------------[ Footer ]------------
TextGadget(#footer, 0, 478, 780, 20, footer$, #SS_CENTERIMAGE)
SetGadgetFont(#footer, FontID(#footerFont))
SetGadgetColor(#footer, #PB_Gadget_BackColor, RGB(4,43,97))
SetGadgetColor(#footer, #PB_Gadget_FrontColor, RGB(124,173,221))
TextGadget(#categoryLBL, 205, 100, 55, 20, "Category: ")
SetGadgetColor(#categoryLBL, #PB_Gadget_BackColor, RGB(245,245,245))
TextGadget(#commandLBL, 200, 160, 55, 20, "Command: ")
SetGadgetColor(#commandLBL, #PB_Gadget_BackColor, RGB(245,245,245))
TextGadget(#syntaxLBL, 200, 220, 55, 20, "Syntax: ")
SetGadgetColor(#syntaxLBL, #PB_Gadget_BackColor, RGB(245,245,245))
StringGadget(#categoryFLD, 260, 97, 100, 20, "", #PB_Text_Border)
SetGadgetColor(#categoryFLD, #PB_Gadget_BackColor, RGB(235,235,235))
StringGadget(#commandFLD, 260, 158, 250, 20, "", #PB_Text_Border)
SetGadgetColor(#commandFLD, #PB_Gadget_BackColor, RGB(235,235,235))
EditorGadget(#syntaxFLD, 260, 217, 450, 200, #PB_Editor_WordWrap)
SetGadgetColor(#syntaxFLD, #PB_Gadget_BackColor, RGB(235,235,235))
ButtonGadget(#submitBT, 260, 430, 110, 20, "Submit")
SetActiveGadget(#categoryFLD)
EndProcedure
Procedure saveData()
dbcat = GetGadgetText(#categoryFLD)
dbcmd = GetGadgetText(#commandFLD)
dbsyntax = GetGadgetText(#syntaxFLD)
result = DatabaseUpdate(#dbaseID, "INSERT INTO command (category, cmd, syntax) VALUES ('"+ dbcat + "','"+ dbcmd +"', '"+ dbsyntax + "')")
;result = DatabaseUpdate(#dbaseID, "INSERT INTO command (category, cmd, syntax) VALUES (?, ?, ?);")
If result = 0
MessageRequester("Error","Could not save data!")
EndIf
FinishDatabaseQuery(#dbaseID) ;Disconnects from database but does not close it.
EndProcedure
Procedure clearGadgets()
SetGadgetText(#categoryFLD, "")
SetGadgetText(#commandFLD, "")
SetGadgetText(#syntaxFLD, "")
EndProcedure
;-------------------[ Open the database & Main Window ]--------------------
If OpenDatabase(#dbaseID, "manual.db", "", "") ;Open the database
wFlags = #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget |#PB_Window_ScreenCentered ;Window flags
OpenWindow(#mainWindow, 0, 0, 780, 498, "", wFlags)
SetWindowColor(#mainWindow, RGB(245,245,245))
setupMainScreen()
;--------[ Wait for window event ]--------
Repeat
Select WaitWindowEvent() ;Wait for an event
Case #PB_Event_CloseWindow ;Close window if "X" is clicked.
run = 1 ;Set run flag to 1
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget ;Check for gadget event
Select EventGadget()
;--------[ Buttons ]--------
Case #submitBT
saveData()
clearGadgets()
EndSelect
EndSelect
Until run = 1 ;If run = 1 close the program
CloseDatabase(#dbaseID) ;close the database.
EndIf