| 1145 | /************************************************************************/ |
| 1146 | |
| 1147 | static char **CSVScanFile(CSVTable *const psTable, int iKeyField, |
| 1148 | const char *pszValue, CSVCompareCriteria eCriteria) |
| 1149 | { |
| 1150 | CSVIngest(psTable->pszFilename); |
| 1151 | |
| 1152 | /* -------------------------------------------------------------------- */ |
| 1153 | /* Does the current record match the criteria? If so, just */ |
| 1154 | /* return it again. */ |
| 1155 | /* -------------------------------------------------------------------- */ |
| 1156 | if (iKeyField >= 0 && iKeyField < CSLCount(psTable->papszRecFields) && |
| 1157 | CSVCompare(psTable->papszRecFields[iKeyField], pszValue, eCriteria) && |
| 1158 | !psTable->bNonUniqueKey) |
| 1159 | { |
| 1160 | return psTable->papszRecFields; |
| 1161 | } |
| 1162 | |
| 1163 | /* -------------------------------------------------------------------- */ |
| 1164 | /* Scan the file from the beginning, replacing the ``current */ |
| 1165 | /* record'' in our structure with the one that is found. */ |
| 1166 | /* -------------------------------------------------------------------- */ |
| 1167 | psTable->iLastLine = -1; |
| 1168 | CSLDestroy(psTable->papszRecFields); |
| 1169 | |
| 1170 | if (psTable->pszRawData != nullptr) |
| 1171 | psTable->papszRecFields = |
| 1172 | CSVScanLinesIngested(psTable, iKeyField, pszValue, eCriteria); |
| 1173 | else |
| 1174 | { |
| 1175 | VSIRewindL(psTable->fp); |
| 1176 | CPLReadLineL(psTable->fp); /* throw away the header line */ |
| 1177 | |
| 1178 | psTable->papszRecFields = |
| 1179 | CSVScanLinesL(psTable->fp, iKeyField, pszValue, eCriteria); |
| 1180 | } |
| 1181 | |
| 1182 | return psTable->papszRecFields; |
| 1183 | } |
| 1184 | |
| 1185 | char **CSVScanFile(const char *pszFilename, int iKeyField, const char *pszValue, |
| 1186 | CSVCompareCriteria eCriteria) |
no test coverage detected