Hi all,
I've learnt from the source code to open a table and scan it, like this:
Relation qma = try_relation_open(qmappersta, AccessShareLock);
if(qma!=NULL){
HeapScanDesc scan= heap_beginscan(qma,SnapshotNow,0,NULL);
HeapTuple tup;
TupleDesc tupDesc= RelationGetDescr(qma);
Datum *values;
bool *nulls;
int value1;
char value2;
while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL){
heap_deform_tuple(tup,tupDesc,values, nulls);
/* int values can be retrieved easily */
value1=values[0];
/* how to retrieve the content of a varchar field here? */
/* What I've tried: */
value2=VARDATA_ANY(values[2]);
/* But value2 seems to be incorrect
if the original data is "abcd", then I will get "abcd2" here(in most cases, a "2" is appended to the data...), I'm wondering how to get the data properly...
I've also tried VARDATA macro and encountered with the same problem.
*/
}
}
Thanks!