Does anybody have an efficient way of counting records which does not involve counting each record one by one ?
Does anybody have an efficient way of counting records which does not involve counting each record one by one ?
It doesn't exist (yet).
See also the SM7 context.GenerateCount.
can you show us how you use rtecount in javascript??
I can't get mine to work
ex: rc1 = system.functions.rtecall("count",rc,filedoselected ,query,returnCount);
returnCount never gets affected.
You need to initialize your returnCount variable as an SCFile() type data.
Add this before your rtecall:
var returnCount = new SCFile()
You will also need to pass the count as an SCDatum so that the rtecall can recognize it. After the rtecall, you will need to then extract the information from the complex object:
HTH.Code:var inc = new SCFile( "probsummary" ); inc.doSelect( 'true' ); var c = new SCDatum(); var rc = new SCDatum(); var v = system.functions.rtecall( "count", rc, inc, "true", c ); print( c.getText() );
there is my solution:
query is up to you
"If" is not necessary but it working wellCode:function count( query ) { var count = 0; var attch = new SCFile("SYSATTACHMENTS"); var attchRec = attch.doSelect(query); if ( attchRec == RC_SUCCESS) do { count++; } while (attch.getNext() == RC_SUCCESS); //print("count= "+count); return count }
it used to count attachments as is declared, and it is usually 0-3, not 11000.
Do you thing that switching between javascript - RAD - javascript does not take time?
As was said counting like that requires scan of all the records (I have done the same mistake too).
Also as a count of attachments that script is wrong because one record in SYSATTACHMENTS does not necesarely equal one attachment! One attachment can consist of 1 to many records in that file.
Thank you all guys! I'm looking for the way of counting records without iterating for 2 years!
Some test info for 2500 records:
iterating: 6.42 seconds
rtecall: 0.04 seconds
Hi pfilaretov,
can you tell us how to calculate the time/seconds to perform the rquery ?
thanks,
Here you are:
Code:/** Get time in with milliseconds */ function getNowTimeString() { var now = new Date(); return now.toLocaleTimeString() + "." + now.getMilliseconds() + " "; } /** */ function testCountSpeed() { // "requests" is my own dbdict var incFile = new SCFile("requests"); // To get about 2500 records var query = "flag=true"; // RTECALL print(getNowTimeString() + "RTECALL - Starting..."); var returnCount = new SCDatum(); var rc = new SCDatum(); var rc2 = system.functions.rtecall("count", rc, incFile, query, returnCount); print(getNowTimeString() + "RTECALL - Count=" + returnCount.getText()); // ITERATING print(getNowTimeString() + "ITERATING - Starting..."); var rc3 = incFile.doSelect(query); var i = 0; while (rc3 == RC_SUCCESS) { i++; rc3 = incFile.getNext(); } print(getNowTimeString() + "ITERATING - Count=" + i); } testCountSpeed();
In 9.30 there is a new way of counting. Sligthly slower than rtecall but still significantly faster than looping and syntax a bit easier to remember that the rtecall.
115.000 records counter with this function took 188 milliseconds. Rtecall took 46 milliseconds.Code:function countRecords() { var fh = new SCFile("contacts"); var sql = "true"; var i = fh.doCount(sql); print("count: "+i); }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks