Simple database: Difference between revisions
Content added Content deleted
(Dialects of BASIC moved to the BASIC section.) |
|||
Line 123: | Line 123: | ||
{{out}} |
{{out}} |
||
The same as in Kotlin. |
The same as in Kotlin. |
||
=={{header|BASIC}}== |
|||
==={{header|Run BASIC}}=== |
|||
<syntaxhighlight lang="runbasic">sqliteconnect #sql, "f:\client.db" ' Connect to the DB |
|||
' ------------------------------- |
|||
' show user options |
|||
' ------------------------------- |
|||
[sho] |
|||
cls ' clear screen |
|||
button #acd, "Add a new entry", [add] |
|||
button #acd, "Print the latest entry", [last] |
|||
button #acd, "Print the latest entry for each category", [lastCat] |
|||
button #acd, "Print all entries sorted by a date", [date] |
|||
button #ex, "Exit", [exit] |
|||
wait |
|||
' ------------------------------------ |
|||
' add a new entry (user input screen) |
|||
' ------------------------------------ |
|||
[add] |
|||
cls ' clear the screen |
|||
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 bgcolor=wheat>" |
|||
html "<TR align=center BGCOLOR=tan><TD colspan=2>Client Maintenance</TD></TR><TR>" |
|||
html "<TD bgcolor=tan align=right>Client Num</TD><TD>" |
|||
textbox #clientNum,clientNum$,5 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Name</TD><TD>" |
|||
textbox #name,name$,30 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Client Date</TD><TD>" |
|||
textbox #clientDate,clientDate$,19 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Category</TD><TD>" |
|||
textbox #category,category$,10 |
|||
html "</TD></TR><TR><TR bgcolor=tan><TD colspan=2 ALIGN=CENTER>" |
|||
button #acd, "Add", [addIt] |
|||
button #ex, "Exit", [sho] |
|||
html "</TD></TR></TABLE>" |
|||
wait |
|||
' --------------------------------------------- |
|||
' Get data from the screen |
|||
' --------------------------------------------- |
|||
[addIt] |
|||
clientNum = #clientNum contents$() |
|||
name$ = trim$(#name contents$()) |
|||
clientDate$ = trim$(#clientDate contents$()) |
|||
category$ = trim$(#category contents$()) |
|||
dbVals$ = clientNum;",'";name$;"','";clientDate$;"','";category$;"'" |
|||
sql$ = "INSERT into client VALUES ("; dbVals$ ; ")" |
|||
#sql execute(sql$) |
|||
goto [sho] |
|||
' ------------------------------------ |
|||
' Select last entry |
|||
' ------------------------------------ |
|||
[last] |
|||
sql$ = "SELECT *,client.rowid as rowid FROM client ORDER BY rowid desc LIMIT 1" |
|||
what$ = "---- Last Entry ----" |
|||
goto [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by category (Last date only) |
|||
' ------------------------------------ |
|||
[lastCat] |
|||
sql$ = "SELECT * FROM client |
|||
WHERE client.clientDate = (SELECT max(c.clientDate) |
|||
FROM client as c WHERE c.category = client.category) |
|||
ORDER BY category" |
|||
what$ = "---- Last Category Sequence ----" |
|||
goto [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by date |
|||
' ------------------------------------ |
|||
[date] |
|||
sql$ = "SELECT * FROM client ORDER BY clientDate" |
|||
what$ = "---- By Date ----" |
|||
[shoQuery] |
|||
cls |
|||
print what$ |
|||
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>" |
|||
html "<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR>" ' heading |
|||
#sql execute(sql$) |
|||
WHILE #sql hasanswer() |
|||
#row = #sql #nextrow() |
|||
clientNum = #row clientNum() |
|||
name$ = #row name$() |
|||
clientDate$ = #row clientDate$() |
|||
category$ = #row category$() |
|||
html "<TR><TD align=right>";clientNum;"</TD><TD>";name$;"</TD><TD>";clientDate$;"</TD><TD>";category$;"</TD></TR>" |
|||
WEND |
|||
html "</TABLE>" |
|||
button #c, "Continue", [sho] |
|||
wait |
|||
' ------ the end ------- |
|||
[exit] |
|||
end</syntaxhighlight> |
|||
Output: |
|||
---- User Input ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 bgcolor=wheat> |
|||
<TR align=center BGCOLOR=tan><TD colspan=2>Client Maintenance</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Client Num</TD><TD>5</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Name</TD><TD>Dawnridge Winery</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Client Date</TD><TD>2008-06-18 22:16</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Category</TD><TD>wine</TD></TR> |
|||
<TR><TR bgcolor=tan><TD colspan=2 ALIGN=CENTER>[Add] [Exit]</TD></TR></TABLE> |
|||
---- Last Entry ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22:16</TD><TD>wine</TD></TR></TABLE> |
|||
---- Last category Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>1</TD><TD>Home Sales</TD><TD>2012-01-01 10;20</TD><TD>broker</TD></TR> |
|||
<TR><TD align=right>4</TD><TD>Back 40 Equipment</TD><TD>2009-09-18 20:18</TD><TD>farm</TD></TR> |
|||
<TR><TD align=right>3</TD><TD>Floral Designs</TD><TD>2010-10-14 09:16</TD><TD>flowers</TD></TR> |
|||
<TR><TD align=right>2</TD><TD>Best Foods</TD><TD>2011-02-02 12:33</TD><TD>food</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22:16</TD><TD>wine</TD></TR></TABLE> |
|||
---- Date Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22;16</TD><TD>wine</TD></TR> |
|||
<TR><TD align=right>4</TD><TD>Back 40 Equipment</TD><TD>2009-09-18 20:18</TD><TD>farm</TD></TR> |
|||
<TR><TD align=right>3</TD><TD>Floral Designs</TD><TD>2010-10-14 09:16</TD><TD>flowers</TD></TR> |
|||
<TR><TD align=right>2</TD><TD>Best Foods</TD><TD>2011-02-02 12:33</TD><TD>food</TD></TR> |
|||
<TR><TD align=right>1</TD><TD>Home Sales</TD><TD>2012-01-01 10:20</TD><TD>broker</TD></TR></TABLE> |
|||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
Line 4,623: | Line 4,759: | ||
{"fields":["event_title","start_time","stop_time","location","event_description"],"items":{"6dd02195-1efe-40d1-b43e-c2efd852cd1d":{"event_title":"Wife's Birthday","start_time":"2011-11-01","stop_time":"2011-11-01","location":"","event_description":"happy 39th"},"0190b835-401d-42da-9ed3-1d335d27b83c":{"event_title":"Parent-Teacher Conference","start_time":"2011-11-03 19:30","stop_time":"2011-11-03 20:00","location":"school","event_description":"desc"},"4023e6f1-bcc1-49e5-a59f-138157b413f4":{"event_title":"Buy gift for wife","start_time":"2011-10-31 16:00","stop_time":"2011-10-31 16:30","location":"the mall","event_description":"hmm, maybe jewelery?"}},"history":[[1320349951.000625,"6dd02195-1efe-40d1-b43e-c2efd852cd1d"],[1320350045.4736252,"0190b835-401d-42da-9ed3-1d335d27b83c"],[1320350102.9486248,"4023e6f1-bcc1-49e5-a59f-138157b413f4"]],"tags":{"birthday":["6dd02195-1efe-40d1-b43e-c2efd852cd1d"],"family":["6dd02195-1efe-40d1-b43e-c2efd852cd1d","0190b835-401d-42da-9ed3-1d335d27b83c","4023e6f1-bcc1-49e5-a59f-138157b413f4"],"school":["0190b835-401d-42da-9ed3-1d335d27b83c"],"last-minute":["4023e6f1-bcc1-49e5-a59f-138157b413f4"]}} |
{"fields":["event_title","start_time","stop_time","location","event_description"],"items":{"6dd02195-1efe-40d1-b43e-c2efd852cd1d":{"event_title":"Wife's Birthday","start_time":"2011-11-01","stop_time":"2011-11-01","location":"","event_description":"happy 39th"},"0190b835-401d-42da-9ed3-1d335d27b83c":{"event_title":"Parent-Teacher Conference","start_time":"2011-11-03 19:30","stop_time":"2011-11-03 20:00","location":"school","event_description":"desc"},"4023e6f1-bcc1-49e5-a59f-138157b413f4":{"event_title":"Buy gift for wife","start_time":"2011-10-31 16:00","stop_time":"2011-10-31 16:30","location":"the mall","event_description":"hmm, maybe jewelery?"}},"history":[[1320349951.000625,"6dd02195-1efe-40d1-b43e-c2efd852cd1d"],[1320350045.4736252,"0190b835-401d-42da-9ed3-1d335d27b83c"],[1320350102.9486248,"4023e6f1-bcc1-49e5-a59f-138157b413f4"]],"tags":{"birthday":["6dd02195-1efe-40d1-b43e-c2efd852cd1d"],"family":["6dd02195-1efe-40d1-b43e-c2efd852cd1d","0190b835-401d-42da-9ed3-1d335d27b83c","4023e6f1-bcc1-49e5-a59f-138157b413f4"],"school":["0190b835-401d-42da-9ed3-1d335d27b83c"],"last-minute":["4023e6f1-bcc1-49e5-a59f-138157b413f4"]}} |
||
</pre> |
</pre> |
||
=={{header|Run BASIC}}== |
|||
<syntaxhighlight lang="runbasic">sqliteconnect #sql, "f:\client.db" ' Connect to the DB |
|||
' ------------------------------- |
|||
' show user options |
|||
' ------------------------------- |
|||
[sho] |
|||
cls ' clear screen |
|||
button #acd, "Add a new entry", [add] |
|||
button #acd, "Print the latest entry", [last] |
|||
button #acd, "Print the latest entry for each category", [lastCat] |
|||
button #acd, "Print all entries sorted by a date", [date] |
|||
button #ex, "Exit", [exit] |
|||
wait |
|||
' ------------------------------------ |
|||
' add a new entry (user input screen) |
|||
' ------------------------------------ |
|||
[add] |
|||
cls ' clear the screen |
|||
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 bgcolor=wheat>" |
|||
html "<TR align=center BGCOLOR=tan><TD colspan=2>Client Maintenance</TD></TR><TR>" |
|||
html "<TD bgcolor=tan align=right>Client Num</TD><TD>" |
|||
textbox #clientNum,clientNum$,5 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Name</TD><TD>" |
|||
textbox #name,name$,30 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Client Date</TD><TD>" |
|||
textbox #clientDate,clientDate$,19 |
|||
html "</TD></TR><TR><TD bgcolor=tan align=right>Category</TD><TD>" |
|||
textbox #category,category$,10 |
|||
html "</TD></TR><TR><TR bgcolor=tan><TD colspan=2 ALIGN=CENTER>" |
|||
button #acd, "Add", [addIt] |
|||
button #ex, "Exit", [sho] |
|||
html "</TD></TR></TABLE>" |
|||
wait |
|||
' --------------------------------------------- |
|||
' Get data from the screen |
|||
' --------------------------------------------- |
|||
[addIt] |
|||
clientNum = #clientNum contents$() |
|||
name$ = trim$(#name contents$()) |
|||
clientDate$ = trim$(#clientDate contents$()) |
|||
category$ = trim$(#category contents$()) |
|||
dbVals$ = clientNum;",'";name$;"','";clientDate$;"','";category$;"'" |
|||
sql$ = "INSERT into client VALUES ("; dbVals$ ; ")" |
|||
#sql execute(sql$) |
|||
goto [sho] |
|||
' ------------------------------------ |
|||
' Select last entry |
|||
' ------------------------------------ |
|||
[last] |
|||
sql$ = "SELECT *,client.rowid as rowid FROM client ORDER BY rowid desc LIMIT 1" |
|||
what$ = "---- Last Entry ----" |
|||
goto [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by category (Last date only) |
|||
' ------------------------------------ |
|||
[lastCat] |
|||
sql$ = "SELECT * FROM client |
|||
WHERE client.clientDate = (SELECT max(c.clientDate) |
|||
FROM client as c WHERE c.category = client.category) |
|||
ORDER BY category" |
|||
what$ = "---- Last Category Sequence ----" |
|||
goto [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by date |
|||
' ------------------------------------ |
|||
[date] |
|||
sql$ = "SELECT * FROM client ORDER BY clientDate" |
|||
what$ = "---- By Date ----" |
|||
[shoQuery] |
|||
cls |
|||
print what$ |
|||
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>" |
|||
html "<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR>" ' heading |
|||
#sql execute(sql$) |
|||
WHILE #sql hasanswer() |
|||
#row = #sql #nextrow() |
|||
clientNum = #row clientNum() |
|||
name$ = #row name$() |
|||
clientDate$ = #row clientDate$() |
|||
category$ = #row category$() |
|||
html "<TR><TD align=right>";clientNum;"</TD><TD>";name$;"</TD><TD>";clientDate$;"</TD><TD>";category$;"</TD></TR>" |
|||
WEND |
|||
html "</TABLE>" |
|||
button #c, "Continue", [sho] |
|||
wait |
|||
' ------ the end ------- |
|||
[exit] |
|||
end</syntaxhighlight> |
|||
Output: |
|||
---- User Input ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 bgcolor=wheat> |
|||
<TR align=center BGCOLOR=tan><TD colspan=2>Client Maintenance</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Client Num</TD><TD>5</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Name</TD><TD>Dawnridge Winery</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Client Date</TD><TD>2008-06-18 22:16</TD></TR> |
|||
<TR><TD bgcolor=tan align=right>Category</TD><TD>wine</TD></TR> |
|||
<TR><TR bgcolor=tan><TD colspan=2 ALIGN=CENTER>[Add] [Exit]</TD></TR></TABLE> |
|||
---- Last Entry ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22:16</TD><TD>wine</TD></TR></TABLE> |
|||
---- Last category Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>1</TD><TD>Home Sales</TD><TD>2012-01-01 10;20</TD><TD>broker</TD></TR> |
|||
<TR><TD align=right>4</TD><TD>Back 40 Equipment</TD><TD>2009-09-18 20:18</TD><TD>farm</TD></TR> |
|||
<TR><TD align=right>3</TD><TD>Floral Designs</TD><TD>2010-10-14 09:16</TD><TD>flowers</TD></TR> |
|||
<TR><TD align=right>2</TD><TD>Best Foods</TD><TD>2011-02-02 12:33</TD><TD>food</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22:16</TD><TD>wine</TD></TR></TABLE> |
|||
---- Date Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center bgcolor=wheat><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</TD></TR> |
|||
<TR><TD align=right>5</TD><TD>Dawnridge Winery</TD><TD>2008-06-18 22;16</TD><TD>wine</TD></TR> |
|||
<TR><TD align=right>4</TD><TD>Back 40 Equipment</TD><TD>2009-09-18 20:18</TD><TD>farm</TD></TR> |
|||
<TR><TD align=right>3</TD><TD>Floral Designs</TD><TD>2010-10-14 09:16</TD><TD>flowers</TD></TR> |
|||
<TR><TD align=right>2</TD><TD>Best Foods</TD><TD>2011-02-02 12:33</TD><TD>food</TD></TR> |
|||
<TR><TD align=right>1</TD><TD>Home Sales</TD><TD>2012-01-01 10:20</TD><TD>broker</TD></TR></TABLE> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |