Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
11f500fa
Commit
11f500fa
authored
Mar 11, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4630 from mmoya/mysql_variables-fix2
Add support for string values
parents
e4e64a96
811aa261
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
4 deletions
+41
-4
library/database/mysql_variables
+41
-4
No files found.
library/database/mysql_variables
View file @
11f500fa
...
@@ -76,14 +76,48 @@ else:
...
@@ -76,14 +76,48 @@ else:
mysqldb_found
=
True
mysqldb_found
=
True
def
typedvalue
(
value
):
"""
Convert value to number whenever possible, return same value
otherwise.
>>> typedvalue('3')
3
>>> typedvalue('3.0')
3.0
>>> typedvalue('foobar')
'foobar'
"""
try
:
return
int
(
value
)
except
ValueError
:
pass
try
:
return
float
(
value
)
except
ValueError
:
pass
return
value
def
getvariable
(
cursor
,
mysqlvar
):
def
getvariable
(
cursor
,
mysqlvar
):
cursor
.
execute
(
"SHOW VARIABLES LIKE '"
+
mysqlvar
+
"'"
)
cursor
.
execute
(
"SHOW VARIABLES LIKE '"
+
mysqlvar
+
"'"
)
mysqlvar_val
=
cursor
.
fetchall
()
mysqlvar_val
=
cursor
.
fetchall
()
return
mysqlvar_val
return
mysqlvar_val
def
setvariable
(
cursor
,
mysqlvar
,
value
):
def
setvariable
(
cursor
,
mysqlvar
,
value
):
""" Set a global mysql variable to a given value
The DB driver will handle quoting of the given value based on its
type, thus numeric strings like '3.0' or '8' are illegal, they
should be passed as numeric literals.
"""
try
:
try
:
cursor
.
execute
(
"SET GLOBAL "
+
mysqlvar
+
"
="
+
value
)
cursor
.
execute
(
"SET GLOBAL "
+
mysqlvar
+
"
=
%
s"
,
(
value
,)
)
cursor
.
fetchall
()
cursor
.
fetchall
()
result
=
True
result
=
True
except
Exception
,
e
:
except
Exception
,
e
:
...
@@ -203,11 +237,14 @@ def main():
...
@@ -203,11 +237,14 @@ def main():
else
:
else
:
if
len
(
mysqlvar_val
)
<
1
:
if
len
(
mysqlvar_val
)
<
1
:
module
.
fail_json
(
msg
=
"Variable not available"
,
changed
=
False
)
module
.
fail_json
(
msg
=
"Variable not available"
,
changed
=
False
)
if
value
==
mysqlvar_val
[
0
][
1
]:
# Type values before using them
value_wanted
=
typedvalue
(
value
)
value_actual
=
typedvalue
(
mysqlvar_val
[
0
][
1
])
if
value_wanted
==
value_actual
:
module
.
exit_json
(
msg
=
"Variable already set to requested value"
,
changed
=
False
)
module
.
exit_json
(
msg
=
"Variable already set to requested value"
,
changed
=
False
)
result
=
setvariable
(
cursor
,
mysqlvar
,
value
)
result
=
setvariable
(
cursor
,
mysqlvar
,
value
_wanted
)
if
result
is
True
:
if
result
is
True
:
module
.
exit_json
(
msg
=
"Variable change succeeded
"
,
changed
=
True
)
module
.
exit_json
(
msg
=
"Variable change succeeded
prev_value=
%
s"
%
value_actual
,
changed
=
True
)
else
:
else
:
module
.
fail_json
(
msg
=
result
,
changed
=
False
)
module
.
fail_json
(
msg
=
result
,
changed
=
False
)
...
...
Write
Preview
Markdown
is supported
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