@@ -244,6 +244,23 @@ alasql.exec = function (sql, params, cb, scope) {
244244 }
245245} ;
246246
247+ /**
248+ * Clears any unneeded properties from a given AST statement closure used for caching
249+ * @param {Object } statement the statement to cleanup
250+ */
251+ function cleanupCache ( statement ) {
252+ if ( ! statement ) {
253+ return ;
254+ }
255+ if ( ! alasql . options . cache ) {
256+ return ;
257+ }
258+ // cleanup the table data to prevent storing this information in the SQL cache
259+ if ( statement && statement . query && statement . query . data ) {
260+ statement . query . data = [ ] ;
261+ }
262+ }
263+
247264/**
248265 Run SQL statement on specific database
249266 */
@@ -259,7 +276,9 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
259276 let statement = db . sqlCache [ hh ] ;
260277 // If database structure was not changed since last time return cache
261278 if ( statement && db . dbversion === statement . dbversion ) {
262- return statement ( params , cb ) ;
279+ var res = statement ( params , cb ) ;
280+ cleanupCache ( statement ) ;
281+ return res ;
263282 }
264283 }
265284
@@ -302,6 +321,7 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
302321 db . sqlCache [ hh ] = statement ;
303322 }
304323 var res = ( alasql . res = statement ( params , cb , scope ) ) ;
324+ cleanupCache ( statement ) ;
305325 return res ;
306326 }
307327 alasql . precompile ( ast . statements [ 0 ] , alasql . useid , params ) ;
0 commit comments