@@ -388,7 +388,7 @@ impl<S: Storage> Database<S> {
388388 . with_sql_context ( sql) ) ;
389389 }
390390
391- let _guard = if has_ddl {
391+ let guard = if has_ddl {
392392 MetaDataLock :: Write ( self . mdl . write_arc ( ) )
393393 } else {
394394 MetaDataLock :: Read ( self . mdl . read_arc ( ) )
@@ -417,7 +417,11 @@ impl<S: Storage> Database<S> {
417417 }
418418 } else {
419419 let inner = Box :: into_raw ( Box :: new ( TransactionIter :: new ( schema, executor) ) ) ;
420- return Ok ( DatabaseIter { transaction, inner } ) ;
420+ return Ok ( DatabaseIter {
421+ transaction,
422+ inner,
423+ _guard : guard,
424+ } ) ;
421425 }
422426 }
423427
@@ -434,7 +438,7 @@ impl<S: Storage> Database<S> {
434438 statement : & Statement ,
435439 params : A ,
436440 ) -> Result < DatabaseIter < ' _ , S > , DatabaseError > {
437- let _guard = if matches ! ( command_type( statement) ?, CommandType :: DDL ) {
441+ let guard = if matches ! ( command_type( statement) ?, CommandType :: DDL ) {
438442 MetaDataLock :: Write ( self . mdl . write_arc ( ) )
439443 } else {
440444 MetaDataLock :: Read ( self . mdl . read_arc ( ) )
@@ -452,7 +456,11 @@ impl<S: Storage> Database<S> {
452456 }
453457 } ;
454458 let inner = Box :: into_raw ( Box :: new ( TransactionIter :: new ( schema, executor) ) ) ;
455- Ok ( DatabaseIter { transaction, inner } )
459+ Ok ( DatabaseIter {
460+ transaction,
461+ inner,
462+ _guard : guard,
463+ } )
456464 }
457465
458466 pub fn new_transaction ( & self ) -> Result < DBTransaction < ' _ , S > , DatabaseError > {
@@ -477,6 +485,7 @@ pub trait ResultIter: Iterator<Item = Result<Tuple, DatabaseError>> {
477485pub struct DatabaseIter < ' a , S : Storage + ' a > {
478486 transaction : * mut S :: TransactionType < ' a > ,
479487 inner : * mut TransactionIter < ' a > ,
488+ _guard : MetaDataLock ,
480489}
481490
482491impl < S : Storage > Drop for DatabaseIter < ' _ , S > {
0 commit comments