@@ -6,7 +6,7 @@ use std::time::Duration;
66use spacetimedb_lib:: buffer:: DecodeError ;
77use spacetimedb_lib:: identity:: AuthCtx ;
88use spacetimedb_lib:: { bsatn, Address , ModuleDef , TableDesc } ;
9- use spacetimedb_vm:: expr:: CrudExpr ;
9+ use spacetimedb_vm:: expr:: { CrudExpr , SourceSet } ;
1010
1111use super :: instrumentation:: CallTimes ;
1212use crate :: database_instance_context:: DatabaseInstanceContext ;
@@ -268,8 +268,9 @@ impl<T: WasmModule> Module for WasmModuleHostActor<T> {
268268 let auth = AuthCtx :: new ( self . database_instance_context . identity , caller_identity) ;
269269 log:: debug!( "One-off query: {query}" ) ;
270270 let ctx = & ExecutionContext :: sql ( db. address ( ) ) ;
271- let compiled = db. with_read_only ( ctx, |tx| {
272- sql:: compiler:: compile_sql ( db, tx, & query) ?
271+ let ( compiled, mut sources) : ( Vec < _ > , Box < SourceSet > ) = db. with_read_only ( ctx, |tx| {
272+ let ( ast, sources) = sql:: compiler:: compile_sql_merge_sources ( db, tx, & query) ?;
273+ let compiled = ast
273274 . into_iter ( )
274275 . map ( |expr| {
275276 if matches ! ( expr, CrudExpr :: Query { .. } ) {
@@ -278,10 +279,11 @@ impl<T: WasmModule> Module for WasmModuleHostActor<T> {
278279 Err ( anyhow ! ( "One-off queries are not allowed to modify the database" ) )
279280 }
280281 } )
281- . collect :: < Result < _ , _ > > ( )
282+ . collect :: < Result < _ , _ > > ( ) ?;
283+ Ok :: < _ , DBError > ( ( compiled, sources) )
282284 } ) ?;
283285
284- sql:: execute:: execute_sql ( db, compiled, auth)
286+ sql:: execute:: execute_sql ( db, compiled, auth, & mut sources )
285287 }
286288
287289 fn clear_table ( & self , table_name : String ) -> Result < ( ) , anyhow:: Error > {
0 commit comments