@@ -120,20 +120,29 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
120120 protected generateLockContext ( db : SQLiteDBConnection ) : LockContext {
121121 const _execute = async ( query : string , params : any [ ] = [ ] ) : Promise < QueryResult > => {
122122 const platform = Capacitor . getPlatform ( ) ;
123+
124+ const _query = async ( query : string , params : any [ ] = [ ] ) => {
125+ const result = await db . query ( query , params ) ;
126+ const arrayResult = result . values ?? [ ] ;
127+ return {
128+ rowsAffected : 0 ,
129+ rows : {
130+ _array : arrayResult ,
131+ length : arrayResult . length ,
132+ item : ( idx : number ) => arrayResult [ idx ]
133+ }
134+ } ;
135+ } ;
136+
137+ if ( db . getConnectionReadOnly ( ) ) {
138+ return _query ( query , params ) ;
139+ }
140+
123141 if ( platform == 'android' ) {
124142 // Android: use query for SELECT and executeSet for mutations
125143 // We cannot use `run` here for both cases.
126144 if ( query . toLowerCase ( ) . trim ( ) . startsWith ( 'select' ) ) {
127- const result = await db . query ( query , params ) ;
128- const arrayResult = result . values ?? [ ] ;
129- return {
130- rowsAffected : 0 ,
131- rows : {
132- _array : arrayResult ,
133- length : arrayResult . length ,
134- item : ( idx : number ) => arrayResult [ idx ]
135- }
136- } ;
145+ return _query ( query , params ) ;
137146 } else {
138147 const result = await db . executeSet ( [ { statement : query , values : params } ] , false ) ;
139148 return {
0 commit comments