'This is a simple example on using SQL with RB.
'You can add records, delete, and edit existing data.
'I created this for personal use and decided to share.
'Will update as I progress.
'Some code taken from the SQL example on this wiki
 
[start]
kbname$="Knowledge base"
html"<h1>";kbname$;"</h1>"
 
cssclass "table", "{ width: 600px; border: 3px ridge #CCF ; border-spacing: 3px }"
cssclass "tr", "{ background: #CCF }"
 
 
dbName$="kbtest1.db"
files #a,dbName$
 
exists= #a hasAnswer()
if exists then
    sqliteconnect #mySQLdb, dbName$
      action$ = "select * from mykb1 ;"
      #mySQLdb execute(action$)
      if #mySQLdb hasanswer() then
       cnames$ = #mySQLdb columnnames$()
    cname$ = trim$(word$(cnames$,6,","))
    #mySQLdb LINK(cname$, "[edit]")
 
      render #mySQLdb
      else
            Print "Please Add Your First Record."
      end if
      #mySQLdb disconnect()
 else
      sqliteconnect #mySQLdb, dbName$
      action$ = "create table mykb1 (Manufacturer char(150), Model char(50),Category char(255),Description char (256),Knowledge char(2000),id integer primary key autoincrement);"
      #mySQLdb execute(action$)
      #mySQLdb disconnect()
end if
print
 
link #delete ,"Delete Record",[delete]
 
html "<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0"" summary=""Subject of table"">"
 
html "<tr>"
html "<th>":print "Manufacturer: ":html "</th>"
html "<th>":print "Model: ":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textbox #manufact, "":html "</th>"
html "<th>":textbox #model, "":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":print "Category: ":html "</th>"
html "<th>":print "Description: ":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textbox #category, "":html "</th>"
html "<th>":textbox #description, "":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":print "Knowledge: ":html "</th>"
html "<th>":print "":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textarea #knowledge, "":html "</th>"
html "<th>":link #save ,"Save",[save]:html"<br>":link #clear ,"Clear",[clear]:html "</th>"
html "</tr>"
html "</table>"
wait
 
 
[edit]
cls
curKey$=EventKey$
 
sqliteconnect #mySQLdb , dbName$
action$ = "select * from mykb1 where id="+EventKey$+" ;"
#mySQLdb execute(action$)
 
 if #mySQLdb hasanswer() then
  temp$=  #mySQLdb nextrow$("~~")
  end if
 #mySQLdb disconnect()
 
 
html "<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0"" summary=""Subject of table"">"
 
html "<tr>"
html "<th>":print "Manufacturer: ":html "</th>"
html "<th>":print "Model: ":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textbox #manufact, trim$(word$(temp$,1,"~~")):html "</th>"
html "<th>":textbox #model, trim$(word$(temp$,2,"~~")):html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":print "Category: ":html "</th>"
html "<th>":print "Description: ":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textbox #category, trim$(word$(temp$,3,"~~")):html "</th>"
html "<th>":textbox #description, trim$(word$(temp$,4,"~~")):html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":print "Knowledge: ":html "</th>"
html "<th>":print "":html "</th>"
html "</tr>"
 
html "<tr>"
html "<th>":textarea #knowledge, trim$(word$(temp$,5,"~~")):html "</th>"
html "<th>":link #save ,"Save",[update]:html " ":link #cancel, "Cancel",[clear]:html "</th>"
html "</tr>"
html "</table>"
wait
 
 
[update]
sqliteconnect #mySQLdb, dbName$
 action$="update mykb1 set Manufacturer='";#manufact contents$();"',Model='";#model contents$();"',Description='";#description contents$();"',Category='";#category contents$();"',Knowledge='";#knowledge contents$();"' where id='";curKey$;"' ;"
 #mySQLdb execute(action$)
 #mySQLdb disconnect()
cls
 
goto [start]
wait
 
[delete]
    print
    input "Enter record ID to delete: ";key
    print " "
    sqliteconnect #mySQLdb, dbName$
    action$="delete from mykb1 where id="+str$(key)+" ;"
 #mySQLdb execute(action$)
    #mySQLdb disconnect()
    cls
    goto [start]
wait
 
 
 
[clear]
cls
goto[start]
wait
 
 
[save]
 sqliteconnect #mySQLdb, dbName$
 
 action$ = "insert into mykb1 (Manufacturer, Model,Category,Description,Knowledge,id) values ('"+#manufact contents$()+"', '"+ #model contents$()+"','"+#category contents$()+"','"+#description contents$()+"','"+#knowledge contents$()+"',NULL);"
 #mySQLdb execute(action$)
 #mySQLdb disconnect()
 cls
 goto [start]
 wait