# API MySQL Compatibility Fix

## Issue Fixed

The API endpoint `/documents/by-document-number` was using MSSQL syntax (`?` placeholders) but the database is now MySQL which requires `%s` placeholders.

**Error:**
```
TypeError: not all arguments converted during string formatting
```

## Changes Made

Updated the following endpoints to support both MySQL and MSSQL:

1. **`/dictionary/document-types`** - Document type labels
2. **`/documents/by-document-number`** - Main document lookup endpoint
3. **`/documents/metadata-by-number`** - Document metadata
4. **`/documents/id/{document_id}`** - Get document by ID
5. **`/documents/id/{document_id}/pdf`** - Stream PDF by ID

## SQL Syntax Changes

### MySQL (Current)
- Placeholder: `%s` instead of `?`
- Schema prefix: None (e.g., `lr_source_document` not `LRSAdmin.lr_source_document`)
- Trim function: `TRIM()` instead of `RTRIM(LTRIM())`

### MSSQL (Legacy)
- Placeholder: `?`
- Schema prefix: `LRSAdmin.` (e.g., `LRSAdmin.lr_source_document`)
- Trim function: `RTRIM(LTRIM())`

## Testing

The endpoint now works correctly:

```bash
# Test endpoint
curl "http://localhost:8000/documents/by-document-number?document_number=pl60600"
```

If document doesn't exist, you'll get:
```json
{
  "detail": "No records found for document_number 'pl60600'"
}
```

If document exists, you'll get the full document metadata.

## Status

✅ **Fixed** - All SQL queries now support MySQL syntax
✅ **Backward Compatible** - Still supports MSSQL if needed
✅ **Tested** - Query execution verified

