@@ -18,6 +18,7 @@ import {
1818import { PowerSyncCore } from '../plugin/PowerSyncCore.js' ;
1919import { messageForErrorCode } from '../plugin/PowerSyncPlugin.js' ;
2020import { CapacitorSQLiteOpenFactoryOptions , DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js' ;
21+ import { normalizeIOSSqliteParams } from './sqliteParams.js' ;
2122/**
2223 * Monitors the execution time of a query and logs it to the performance timeline.
2324 */
@@ -39,13 +40,15 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
3940 protected initializedPromise : Promise < void > ;
4041 protected writeMutex : Mutex ;
4142 protected readMutex : Mutex ;
43+ protected readonly platform : string ;
4244
4345 constructor ( protected options : CapacitorSQLiteOpenFactoryOptions ) {
4446 super ( ) ;
4547 this . _writeConnection = null ;
4648 this . _readConnection = null ;
4749 this . writeMutex = new Mutex ( ) ;
4850 this . readMutex = new Mutex ( ) ;
51+ this . platform = Capacitor . getPlatform ( ) ;
4952 this . initializedPromise = this . init ( ) ;
5053 }
5154
@@ -98,8 +101,7 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
98101
99102 await this . _readConnection . open ( ) ;
100103
101- const platform = Capacitor . getPlatform ( ) ;
102- if ( platform == 'android' ) {
104+ if ( this . platform == 'android' ) {
103105 /**
104106 * SQLCipher for Android enables dynamic loading of extensions.
105107 * On iOS we use a static auto extension registration.
@@ -118,8 +120,10 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
118120 }
119121
120122 protected generateLockContext ( db : SQLiteDBConnection ) : LockContext {
123+ const normalizeParams = ( params : any [ ] ) => ( this . platform == 'ios' ? normalizeIOSSqliteParams ( params ) : params ) ;
124+
121125 const _query = async ( query : string , params : any [ ] = [ ] ) => {
122- const result = await db . query ( query , params ) ;
126+ const result = await db . query ( query , normalizeParams ( params ) ) ;
123127 const arrayResult = result . values ?? [ ] ;
124128 return {
125129 rowsAffected : 0 ,
@@ -132,13 +136,11 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
132136 } ;
133137
134138 const _execute = async ( query : string , params : any [ ] = [ ] ) : Promise < QueryResult > => {
135- const platform = Capacitor . getPlatform ( ) ;
136-
137139 if ( db . getConnectionReadOnly ( ) ) {
138140 return _query ( query , params ) ;
139141 }
140142
141- if ( platform == 'android' ) {
143+ if ( this . platform == 'android' ) {
142144 // Android: use query for SELECT and executeSet for mutations
143145 // We cannot use `run` here for both cases.
144146 if ( query . toLowerCase ( ) . trim ( ) . startsWith ( 'select' ) ) {
@@ -158,7 +160,7 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
158160 }
159161
160162 // iOS (and other platforms): use run("all")
161- const result = await db . run ( query , params , false , 'all' ) ;
163+ const result = await db . run ( query , normalizeParams ( params ) , false , 'all' ) ;
162164 const resultSet = result . changes ?. values ?? [ ] ;
163165 return {
164166 insertId : result . changes ?. lastId ,
@@ -207,7 +209,7 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
207209 let result = await db . executeSet (
208210 params . map ( ( param ) => ( {
209211 statement : query ,
210- values : param
212+ values : normalizeParams ( param )
211213 } ) )
212214 ) ;
213215
0 commit comments