-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pb
More file actions
74 lines (64 loc) · 1.91 KB
/
main.pb
File metadata and controls
74 lines (64 loc) · 1.91 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
; ----------------------------------------------------
; AUTHOR : microdevWeb
; MODULE : sqlite
; EXAMPLE :
; ----------------------------------------------------
XIncludeFile "include/sqlite.pbi"
EnableExplicit
Macro sqlError()
MessageRequester("SQL ERROR",req+Chr(10)+db\getError(),#PB_MessageRequester_Error)
End
EndMacro
sqlite::FILE_PATH = "data"
sqlite::FILE_NAME = "myDase.db"
sqlite::LOG_PATH = "log"
sqlite::LOG_NAME = "sqll.log"
Procedure createDatabase()
Protected db.sqlite::obj = sqlite::new(),
req.s = "CREATE TABLE IF NOT EXISTS person ("+
"id INTEGER PRIMARY KEY AUTOINCREMENT,"+
"name TEXT,"+
"age INTEGER)"
If Not db\open():sqlError():EndIf
If Not db\update(req):sqlError():EndIf
db\close()
EndProcedure
Procedure fillDatabase()
Protected db.sqlite::obj = sqlite::new(),
req.s = "INSERT INTO person (name,age) VALUES (?,?)",
name.s,age.s
If Not db\open():sqlError():EndIf
Restore D_NAME
Repeat
Read.s name
If name = "-1":Break:EndIf
Read.s age
db\setString(0,name)
db\setLong(1,Val(age))
If Not db\update(req):sqlError():EndIf
ForEver
db\close()
EndProcedure
Procedure readDatabase()
Protected db.sqlite::obj = sqlite::new(),
req.s = "SELECT * FROM person"
If Not db\open():sqlError():EndIf
If Not db\query(req):sqlError():EndIf
While db\nextRow()
Debug db\getString(db\getIdColumn("name"))+" : "+Str(db\getLong(db\getIdColumn("age")))
Wend
db\close()
EndProcedure
createDatabase()
fillDatabase()
readDatabase()
; for make some records into db
DataSection
D_NAME:
Data.s "Pierre","54","Jacque","18","Olivier","30","Marcel","34","Jhon","47","George","64","Philippes","28","Fred","84","Alain","16","-1"
EndDataSection
; IDE Options = PureBasic 5.72 LTS Beta 1 (Windows - x64)
; CursorPosition = 21
; FirstLine = 3
; Folding = -
; EnableXP