File: databasefoo.kbs

package info (click to toggle)
basic256 0.9.6.69a-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,304 kB
  • sloc: cpp: 7,778; yacc: 926; lex: 575; sh: 21; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#database foo - create a database, populate a table, open a recordset and read data from table.

# create a new database file or open it
dbopen "dbtest.sqlite3"

# delete old foo table - trap error if new database
onerror errortrap
dbexecute "drop table foo;"
offerror
# create and populate
dbexecute "create table foo (id integer, words text, value decimal);"
dbexecute "insert into foo values (1,'one',3.14);"
dbexecute "insert into foo values (2,'two',6.28);"
dbexecute "insert into foo values (3,'three',9.43);"

# open a recordset and loop through the rows of data
dbopenset "select * from foo order by words;"
while dbrow()
	print dbint(0) + dbstring(1) + dbfloat(2)
end while
dbcloseset

# wrap everything up
dbclose
end

errortrap:
# accept error - display nothing - return to next statement
return