@@ -257,33 +257,6 @@ void delete_single_record_static()
257257 * next record cannot be found.
258258 */
259259void delete_all_records ()
260- {
261- PRINT_METHOD_NAME ();
262- doctor_t dr_house =
doctor_t::get (
doctor_t::insert_row (
" Dr. House" ,
" [email protected] " ));
263- doctor_t dr_dorian =
doctor_t::get (
doctor_t::insert_row (
" Dr. Dorian" ,
" [email protected] " ));
264- doctor_t dr_reid =
doctor_t::get (
doctor_t::insert_row (
" Dr. Reid" ,
" [email protected] " ));
265-
266- // This approach doesn't work, it will remove only one element.
267- // for (auto& doctor : doctor_t::list())
268- // {
269- // doctor.delete_row();
270- // }
271-
272- // The following is an approach that works to delete all the records:
273- for (auto doctor = *doctor_t::list ().begin ();
274- doctor;
275- doctor = *doctor_t::list ().begin ())
276- {
277- doctor.delete_row ();
278- }
279-
280- gaia_log::app ().info (" Doctors count: {}" , doctor_t::list ().size ());
281- }
282-
283- /* *
284- * Another way to delete all of the records is to use an iterator.
285- */
286- void delete_all_records_iter ()
287260{
288261 PRINT_METHOD_NAME ();
289262
@@ -295,7 +268,7 @@ void delete_all_records_iter()
295268 doctor_it != doctor_t::list ().end ();)
296269 {
297270 auto next_doctor_it = doctor_it++;
298- (* next_doctor_it). delete_row ();
271+ next_doctor_it-> delete_row ();
299272 }
300273
301274 gaia_log::app ().info (" Doctors count: {}" , doctor_t::list ().size ());
@@ -800,24 +773,27 @@ void use_dac_object_across_transactions()
800773 */
801774void clean_db ()
802775{
803- for (auto doctor = * doctor_t::list ().begin ();
804- doctor; doctor = * doctor_t::list ().begin () )
776+ for (auto doctor_it = doctor_t::list ().begin ();
777+ doctor_it != doctor_t::list ().end (); )
805778 {
806- doctor.patients ().clear ();
807- doctor.delete_row ();
779+ auto next_doctor_it = doctor_it++;
780+ next_doctor_it->patients ().clear ();
781+ next_doctor_it->delete_row ();
808782 }
809783
810- for (auto patient = * patient_t::list ().begin ();
811- patient; patient = * patient_t::list ().begin () )
784+ for (auto patient_it = patient_t::list ().begin ();
785+ patient_it != patient_t::list ().end (); )
812786 {
813- patient.address ().disconnect ();
814- patient.delete_row ();
787+ auto next_patient_it = patient_it++;
788+ next_patient_it->address ().disconnect ();
789+ next_patient_it->delete_row ();
815790 }
816791
817- for (auto address = * address_t::list ().begin ();
818- address; address = * address_t::list ().begin () )
792+ for (auto address_it = address_t::list ().begin ();
793+ address_it != address_t::list ().end (); )
819794 {
820- address.delete_row ();
795+ auto next_address_it = address_it++;
796+ next_address_it->delete_row ();
821797 }
822798}
823799
@@ -844,7 +820,6 @@ int main()
844820 delete_single_record ();
845821 delete_single_record_static ();
846822 delete_all_records ();
847- delete_all_records_iter ();
848823 gaia_id_t doctor_id = create_one_to_many_relationship ();
849824 traverse_one_to_many_relationship (doctor_id);
850825 delete_one_to_many_relationship_re (doctor_id);
0 commit comments