what's difference of "/Name/1/Value" and "Name/1/Value" in set/get name field content? | developer.brewmp.com what's difference of "/Name/1/Value" and "Name/1/Value" in set/get name field content? | developer.brewmp.com

Developer

what's difference of "/Name/1/Value" and "Name/1/Value" in set/get name field content?

Forums:

i want to get the firstname of one record exised in db,which of the right format to use in the following function?

the first is :

pim_IContactsRecord_GetFieldValue(pRecord, "/Name/1/Value", wszWrkBuf, MAX_CHAR_ARRAY_SIZE, &nLenReq);

 

the second is :

pim_IContactsRecord_GetFieldValue(pRecord, "Name/1/Value", wszWrkBuf, MAX_CHAR_ARRAY_SIZE, &nLenReq);

 

what's differency of them?

it should be Name/1/Value or the format in which it was stored initially.

it should be Name/1/Value or the format in which it was stored initially.

Hi Nana,
"Name/1/Type" contains the type of the name sub-field and will contain one of pim_XXXX_NameType_XXXX values. For EFS contacts, the values are pim_EFSDBDevice_NameType_XXXX as defined in pim_EFSDBDevice.bid. Whereas "Name/1/Value" contains the value being stored for the "Name/1/Type".
For example, consider the below code lines:
pim_IContactsRecord_SetFieldValue(pRecord, "Name/1/Type", pim_EFSDBDevice_NameType_FirstName);
pim_IContactsRecord_SetFieldValue(pRecord, "Name/1/Value", L"FirstnameTesting");
 
The name type stored at index 1 is FIRSTNAME and the value assigned to FIRSTNAME is "FirstnameTesting" i.e. this record has "FirstnameTesting" as it's FIRSTNAME.
Kindly note that the field instance numbers (like the 1 mentioned in Name/1/Value) are arbitary and pim_IContacts interface does NOT assure or guarantee that the field instance number is going to be the same for that field. As such, it is recommended to first check for the "Name//Type" and then retrieve the corresponding "Name//Value". Note that it is the developer's or the application's responsibility to take care of this recommendation.
Below is the code snippet that would retrive the FIRSTNAME value from a given record (pRecord):
/* Assumption:: pRecord is a valid record pointer */
void GetFirstname(pim_IContactsRecord *pRecord)
{
AEEResult nErr;
int nNumFields;
int i;

/* Find the Number of Name fields present in this record */
nErr = pim_IContactsRecord_GetNumChildren(pRecord, "Name/", &nNumFields);
if(AEE_SUCCESS != nErr)
{
DBGPRINTF("Failed to GetNumChildren [%d]", nErr);
return;
}

/* Get the Types of the fields present in this record */
for(i=1; i<=nNumFields; i++)
{
char szFieldUriBuf[16] = {0};
AECHAR *pszFieldTypeBuf = NULL;
int nBufLenReq, nBufLen = 0;

/* Form the URI to be checked */
SNPRINTF(szFieldUriBuf, sizeof(szFieldUriBuf), "Name/%d/Type", i);

/* Get the buffer required for Field Type */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldTypeBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 1 failed [%d]", szFieldUriBuf, nErr);
return;
}

/* Allocate the memory */
pszFieldTypeBuf = (AECHAR *)MALLOC(nBufLenReq * sizeof(AECHAR));
if(NULL == pszFieldTypeBuf)
{
/* Do error handling & return */
DBGPRINTF("%s Memory allocation failed", szFieldUriBuf);
return;
}
nBufLen = nBufLenReq;

/* Get the field Type */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldTypeBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling & return */
DBGPRINTF("%s GetFieldValue 2 failed [%d]", szFieldUriBuf, nErr);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}

/* Check if it's the FIRST NAME */
if(0 == WSTRCMP(pszFieldTypeBuf, pim_EFSDBDevice_NameType_FirstName))
{
/* FIRSTNAME index is found, now retrieve it's value */
AECHAR *pszFieldValueBuf = NULL;
nBufLen = 0;

/* Form the URI to be checked */
SNPRINTF(szFieldUriBuf, sizeof(szFieldUriBuf), "Name/%d/Value", i);

/* Get the buffer required for Field Type */
nErr = pim_IContactsRecord_GetFieldValue(pRecord, szFieldUriBuf, pszFieldValueBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 1 failed [%d]", szFieldUriBuf, nErr);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}

/* Allocate the memory */
pszFieldValueBuf = (AECHAR *)MALLOC(nBufLenReq * sizeof(AECHAR));
if(NULL == pszFieldValueBuf)
{
/* Do error handling & return */
DBGPRINTF("%s Memory allocation failed", szFieldUriBuf);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}
nBufLen = nBufLenReq;

/* Get the field Name */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldValueBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 2 failed [%d]", szFieldUriBuf, nErr);
}
else
{
/* FIRSTNAME is retrieved, do the needful */
DBGPRINTF("FIRSTNAME as [%s] ==> [%S]", szFieldUriBuf, pszFieldValueBuf);
}

/* Release the allocated memories before leaving */
FREE(pszFieldValueBuf);
FREE(pszFieldTypeBuf);
return;
}
else
{
/* Release the Field Type buffer & go to next index */
FREE(pszFieldTypeBuf);

} /* End of if WSTRCMP */

} /* End of for loop */

/* If reached here, it means FIRSTNAME is not present in this record */

return;
For more information about usage of this interface, kindly refer to the PIM Technology Guide (https://developer.brewmp.com/resources/tech-guides/pim-technology-guide) and the sample code c_contactsapp.zip available at Brew MP website.
Regards,
Suresh Kumar S

Hi Nana,
"Name/1/Type" contains the type of the name sub-field and will contain one of pim_XXXX_NameType_XXXX values. For EFS contacts, the values are pim_EFSDBDevice_NameType_XXXX as defined in pim_EFSDBDevice.bid. Whereas "Name/1/Value" contains the value being stored for the "Name/1/Type".
For example, consider the below code lines:
pim_IContactsRecord_SetFieldValue(pRecord, "Name/1/Type", pim_EFSDBDevice_NameType_FirstName);
pim_IContactsRecord_SetFieldValue(pRecord, "Name/1/Value", L"FirstnameTesting");
 
The name type stored at index 1 is FIRSTNAME and the value assigned to FIRSTNAME is "FirstnameTesting" i.e. this record has "FirstnameTesting" as it's FIRSTNAME.
Kindly note that the field instance numbers (like the 1 mentioned in Name/1/Value) are arbitary and pim_IContacts interface does NOT assure or guarantee that the field instance number is going to be the same for that field. As such, it is recommended to first check for the "Name//Type" and then retrieve the corresponding "Name//Value". Note that it is the developer's or the application's responsibility to take care of this recommendation.
Below is the code snippet that would retrive the FIRSTNAME value from a given record (pRecord):
/* Assumption:: pRecord is a valid record pointer */
void GetFirstname(pim_IContactsRecord *pRecord)
{
AEEResult nErr;
int nNumFields;
int i;

/* Find the Number of Name fields present in this record */
nErr = pim_IContactsRecord_GetNumChildren(pRecord, "Name/", &nNumFields);
if(AEE_SUCCESS != nErr)
{
DBGPRINTF("Failed to GetNumChildren [%d]", nErr);
return;
}

/* Get the Types of the fields present in this record */
for(i=1; i<=nNumFields; i++)
{
char szFieldUriBuf[16] = {0};
AECHAR *pszFieldTypeBuf = NULL;
int nBufLenReq, nBufLen = 0;

/* Form the URI to be checked */
SNPRINTF(szFieldUriBuf, sizeof(szFieldUriBuf), "Name/%d/Type", i);

/* Get the buffer required for Field Type */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldTypeBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 1 failed [%d]", szFieldUriBuf, nErr);
return;
}

/* Allocate the memory */
pszFieldTypeBuf = (AECHAR *)MALLOC(nBufLenReq * sizeof(AECHAR));
if(NULL == pszFieldTypeBuf)
{
/* Do error handling & return */
DBGPRINTF("%s Memory allocation failed", szFieldUriBuf);
return;
}
nBufLen = nBufLenReq;

/* Get the field Type */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldTypeBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling & return */
DBGPRINTF("%s GetFieldValue 2 failed [%d]", szFieldUriBuf, nErr);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}

/* Check if it's the FIRST NAME */
if(0 == WSTRCMP(pszFieldTypeBuf, pim_EFSDBDevice_NameType_FirstName))
{
/* FIRSTNAME index is found, now retrieve it's value */
AECHAR *pszFieldValueBuf = NULL;
nBufLen = 0;

/* Form the URI to be checked */
SNPRINTF(szFieldUriBuf, sizeof(szFieldUriBuf), "Name/%d/Value", i);

/* Get the buffer required for Field Type */
nErr = pim_IContactsRecord_GetFieldValue(pRecord, szFieldUriBuf, pszFieldValueBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 1 failed [%d]", szFieldUriBuf, nErr);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}

/* Allocate the memory */
pszFieldValueBuf = (AECHAR *)MALLOC(nBufLenReq * sizeof(AECHAR));
if(NULL == pszFieldValueBuf)
{
/* Do error handling & return */
DBGPRINTF("%s Memory allocation failed", szFieldUriBuf);
/* Free the FieldTypeBuf */
FREE(pszFieldTypeBuf);
return;
}
nBufLen = nBufLenReq;

/* Get the field Name */
nErr = pim_IContactsRecord_GetFieldValue( pRecord, szFieldUriBuf, pszFieldValueBuf, nBufLen, &nBufLenReq);
if(AEE_SUCCESS != nErr)
{
/* Do error handling */
DBGPRINTF("%s GetFieldValue 2 failed [%d]", szFieldUriBuf, nErr);
}
else
{
/* FIRSTNAME is retrieved, do the needful */
DBGPRINTF("FIRSTNAME as [%s] ==> [%S]", szFieldUriBuf, pszFieldValueBuf);
}

/* Release the allocated memories before leaving */
FREE(pszFieldValueBuf);
FREE(pszFieldTypeBuf);
return;
}
else
{
/* Release the Field Type buffer & go to next index */
FREE(pszFieldTypeBuf);

} /* End of if WSTRCMP */

} /* End of for loop */

/* If reached here, it means FIRSTNAME is not present in this record */

return;
For more information about usage of this interface, kindly refer to the PIM Technology Guide (https://developer.brewmp.com/resources/tech-guides/pim-technology-guide) and the sample code c_contactsapp.zip available at Brew MP website.
Regards,
Suresh Kumar S