Gambas France BETA


Pas de compte ? Incription

Database

Database



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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
' Gambas class file

PRIVATE $hConn AS Connection

PUBLIC SUB btnConnect_Click()

DIM sName AS STRING

TRY $hConn.Close
'$hConn = NEW Connection

sName = txtName.Text

WITH $hConn
.Type = cmbType.Text
.Host = txtHost.Text
.Port = txtPort.Text
.Login = txtUser.Text
.Password = txtPassword.Text
.Name = ""
END WITH

IF chkCreate.Value THEN

$hConn.Open
IF NOT $hConn.Databases.Exist(sName) THEN
$hConn.Databases.Add(sName)
ENDIF
$hConn.Close

ENDIF

$hConn.Name = sName
$hConn.Open

frmDatabase.Enabled = TRUE
frmRequest.Enabled = TRUE

CATCH

Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnCreate_Click()

DIM hTable AS Table

hTable = $hConn.Tables.Add("test")

hTable.Fields.Add("id", db.Long)
hTable.Fields.Add("color", db.Integer,, 1)
hTable.Fields.Add("firstname", db.String, 16)
hTable.Fields.Add("name", db.String, 32)
hTable.Fields.Add("birth", db.Date)
hTable.Fields.Add("active", db.Boolean)
hTable.Fields.Add("salary", db.Float)
hTable.Fields.Add("comment", db.String)
hTable.Fields.Add("image", db.Blob)

hTable.PrimaryKey = ["id"]

hTable.Update

hTable = $hConn.Tables.Add("color")

hTable.Fields.Add("color", db.Serial)
hTable.Fields.Add("name", gb.String, 32)
hTable.Fields.Add("french", gb.String, 32)

hTable.PrimaryKey = ["color"]

hTable.Update

CATCH

Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnDelete_Click()

TRY $hConn.Tables.Remove("test")
TRY $hConn.Tables.Remove("color")

END

PUBLIC SUB btnFill_Click()

DIM iInd AS INTEGER
DIM rTest AS Result
DIM rColor AS Result
DIM sColor AS STRING
DIM aName AS String[] = ["Paul", "Pierre", "Jacques", "Antoine", "Mathieu", "Robert", "Stéphane" "Yannick", "Frédéric"]
DIM aFrench AS String[] = ["Noir", "Blanc", "Rouge", "Vert", "Bleu", "Jaune", "Transparent"]

INC Application.Busy

$hConn.Begin

rColor = $hConn.Create("color")

FOR EACH sColor IN [("Black"), ("White"), ("Red"), ("Green"), ("Blue"), ("Yellow"), ("Transparent")]

rColor!name = sColor
rColor!french = aFrench[iInd]
INC iInd
rColor.Update

NEXT

rTest = $hConn.Create("test")

FOR iInd = 1 TO txtCount.Value

rTest!id = iInd
rTest!color = Int(Rnd(6)) + 1
rTest!firstname = aName[Int(Rnd(aName.Count))]
rTest!name = ("Name #") & iInd
rTest!birth = CDate("01/01/1970") + Int(Rnd(10000))
rTest!active = Int(Rnd(2))
rTest!salary = Round(Rnd(1000, 10000), -2)

rTest.Update

NEXT

$hConn.Commit

FINALLY

DEC Application.Busy

CATCH

$hConn.Rollback
Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnRun_Click()

DIM rData AS Result
DIM hForm AS FRequest

rData = $hConn.Exec(txtRequest.Text)
hForm = NEW FRequest($hConn, rData)
hForm.Show

'Catch

'Message.Error(DConv(Error.Text))

END

PUBLIC SUB Form_Open()

$hConn = NEW Connection
FRequest.Init = TRUE

END

PUBLIC SUB Form_Close()

$hConn.Close

END

PUBLIC SUB chkDebug_Click()

DB.Debug = chkDebug.Value

END

PUBLIC SUB btnTest_Click()

FTest.Show

END

MySQLExample



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
' Gambas module file

PUBLIC $Connection AS NEW Connection
PUBLIC $hResult AS Result
PUBLIC $Host AS STRING
PUBLIC $Password AS STRING
PUBLIC $Port AS STRING
PUBLIC $User AS STRING
PUBLIC $bSchemaOk AS BOOLEAN = TRUE
PUBLIC $hFTables AS FTables
PUBLIC $hFNewTable AS FNewTable
PUBLIC $hFNewView AS FNewView
PUBLIC $hFNewDatabase AS FNewDatabase
PUBLIC $hFNewIndex AS FNewIndex
PUBLIC $hFNewRoutine AS FNewRoutine
PUBLIC $hFMessage AS FMessage
PUBLIC $hFNewTrigger AS FNewTrigger
PUBLIC $hFNewField AS FNewField
PUBLIC $hFNewEvent AS FNewEvent
PUBLIC $hFConnect AS FConnect

PUBLIC PROCEDURE Main()

$hFConnect = NEW FConnect
IF $hFConnect.ShowModal() OR NOT $Host OR NOT $Password OR NOT $Port OR NOT $User THEN RETURN
WITH $Connection
.Type = "mysql"
.Name = "mysql"
.Host = $Host
.Password = $Password
.Port = $Port
.User = $User
.Open()
END WITH
IF NOT $Connection.Opened THEN RETURN
IF CInt($Connection.MySQL.Version.MinorVersion()) < 1 THEN
$bSchemaOk = FALSE
Message.Warning(("Seems that your MySQL version is lower than 5.1.\ntherefore you will get some error and warning messages."))
ENDIF
TRY $Connection.MySQL.Use(Settings["/General/LastDatabase", "mysql"])
$hFTables = NEW FTables
$hFTables.ShowModal()
CATCH
Message.Error(Error.Where & "::" & Error.Text)

END

PUBLIC PROCEDURE Error(OPTIONAL Message AS STRING)

DEC Application.Busy
IF Error.Text LIKE "*MySQL server has gone away" THEN
$Connection.Close()
$Connection = NULL
$Connection = NEW Connection
WITH $Connection
.Type = "mysql"
.Name = "mysql"
.Host = $Host
.Password = $Password
.Port = $Port
.User = $User
.Open()
END WITH
ENDIF
IF NOT Message THEN Message = Error.Where & "::" & Error.Text
modMain.$hFMessage = NEW FMessage(Message)
modMain.$hFMessage.ShowModal()

END

PictureDatabase



====================

Navigation :



<-- Accueil du WIKI : <--

====================

Documentation :



==============================