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
Francois Mares
NF18 - Projet SCF - Groupe 5
Commits
814d7df8
Commit
814d7df8
authored
May 18, 2021
by
Francois Mares
Browse files
Replace SQL.py
parent
b8ef34b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Python/SQL.py
View file @
814d7df8
...
...
@@ -20,24 +20,20 @@ class SQL():
self
.
_USER
=
USER
def
_connexion
(
self
):
try
:
return
psycopg2
.
connect
(
f
"dbname='
{
self
.
_DATABASE
}
' user ='
{
self
.
_USER
}
' host='
{
self
.
_HOST
}
' password='
{
self
.
_PASSWORD
}
'"
)
except
psycopg2
.
DatabaseError
as
e
:
connexion
.
rollback
()
print
(
"Message système :"
,
e
)
return
psycopg2
.
connect
(
f
"dbname='
{
self
.
_DATABASE
}
' user ='
{
self
.
_USER
}
' host='
{
self
.
_HOST
}
' password='
{
self
.
_PASSWORD
}
'"
)
# PUBLIC:
def
requete_sql
(
self
,
sql
):
connexion
=
self
.
_connexion
()
connexion
=
None
try
:
connexion
=
self
.
_connexion
()
cur
=
connexion
.
cursor
()
cur
.
execute
(
sql
)
rows
=
cur
.
fetchall
()
connexion
.
close
()
return
rows
except
psycopg2
.
Error
as
e
:
connexion
.
rollback
()
print
(
"Message système :"
,
e
)
def
insert_into
(
self
,
class_name
,
values
):
...
...
@@ -48,11 +44,10 @@ class SQL():
sql
=
sql
[:
-
1
]
sql
+=
")"
connexion
=
self
.
_connexion
()
try
:
connexion
=
self
.
_connexion
()
cur
=
connexion
.
cursor
()
cur
.
execute
(
sql
)
connexion
.
close
()
except
psycopg2
.
DataError
as
e
:
connexion
.
rollback
()
except
psycopg2
.
Error
as
e
:
print
(
"Message système :"
,
e
)
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