Browse Source

Separates query for looking up station id

Jose Reyes 6 years ago
parent
commit
db88574082
1 changed files with 14 additions and 2 deletions
  1. 14
    2
      __init__.py

+ 14
- 2
__init__.py View File

@@ -34,10 +34,22 @@ def create_app(test_config=None):
34 34
                 error = 'Email is required'
35 35
             else:
36 36
                 db = get_db()
37
+                station_id = db.execute(
38
+                    'SELECT s_id FROM station WHERE nombre_empleado=?',
39
+                    (place_holder)
40
+                ).fetchone()
41
+                db.execute(
42
+                    'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
43
+                    (station_id)
44
+                )
45
+                turn = db.execute(
46
+                    'SELECT last_turn FROM station WHERE s_id=?',
47
+                    (station_id)
48
+                )
37 49
                 db.execute(
38 50
                     'INSERT INTO turno (cName, cEmail, timeArrival, station)'
39
-                    ' VALUES (?, ?, ?, (SELECT s_id FROM station WHERE nombre_empleado=?))',
40
-                    (cName, cEmail, 'testin', 'Fulano de Tal')
51
+                    ' VALUES (?, ?, ?, ?)',
52
+                    (cName, cEmail, 'testin', station_id)
41 53
                 )
42 54
             db.commit()
43 55