Browse Source

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.
streamline-attempt
Matthew Raymer 1 week ago
parent
commit
afa65b308e
  1. 19
      src/services/platforms/CapacitorPlatformService.ts

19
src/services/platforms/CapacitorPlatformService.ts

@ -179,11 +179,28 @@ export class CapacitorPlatformService implements PlatformService {
sql: string,
params: unknown[] = [],
): Promise<R> {
// 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<R>((resolve, reject) => {
const operation: QueuedOperation = {
type,
sql,
params,
params: convertedParams,
resolve: (value: unknown) => resolve(value as R),
reject,
};

Loading…
Cancel
Save