Steve said:
With your code, I got a RECCOUNT() of 4.
Okay, if you use VFP8 or lower it has no optimizaton of this sepcifi LIKE case with %. Also might depend on whether you have SET ANSI ON or OFF, but trry this instead:
Code:
Clear
Open Database _samples+"tastrade\data\tastrade.dbc"
Select * from customer where customer_id = 'ALFKI' into cursor alfki
? _tally
? Reccount()
Scan
? customer_id
endscan
If that's still returning reccount() of 1 I'd be interested what's going on with your tastrade database. It has an index on customer_Öid that makes that query fully optimizable which is why the result cursor becomes a filter cursor, and then reccount() will be the reccount of the customer.dbf not the _tally of the query.
I'm just posting this for future readers, Steve, I know I convinced you, but whoever is gettnig the idea _tally is unreliable would perhaps - wrongly - jump on the wagon to use reccount(). You can also rely on reccount when you use the NOFILTER or READWRITE keyword for queries, especially since the result cursor also is the selected workarea directly after the query.
And you can fail with anything you use, if you use _tally not directly after a query but after doing any further command listed in the hackers guide that also sets _tally, you have that new count, not the one related to the query. If you use reccount() on a filter cursor or after you select another workarea, reccount() itself won't give you the resultcount, reccount('resultcursoraliasname'), will. But as also mentioned once you addd records to the result cursor that obviously also doesn't reflect the query result count.
And all of that is obviously okay, because that's what reccount() should deliver, if the cursor has more records, it should givce that, and if you use reccount() to reflect that, not only directly afte the query, then reccount() is the right choice.
There's no war between what to avoid or use, just be cautious of the special cases, if you're like someone not knowing how things work and not eager to lookup and take for granted that VARTYPE reflects whether a result hs rows or not, then you don't become aqware that this sepcific VARTYPE checks the existence or nonexiystance of the array. And when you make sure the array doesn't exist before the query runs, you can use that VARTPE check. But if you want to learn something for universal usage, then _tally is the best as it does nother depend on whether a result is a cursor, an array, a new DBGF file or ahtever else I forgot could be a possible result. And you can slo use _tally after updates and such things where knowing the recccount() wouldn't tell you how many rows are changed.
So that makes _tally a solution to keep in mind when you like a general solution. I personally prefer thinking about each individual case. Some would say this makes them slow, I say it keeps me alert and once you know more and more this also isn't the time consuming task you think it is. I'd never just rely on a ruleset, but if you're that kind of programmer or hobbyist, then the general rule I'd guarantee works universalle is using _tally, even though it has gotchas others than maybe under some circumstances being wrong.
I just see people using code they don't understand and rely on it, which often makes it non universal and transferring it to a similar but not equal case then fails on not knowing the details. I can only compare this to copying a paragraph of chinese. If I only know the whole translation of it, I'd still not be able to guess what each single glyph or word means. That's what I see is the state of many developers, even though the programming languages somewhat still lean on english words.
So I'm just after this so rigorously, as I don't want someones "vocabulary" being spoiled ba something that bears no direct relationship to what was asked. The question is how to determine whether a query has results, not whether an array exists, and _tally=0 is the case of no result. vartype('cursorname')='U' would also be true, if the reccount() of it is >0.
Now you may accuse me of thinking too bad about the ability of people to understand things, but my experience here is many things sink in very slow for some members, here. It's not phenomenon limitd to one or two, only.
Chriss