Fix hardcoded SQLite '?' placeholders across all payment modules for MySQL compatibility

- Add DatabaseManager.placeholder property returning '?' (SQLite) or '%s' (MySQL)
- Fix paypal_handler.py: payment_methods INSERT
- Fix service.py: payment_methods INSERT for PayPal vault
- Fix subscription/manager.py: all SQL in create/upgrade/downgrade/cancel_subscription
- Fix subscription/renewal.py: all SQL in process_renewals/_renew_subscription/_cancel_subscription
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 03fcab6a
......@@ -166,6 +166,10 @@ class DatabaseManager:
else:
raise ValueError(f"Unsupported database type: {self.db_type}")
@property
def placeholder(self) -> str:
return '?' if self.db_type == 'sqlite' else '%s'
async def _run_in_executor(self, func, *args):
"""Run a blocking database operation in a thread pool executor."""
loop = asyncio.get_event_loop()
......
......@@ -280,10 +280,11 @@ class PayPalPaymentHandler:
# Store payment method
with self.db._get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
ph = self.db.placeholder
cursor.execute(f"""
INSERT INTO payment_methods
(user_id, type, identifier, is_default, is_active)
VALUES (?, 'paypal', ?, 1, 1)
VALUES ({ph}, 'paypal', {ph}, 1, 1)
""", (user_id, agreement_id))
conn.commit()
......
......@@ -182,10 +182,11 @@ class PaymentService:
# Store payment method
with self.db._get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
ph = self.db.placeholder
cursor.execute(f"""
INSERT INTO payment_methods
(user_id, type, gateway, identifier, paypal_email, is_default, status)
VALUES (?, 'paypal', 'paypal_v3', ?, ?, 1, 'active')
VALUES ({ph}, 'paypal', 'paypal_v3', {ph}, {ph}, 1, 'active')
""", (user_id, result['payment_token_id'], result['payer_email']))
conn.commit()
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment