-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnessione.py
executable file
·40 lines (36 loc) · 1.09 KB
/
connessione.py
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
import sys
#include QT5
from PyQt5 import QtGui, QtCore, QtNetwork, QtSql, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtSql import *
from PyQt5.QtNetwork import *
#-------------------------------------------------------
# Creo la connessione al database SQLite e la relativa
# tabella
#-------------------------------------------------------
def creaConnessione():
#Imposto la connessione al db sqlite
db = QSqlDatabase.addDatabase('QSQLITE')
#Imposto il database con il nome rubrica.db
db.setDatabaseName('rubrica.db')
#Se il dabatase non si apre allora lancia un
#messaggio di errore
if not db.open():
QMessageBox.critical(None,"Cannot open database",
"Unable to estabilish a database connection...\n",
QMessageBox.Ok)
return False
else:
db.open()
#Creo la tabella desiderata
query = QSqlQuery()
query.exec_("create table rubrica("
"id int primary key,"
"nome varchar(100),"
"cognome varchar(100),"
"indirizzo varchar(100),"
"mail varchar(100),"
"tel_casa varchar(100),"
"cellulare varchar(100))")
return True