GetAllRecordsByNearKey |
Databases | |
Aptilis 1 |
GetAllRecordsByNearKey(dbDest[], dbSrc[], key, keypos)
GetAllRecordsByNearKey will extract records from a database (dbSrc)
into a new one (dbDest) according to a criteria specified by you.
This criteria is a field specified by 'key' in the column 'keypos'.
Because it's a 'near' search, the criteria doesn't need to match
a field precisely for a record to be copied into the new database.
For example, if you do a search on "bl*" for a field containing the
colour of a car, then you will get all cars which colours are:
"Blue", "Black". (I can't think of any other colour starting with 'bl')
GetAllRecordsByNearKey is not case sensitive.
You read and write databases from/to files with loadDatabase and saveDatabase respectively.
If you want to do an exact search use GetAllRecordsByKey.
GetRecordIndexByKey and GetRecordIndexByNearKey are more low-level and only retrieve the index of one record at a time.
Return value:
The number of record(s) retrieved.
Example
Retrieving the creepy-crawlies...
sub main db[0] = makeRecord("chien","dog","1","mammal") $ db[1] = makeRecord("chat","cat","2","mammal") $ db[2] = makeRecord("poisson","fish","3","vertebrate") $ db[3] = makeRecord("escargot","snail","4","invertebrate") $ db[4] = makeRecord("souris","mouse","5","mammal") $ db[5] = makeRecord("perroquet","parrot","6","bird") $ db[6] = makeRecord("dauphin","dolphin","7","mammal") $ db[7] = makeRecord("fleur","flower","8","plant") $ n = GetAllRecordsByNearKey(newDb[], db[], "*brate", 3) print("Found: ", n, " records\n") for i=0 to n-1 getAllFields(fl[], newDb[i]$) print(fl[1]$, " ", fl[3]$, "\n") end for end mainResult:
Found: 2.000000 records fish vertebrate snail invertebrate |
Examples
To do an aproximate search, use the special characters
'?' for any one letter, and '*' for any group of letter.
"blue" | will match 'blue', exactly. |
"f*" | All fields begining with 'f'. |
"*i" | All fields ending with 'i'. |
"*a*" | All fields containing the letter 'a'. |
"?ree" | All words of any first letter ending in 'ree', like 'tree' or 'free'. |
"*a" | Anything ending with the letter a, like 'ha' or 'armada' |
etc... |
The patterns used by 'GetAllRecordsByNearKey' are exactly the same as
the ones used by Match.
There is a limited support for fixed length field databases through
getFixedLengthField
and
makeFixedLengthField.