Simple database: Difference between revisions
Content added Content deleted
m (→{{header|C}}: Nevermind, undo last correction. I'm tired, and it works.) |
|||
Line 1,474: | Line 1,474: | ||
{"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}}== |
|||
<lang runbasic>clientDb$ = "f:\client.db" |
|||
sqliteconnect #sql, clientDb$ ' Connect to the DB |
|||
' -------------------------------------------------------- |
|||
' Create Table structure for: client 4 fields |
|||
' -------------------------------------------------------- |
|||
sql$ = " |
|||
CREATE TABLE client ( |
|||
clientNum INT(5) NULL, |
|||
name VARCHAR(30) NULL, |
|||
clientDate DATETIME NULL, |
|||
category VARCHAR(10) NULL)" |
|||
#sql execute(sql$) |
|||
' -------------------------------------------------------- |
|||
' Make 5 records for client |
|||
' -------------------------------------------------------- |
|||
sql$ = " |
|||
INSERT INTO client VALUES ('1','Home Sales','2012-01-01 10;20','broker'); |
|||
INSERT INTO client VALUES ('2','Best Foods','2011-02-02 12;33','food'); |
|||
INSERT INTO client VALUES ('3','Floral Designs','2010-10-14 09:16','flowers'); |
|||
INSERT INTO client VALUES ('4','Back 40 Equipment','2009-09-18 20:18','farm'); |
|||
INSERT INTO client VALUES ('5','Dawnridge Winery','2008-06-18 22;16','wine');" |
|||
#sql execute(sql$) |
|||
[sho] |
|||
' ------------------------------------ |
|||
' Select last entry |
|||
' ------------------------------------ |
|||
sql$ = "SELECT *,client.rowid as rowid FROM client ORDER BY rowid desc LIMIT 1" |
|||
print "---- Last Entry ----" |
|||
gosub [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by category |
|||
' ------------------------------------ |
|||
sql$ = "SELECT * FROM client ORDER BY category" |
|||
print "---- category Sequence ----" |
|||
gosub [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by name |
|||
' ------------------------------------ |
|||
sql$ = "SELECT * FROM client ORDER BY name" |
|||
print "---- Name Sequence ----" |
|||
gosub [shoQuery] |
|||
' ------------------------------------ |
|||
' Select by date |
|||
' ------------------------------------ |
|||
sql$ = "SELECT * FROM client ORDER BY clientDate" |
|||
print "---- Last Entry ----" |
|||
gosub [shoQuery] |
|||
end |
|||
[shoQuery] |
|||
html "TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>" |
|||
html "<TR align=center>" |
|||
html "<TD>Client<br>Num</TD>" |
|||
html "<TD>Name</TD>" |
|||
html "<TD>Client<br>Date</TD>" |
|||
html "<TD>Category</TD>" |
|||
html "</TR>" |
|||
#sql execute(sql$) |
|||
WHILE #sql hasanswer() |
|||
#row = #sql #nextrow() |
|||
clientNum = #row clientNum() |
|||
name$ = #row name$() |
|||
clientDate$ = #row clientDate$() |
|||
category$ = #row category$() |
|||
rowid$ = #row rowid$() |
|||
html "</TD>" |
|||
html "<TD align=right>";clientNum;"</TD>" |
|||
html "<TD>";name$;"</TD>" |
|||
html "<TD>";clientDate$;"</TD>" |
|||
html "<TD>";category$;"</TD>" |
|||
html "</TR>" |
|||
WEND |
|||
html "</TABLE>" |
|||
RETURN</lang> |
|||
Output: |
|||
---- Last Entry ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center><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> |
|||
---- category Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center><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> |
|||
---- Name Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center><TD>Client<br>Num</TD><TD>Name</TD><TD>Client<br>Date</TD><TD>Category</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>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> |
|||
<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>1</TD><TD>Home Sales</TD><TD>2012-01-01 10;20</TD><TD>broker</TD></TR></TABLE> |
|||
---- Date Sequence ----<br /> |
|||
<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> |
|||
<TR align=center><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|Tcl}}== |
=={{header|Tcl}}== |