SCGR commited on
Commit
3d94de1
Β·
1 Parent(s): 07e2e28

fix SQLacademy syntax

Browse files
Files changed (1) hide show
  1. py_backend/app/routers/images.py +8 -7
py_backend/app/routers/images.py CHANGED
@@ -2,6 +2,7 @@ import hashlib
2
  import mimetypes
3
  from fastapi import APIRouter, HTTPException, Depends
4
  from sqlalchemy.orm import Session
 
5
 
6
  from ..database import SessionLocal
7
  from ..models import Images, image_countries
@@ -27,7 +28,7 @@ async def create_image_from_url(payload: CreateImageFromUrlIn, db: Session = Dep
27
 
28
  # Check database connectivity
29
  try:
30
- db.execute("SELECT 1")
31
  print("βœ“ Database connection OK")
32
  except Exception as db_error:
33
  print(f"βœ— Database connection failed: {db_error}")
@@ -35,10 +36,10 @@ async def create_image_from_url(payload: CreateImageFromUrlIn, db: Session = Dep
35
 
36
  # Check if required tables exist
37
  try:
38
- db.execute("SELECT 1 FROM sources LIMIT 1")
39
- db.execute("SELECT 1 FROM event_types LIMIT 1")
40
- db.execute("SELECT 1 FROM spatial_references LIMIT 1")
41
- db.execute("SELECT 1 FROM image_types LIMIT 1")
42
  print("βœ“ Required tables exist")
43
  except Exception as table_error:
44
  print(f"βœ— Required tables missing: {table_error}")
@@ -148,7 +149,7 @@ async def debug_database_status(db: Session = Depends(get_db)):
148
 
149
  # Check basic connectivity
150
  try:
151
- db.execute("SELECT 1")
152
  status["database_connection"] = "OK"
153
  except Exception as e:
154
  status["database_connection"] = f"FAILED: {e}"
@@ -162,7 +163,7 @@ async def debug_database_status(db: Session = Depends(get_db)):
162
 
163
  for table in tables_to_check:
164
  try:
165
- result = db.execute(f"SELECT COUNT(*) FROM {table}")
166
  count = result.scalar()
167
  status[f"table_{table}"] = f"EXISTS ({count} rows)"
168
  except Exception as e:
 
2
  import mimetypes
3
  from fastapi import APIRouter, HTTPException, Depends
4
  from sqlalchemy.orm import Session
5
+ from sqlalchemy import text
6
 
7
  from ..database import SessionLocal
8
  from ..models import Images, image_countries
 
28
 
29
  # Check database connectivity
30
  try:
31
+ db.execute(text("SELECT 1"))
32
  print("βœ“ Database connection OK")
33
  except Exception as db_error:
34
  print(f"βœ— Database connection failed: {db_error}")
 
36
 
37
  # Check if required tables exist
38
  try:
39
+ db.execute(text("SELECT 1 FROM sources LIMIT 1"))
40
+ db.execute(text("SELECT 1 FROM event_types LIMIT 1"))
41
+ db.execute(text("SELECT 1 FROM spatial_references LIMIT 1"))
42
+ db.execute(text("SELECT 1 FROM image_types LIMIT 1"))
43
  print("βœ“ Required tables exist")
44
  except Exception as table_error:
45
  print(f"βœ— Required tables missing: {table_error}")
 
149
 
150
  # Check basic connectivity
151
  try:
152
+ db.execute(text("SELECT 1"))
153
  status["database_connection"] = "OK"
154
  except Exception as e:
155
  status["database_connection"] = f"FAILED: {e}"
 
163
 
164
  for table in tables_to_check:
165
  try:
166
+ result = db.execute(text(f"SELECT COUNT(*) FROM {table}"))
167
  count = result.scalar()
168
  status[f"table_{table}"] = f"EXISTS ({count} rows)"
169
  except Exception as e: