forked from trent_larson/crowd-funder-for-time-pwa
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.
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user