PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int DBFWriteAttribute ( DBFHandle  psDBF,
int  hEntity,
int  iField,
void *  pValue 
)
static

Definition at line 1267 of file dbfopen.c.

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

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

1270 {
1271  int i, j, nRetResult = TRUE;
1272  unsigned char *pabyRec;
1273  char szSField[400], szFormat[20];
1274 
1275 /* -------------------------------------------------------------------- */
1276 /* Is this a valid record? */
1277 /* -------------------------------------------------------------------- */
1278  if( hEntity < 0 || hEntity > psDBF->nRecords )
1279  return( FALSE );
1280 
1281  if( psDBF->bNoHeader )
1282  DBFWriteHeader(psDBF);
1283 
1284 /* -------------------------------------------------------------------- */
1285 /* Is this a brand new record? */
1286 /* -------------------------------------------------------------------- */
1287  if( hEntity == psDBF->nRecords )
1288  {
1289  if( !DBFFlushRecord( psDBF ) )
1290  return FALSE;
1291 
1292  psDBF->nRecords++;
1293  for( i = 0; i < psDBF->nRecordLength; i++ )
1294  psDBF->pszCurrentRecord[i] = ' ';
1295 
1296  psDBF->nCurrentRecord = hEntity;
1297  }
1298 
1299 /* -------------------------------------------------------------------- */
1300 /* Is this an existing record, but different than the last one */
1301 /* we accessed? */
1302 /* -------------------------------------------------------------------- */
1303  if( !DBFLoadRecord( psDBF, hEntity ) )
1304  return FALSE;
1305 
1306  pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
1307 
1308  psDBF->bCurrentRecordModified = TRUE;
1309  psDBF->bUpdated = TRUE;
1310 
1311 /* -------------------------------------------------------------------- */
1312 /* Translate NULL value to valid DBF file representation. */
1313 /* */
1314 /* Contributed by Jim Matthews. */
1315 /* -------------------------------------------------------------------- */
1316  if( pValue == NULL )
1317  {
1318  memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]),
1319  DBFGetNullCharacter(psDBF->pachFieldType[iField]),
1320  psDBF->panFieldSize[iField] );
1321  return TRUE;
1322  }
1323 
1324 /* -------------------------------------------------------------------- */
1325 /* Assign all the record fields. */
1326 /* -------------------------------------------------------------------- */
1327  switch( psDBF->pachFieldType[iField] )
1328  {
1329  case 'D':
1330  case 'N':
1331  case 'F':
1332  if( psDBF->panFieldDecimals[iField] == 0 )
1333  {
1334  int nWidth = psDBF->panFieldSize[iField];
1335 
1336  if( (int) sizeof(szSField)-2 < nWidth )
1337  nWidth = sizeof(szSField)-2;
1338 
1339  sprintf( szFormat, "%%%dd", nWidth );
1340  sprintf(szSField, szFormat, (int) *((double *) pValue) );
1341  if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )
1342  {
1343  szSField[psDBF->panFieldSize[iField]] = '\0';
1344  nRetResult = FALSE;
1345  }
1346 
1347  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1348  szSField, strlen(szSField) );
1349  }
1350  else
1351  {
1352  int nWidth = psDBF->panFieldSize[iField];
1353 
1354  if( (int) sizeof(szSField)-2 < nWidth )
1355  nWidth = sizeof(szSField)-2;
1356 
1357  sprintf( szFormat, "%%%d.%df",
1358  nWidth, psDBF->panFieldDecimals[iField] );
1359  sprintf(szSField, szFormat, *((double *) pValue) );
1360  if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )
1361  {
1362  szSField[psDBF->panFieldSize[iField]] = '\0';
1363  nRetResult = FALSE;
1364  }
1365  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1366  szSField, strlen(szSField) );
1367  }
1368  break;
1369 
1370  case 'L':
1371  if (psDBF->panFieldSize[iField] >= 1 &&
1372  (*(char*)pValue == 'F' || *(char*)pValue == 'T'))
1373  *(pabyRec+psDBF->panFieldOffset[iField]) = *(char*)pValue;
1374  break;
1375 
1376  default:
1377  if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )
1378  {
1379  j = psDBF->panFieldSize[iField];
1380  nRetResult = FALSE;
1381  }
1382  else
1383  {
1384  memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
1385  psDBF->panFieldSize[iField] );
1386  j = strlen((char *) pValue);
1387  }
1388 
1389  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1390  (char *) pValue, j );
1391  break;
1392  }
1393 
1394  return( nRetResult );
1395 }
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition: dbfopen.c:291
static void DBFWriteHeader(DBFHandle psDBF)
Definition: dbfopen.c:197
static int DBFFlushRecord(DBFHandle psDBF)
Definition: dbfopen.c:258
#define FALSE
Definition: dbfopen.c:168
static char DBFGetNullCharacter(char chType)
Definition: dbfopen.c:792
#define TRUE
Definition: dbfopen.c:169

Here is the call graph for this function:

Here is the caller graph for this function: