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
1783d765
Commit
1783d765
authored
May 18, 2021
by
Francois Mares
Browse files
Upload New File
parent
b2c2e13d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Python/SQL.py
0 → 100644
View file @
1783d765
import
psycopg2
class
SQL
():
HOST
=
'tuxa.sme.utc'
DATABASE
=
'dbnf18p103'
PASSWORD
=
'RdhPbg7H'
USER
=
'nf18p103'
def
requete_sql
(
self
,
sql
):
try
:
connexion
=
psycopg2
.
connect
(
f
"dbname='
{
DATABASE
}
' user ='
{
USER
}
' host='
{
HOST
}
' password='
{
PASSWORD
}
'"
)
cur
=
connexion
.
cursor
()
cur
.
execute
(
sql
)
rows
=
cur
.
fetchall
()
connexion
.
close
()
return
rows
except
psycopg2
.
IntegrityError
as
e
:
connexion
.
rollback
()
print
(
"Message système :"
,
e
)
def
insert_into
(
self
,
classe
,
values
):
sql
=
"INSERT INTO "
+
classe
+
" VALUES("
+
values
+
")"
try
:
connexion
=
psycopg2
.
connect
(
f
"dbname='
{
DATABASE
}
' user ='
{
USER
}
' host='
{
HOST
}
' password='
{
PASSWORD
}
'"
)
cur
=
connexion
.
cursor
()
cur
.
execute
(
sql
)
connexion
.
close
()
except
psycopg2
.
DataError
as
e
:
connexion
.
rollback
()
print
(
"Message système :"
,
e
)
\ No newline at end of file
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