Search Postgresql Archives

What is the correct way to get the content of a varchar field in pgsql's source code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux