Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathieu Loiseau
GameOfWords
Commits
a71397d4
Commit
a71397d4
authored
May 09, 2017
by
Mathieu Loiseau
Browse files
transaction w/ verification
parent
f9cd9df2
Changes
2
Hide whitespace changes
Inline
Side-by-side
GoW.sql
View file @
a71397d4
...
...
@@ -146,7 +146,7 @@ CREATE TABLE IF NOT EXISTS `parties` (
CREATE
TABLE
IF
NOT
EXISTS
`stats`
(
`userid`
int
(
11
)
NOT
NULL
,
`langue`
varchar
(
20
)
NOT
NULL
,
`langue`
varchar
(
3
)
NOT
NULL
,
`nbJeux_oracle`
smallint
(
5
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'Nombre de parties'
,
`nbAbandons_oracle`
smallint
(
5
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'Nombre d
''
abandons'
,
`nbEnregistrements_oracle`
smallint
(
5
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'Nombre d
''
enregistrements envoyés'
,
...
...
@@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS `stats` (
`score_druide`
mediumint
(
9
)
NOT
NULL
DEFAULT
'0'
COMMENT
'score (peut être calculé uniquement avec les données de la table)'
,
`nbEnregistrements_devin`
smallint
(
5
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'nombre d
''
enregistrements écoutés'
,
`nbMotsTrouves_devin`
smallint
(
5
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'nombres de mots associés aux enregistrements trouvés'
,
`sommeMises_devin`
mediumint
(
8
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'La somme des mises des parties
jou
ées en tant que devin'
,
`sommeMises_devin`
mediumint
(
8
)
UNSIGNED
NOT
NULL
DEFAULT
'0'
COMMENT
'La somme des mises des parties
gagn
ées en tant que devin'
,
`score_devin`
mediumint
(
9
)
NOT
NULL
DEFAULT
'0'
COMMENT
'score de devin (pas calculable avec les données de la table)'
,
PRIMARY
KEY
(
`userid`
,
`langue`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'Statistiques et scores des joueurs'
;
...
...
sys/db.class.php
View file @
a71397d4
...
...
@@ -58,15 +58,23 @@ class db
return
$this
->
result
;
}
public
function
transaction
(
$query_array
){
public
function
transaction
(
$query_array
,
$abort_on_0
=
true
){
$this
->
handler
->
begin_transaction
();
$i
=
1
;
foreach
(
$query_array
as
$query
)
{
$this
->
query
(
$query
);
if
(
!
$this
->
result
){
if
(
!
$this
->
result
||
(
$abort_on_0
&&
$this
->
touched_rows
()
===
0
)
){
$commit
=
false
;
$this
->
handler
->
rollback
();
throw
new
Exception
(
"Error “"
.
$this
->
handler
->
error
.
"” in “"
.
$query
.
"” (query #"
.
$i
.
")."
);
if
(
!
$this
->
result
){
$message
=
"Error “"
.
$this
->
handler
->
error
.
"”"
;
}
else
{
$message
=
"No affected rows"
;
}
throw
new
Exception
(
"
$message
in “"
.
$query
.
"” (query #"
.
$i
.
")."
);
}
$i
++
;
}
...
...
@@ -99,7 +107,7 @@ class db
public
function
affected_rows
()
{
return
$this
->
handler
->
affected_rows
;
return
isset
(
$this
->
handler
->
affected_rows
)
?
$this
->
handler
->
affected_rows
:
0
;
}
public
function
has_result
(){
...
...
@@ -109,11 +117,15 @@ class db
public
function
num_rows
(){
$res
=
0
;
if
(
$this
->
has_result
()){
$res
=
$this
->
result
->
num_rows
;
$res
=
isset
(
$this
->
result
->
num_rows
)
?
$this
->
result
->
num_rows
:
0
;
}
return
$res
;
}
public
function
touched_rows
(){
return
$this
->
num_rows
()
+
$this
->
affected_rows
();
}
public
function
get_result
(){
return
$this
->
result
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment