From afa65b308e872af6b59deab65df20e121dff4f8c Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 26 Jun 2025 09:31:59 +0000 Subject: [PATCH] fix: Add comprehensive SQL parameter type conversion at platform service level - Add parameter conversion in CapacitorPlatformService.queueOperation() - Convert booleans to integers (0/1) for SQLite compatibility - Convert objects/arrays to JSON strings for database storage - Handle null/undefined values properly - Ensure all SQL parameters are SQLite-compatible before queuing This should resolve the 'SQLite3 can only bind numbers, strings, bigints, buffers, and null' error by converting all parameters at the platform service level before they reach SQLite. --- .../platforms/CapacitorPlatformService.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/services/platforms/CapacitorPlatformService.ts b/src/services/platforms/CapacitorPlatformService.ts index e004147f..d67187b8 100644 --- a/src/services/platforms/CapacitorPlatformService.ts +++ b/src/services/platforms/CapacitorPlatformService.ts @@ -179,11 +179,28 @@ export class CapacitorPlatformService implements PlatformService { sql: string, params: unknown[] = [], ): Promise { + // Convert parameters to SQLite-compatible types + const convertedParams = params.map((param) => { + if (param === null || param === undefined) { + return null; + } + if (typeof param === 'object' && param !== null) { + // Convert objects and arrays to JSON strings + return JSON.stringify(param); + } + if (typeof param === 'boolean') { + // Convert boolean to integer (0 or 1) + return param ? 1 : 0; + } + // Numbers, strings, bigints, and buffers are already supported + return param; + }); + return new Promise((resolve, reject) => { const operation: QueuedOperation = { type, sql, - params, + params: convertedParams, resolve: (value: unknown) => resolve(value as R), reject, };