c++ - function with double mode of functionality -


i have function should have 2 modes of behaviour according place it's called from.

the core functionality insert table in database, has done in 2 different ways.

  1. normal mode: whenever it's called 1 time (outside of loop)

for example: //... myfunc(param1, record); // should insert single record database //...

  1. batch mode: whenever it's called inside of loop

for example:

    while(...){         myfunc(param1, record);       } 

inside "while" loop, each time it's called, should store record in list , when reaches end of loop, should fetch records list , prepare "batch" query inserts in 1 go.

i wondering how make detect it's called in order switch corresponding mode , how detect has reached end of loop , on, should start getting records list, prepare query , execute it.

any tips or suggestions highly appreciated!

thanks heaps!

it not, in general, possible tell whether being called in loop, full source code access.

you might able caching , delaying actual database insert limited time in cases. go on caching until go x microseconds without new call, , insert cached data.

however, give strange effects if not in control of accesses database. in particular, should cached inserts time there query might affected them, in loop.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -