
    i                     $    S SK Jr   " S S5      rg)   )get_db_connectionc                   D    \ rS rSr\S 5       r\S 5       r\S 5       rSrg)Location   c                     [        5       n U (       d  g U R                  5       nUR                  S5        U R                  5         [	        S5        U (       a7  U R                  5       (       a!  WR                  5         U R                  5         ggg! [
         a  n[	        SU 35         SnAN\SnAff = f! U (       a7  U R                  5       (       a!  WR                  5         U R                  5         f f f = f)z0Creates the locations table if it doesn't exist.Nz
                CREATE TABLE IF NOT EXISTS locations (
                    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                    name TEXT NOT NULL,
                    UNIQUE (name(191))
                )
            z:[OK] 'locations' table exists or was successfully created.z"Error creating 'locations' table: )r   cursorexecutecommitprint	Exceptionis_connectedclose)connr   es      -/var/www/fran/franai/models/location_model.pycreate_table_if_not_exists#Location.create_table_if_not_exists   s     !"	[[]FNN   KKMNO ))++

 ,t  	<6qc:;;	< ))++

 ,ts*   <B 
B1B,'B4 ,B11B4 4A C4c                  ^   [        5       n U (       d  / $  U R                  SS9nSnUR                  U5        UR                  5       nUU (       a7  U R	                  5       (       a!  UR                  5         U R                  5         $ $ $ ! [         aX  n[        SU 35        / s SnAU (       a7  U R	                  5       (       a!  WR                  5         U R                  5         $ $ $ SnAff = f! U (       a7  U R	                  5       (       a!  WR                  5         U R                  5         f f f = f)zFetch a list of all locations.T)
dictionaryz,SELECT id, name FROM locations ORDER BY namezError fetching all locations: N)r   r   r	   fetchallr   r   r   r   )r   r   query	locationsr   s        r   get_all_locationsLocation.get_all_locations   s     !"I	[[D[1FBENN5!)I
 ))++

 ,t	  	21#67I))++

 ,t		 ))++

 ,ts0   3B 
C)C$ C)!C, $C))C, ,A D,c                    [        5       nU(       d  g UR                  5       nSnUR                  X045        UR                  5         UR                  U(       a7  UR                  5       (       a!  UR                  5         UR                  5         $ $ $ ! [         af  n[        SU 35        UR                  5          SnAU(       a7  UR                  5       (       a!  WR                  5         UR                  5         gggSnAff = f! U(       a7  UR                  5       (       a!  WR                  5         UR                  5         f f f = f)z$Adds a new location to the database.Nz(INSERT INTO locations (name) VALUES (%s)zError adding location: )
r   r   r	   r
   	lastrowidr   r   r   r   rollback)namer   r   r   r   s        r   add_locationLocation.add_location2   s     !"	[[]F>ENN5'*KKM## ))++

 ,t  	+A3/0MMO))++

 ,t	
 ))++

 ,ts*   ?B 
DC=:D =DD A E N)	__name__
__module____qualname____firstlineno__staticmethodr   r   r   __static_attributes__r!       r   r   r      s<     0  (  r(   r   N)services.mysql_servicer   r   r!   r(   r   <module>r*      s    6C Cr(   