Simple+Database+Log

code format="lb" '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" ";kbname$;" "

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 " " wait

[edit] cls curKey$=EventKey$

sqliteconnect #mySQLdb, dbName$ action$ = "select * from mykb1 where id="+EventKey$+" ;"
 * 1) mySQLdb execute(action$)

if #mySQLdb hasanswer then temp$= #mySQLdb nextrow$("") end if
 * 1) mySQLdb disconnect

html " " 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$;"' ;" cls
 * 1) mySQLdb execute(action$)
 * 2) mySQLdb disconnect

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 disconnect cls goto [start] wait
 * 1) mySQLdb execute(action$)

[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);" cls goto [start] wait code
 * 1) mySQLdb execute(action$)
 * 2) mySQLdb disconnect