PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ DBFWriteAttribute()

static int DBFWriteAttribute ( DBFHandle  psDBF,
int  hEntity,
int  iField,
void *  pValue 
)
static

Definition at line 1235 of file dbfopen.c.

1236{
1237 int i, j, nRetResult = TRUE;
1238 unsigned char *pabyRec;
1239 char szSField[400], szFormat[20];
1240
1241 /* -------------------------------------------------------------------- */
1242 /* Is this a valid record? */
1243 /* -------------------------------------------------------------------- */
1244 if (hEntity < 0 || hEntity > psDBF->nRecords)
1245 return (FALSE);
1246
1247 if (psDBF->bNoHeader)
1248 DBFWriteHeader(psDBF);
1249
1250 /* -------------------------------------------------------------------- */
1251 /* Is this a brand new record? */
1252 /* -------------------------------------------------------------------- */
1253 if (hEntity == psDBF->nRecords)
1254 {
1255 if (!DBFFlushRecord(psDBF))
1256 return FALSE;
1257
1258 psDBF->nRecords++;
1259 for (i = 0; i < psDBF->nRecordLength; i++)
1260 psDBF->pszCurrentRecord[i] = ' ';
1261
1262 psDBF->nCurrentRecord = hEntity;
1263 }
1264
1265 /* -------------------------------------------------------------------- */
1266 /* Is this an existing record, but different than the last one */
1267 /* we accessed? */
1268 /* -------------------------------------------------------------------- */
1269 if (!DBFLoadRecord(psDBF, hEntity))
1270 return FALSE;
1271
1272 pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
1273
1274 psDBF->bCurrentRecordModified = TRUE;
1275 psDBF->bUpdated = TRUE;
1276
1277 /* -------------------------------------------------------------------- */
1278 /* Translate NULL value to valid DBF file representation. */
1279 /* */
1280 /* Contributed by Jim Matthews. */
1281 /* -------------------------------------------------------------------- */
1282 if (pValue == NULL)
1283 {
1284 memset((char *)(pabyRec + psDBF->panFieldOffset[iField]),
1285 DBFGetNullCharacter(psDBF->pachFieldType[iField]),
1286 psDBF->panFieldSize[iField]);
1287 return TRUE;
1288 }
1289
1290 /* -------------------------------------------------------------------- */
1291 /* Assign all the record fields. */
1292 /* -------------------------------------------------------------------- */
1293 switch (psDBF->pachFieldType[iField])
1294 {
1295 case 'D':
1296 case 'N':
1297 case 'F':
1298 if (psDBF->panFieldDecimals[iField] == 0)
1299 {
1300 int nWidth = psDBF->panFieldSize[iField];
1301
1302 if ((int)sizeof(szSField) - 2 < nWidth)
1303 nWidth = sizeof(szSField) - 2;
1304
1305 sprintf(szFormat, "%%%dd", nWidth);
1306 sprintf(szSField, szFormat, (int)*((double *)pValue));
1307 if ((int)strlen(szSField) > psDBF->panFieldSize[iField])
1308 {
1309 szSField[psDBF->panFieldSize[iField]] = '\0';
1310 nRetResult = FALSE;
1311 }
1312 memcpy(
1313 (char *)(pabyRec + psDBF->panFieldOffset[iField]), szSField, psDBF->panFieldSize[iField]);
1314 }
1315 else
1316 {
1317 int nWidth = psDBF->panFieldSize[iField];
1318
1319 if ((int)sizeof(szSField) - 2 < nWidth)
1320 nWidth = sizeof(szSField) - 2;
1321
1322 sprintf(szFormat, "%%%d.%df", nWidth, psDBF->panFieldDecimals[iField]);
1323 sprintf(szSField, szFormat, *((double *)pValue));
1324 if ((int)strlen(szSField) > psDBF->panFieldSize[iField])
1325 {
1326 szSField[psDBF->panFieldSize[iField]] = '\0';
1327 nRetResult = FALSE;
1328 }
1329 memcpy(
1330 (char *)(pabyRec + psDBF->panFieldOffset[iField]), szSField, psDBF->panFieldSize[iField]);
1331 }
1332 break;
1333
1334 case 'L':
1335 if (psDBF->panFieldSize[iField] >= 1 && (*(char *)pValue == 'F' || *(char *)pValue == 'T'))
1336 *(pabyRec + psDBF->panFieldOffset[iField]) = *(char *)pValue;
1337 break;
1338
1339 default:
1340 if ((int)strlen((char *)pValue) > psDBF->panFieldSize[iField])
1341 {
1342 j = psDBF->panFieldSize[iField];
1343 nRetResult = FALSE;
1344 }
1345 else
1346 {
1347 memset(pabyRec + psDBF->panFieldOffset[iField], ' ', psDBF->panFieldSize[iField]);
1348 j = strlen((char *)pValue);
1349 }
1350 memcpy((char *)(pabyRec + psDBF->panFieldOffset[iField]), (char *)pValue, j);
1351 break;
1352 }
1353
1354 return nRetResult;
1355}
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition dbfopen.c:286
static void DBFWriteHeader(DBFHandle psDBF)
Definition dbfopen.c:198
#define TRUE
Definition dbfopen.c:169
#define FALSE
Definition dbfopen.c:168
static char DBFGetNullCharacter(char chType)
Definition dbfopen.c:778
static int DBFFlushRecord(DBFHandle psDBF)
Definition dbfopen.c:258

References DBFFlushRecord(), DBFGetNullCharacter(), DBFLoadRecord(), DBFWriteHeader(), FALSE, and TRUE.

Referenced by DBFWriteDoubleAttribute(), DBFWriteIntegerAttribute(), DBFWriteLogicalAttribute(), DBFWriteNULLAttribute(), and DBFWriteStringAttribute().

Here is the call graph for this function:
Here is the caller graph for this function: