0

I've recently tried to create an executable with python 2.7 which can read a MySQL database.

The database (named 'montre') regroups two tables : patient and proto_1

Here is the content of those tables :

mysql> select * from proto_1;
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+
| id | Nom_Montre | Date_Heure          | Temperature | Pulsion_cardiaque | Taux
_oxy_sang | Humidite |
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+
|  1 | montre_1   | 2017-11-27 19:33:25 |       22.30 |              NULL |
     NULL |     NULL |
|  2 | montre_1   | 2017-11-27 19:45:12 |       22.52 |              NULL |
     NULL |     NULL |
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+

mysql> select * from patient;
+----+-----------+--------+------+------+---------------------+------------+----
----------+
| id | nom       | prenom | sexe | age  | date_naissance      | Nom_Montre | com
mentaires |
+----+-----------+--------+------+------+---------------------+------------+----
----------+
|  2 | RICHEMONT | Robert | M    |   37 | 1980-04-05 23:43:00 | montre_3   | ess
aye2      |
|  3 | PIERRET   | Mandy  | F    |   22 | 1995-04-05 10:43:00 | montre_4   | ess
aye3      |
| 14 | PIEKARZ   | Allan  | M    |   22 | 1995-06-01 10:32:56 | montre_1   | Hea
lthy man  |

+----+-----------+--------+------+------+---------------------+------------+----
----------+

As I'm just used to code in C (no OOP), I didn't create class in the python project (shame on me...). But I managed, in two files, to create something (with mysql.connector) which can print (on the cmd) my database and excecute sub like looking-for() etc.

Now, I want to create a GUI for users with pyqt. Unfortunately, I saw that the structure is totally different, with class etc. But okay, I tried to go throught this and I've created a GUI which allows to display the table "patient". But I didn't manage (in the datasheet of QT) to find how I can use the programs I've already created to display. Neither how to display in a tableWidget only several rows of my table patient for exemple (Using QSQL).

For example, if I want to display all the table patient, I use this line (pyQt):

self.model.setTable("patient")

For this one, I got it, but that disturb me because there is no MySQL coding requisites to display my table and so I don't know how to sort only the rows we want to see and display them. If we only want to see, for example, the ID n°2, how to display in the table:widget only Robert ?

To recap, I want to know :

  • If I can take the coding I've created and combine it with pyQT
  • How to display (tableWidget) only rows which are selected by MySQL. Is that possible ?

Please find in the URL my code for a better understanding of my problem : https://drive.google.com/file/d/1nxufjJfF17P5hN__CBEcvrbuHF-23aHN/view?usp=sharing

I hope I was clear, thank you all for your help !

piekaall
  • 9
  • 1
  • 2
    Please read the guidance on [ask]. This is currently far too broad and is asking multiple questions. – ekhumoro Nov 30 '17 at 18:45
  • PyQt has a [QtSql module](http://pyqt.sourceforge.net/Docs/PyQt4/qtsql.html). So yes, you can display on a tableWidget only rows selected with a SQL query. – Loïc G. Nov 30 '17 at 22:43

0 Answers0