Search code examples
ckdb

How to access date and varbinary from KDB+ in C api


Having trouble to get date and varbinary values in C program from KDB database. K (3.2t 2004-06-03)

types:  
date = `date  
col1 = `varbinary

query:

select date, col1 from table1 where date='1993-01-04'

result in K shell:

.((`date
,-15337
.,(`T;`date;))
(`col1
,"000  00010"
 ))

Result in C:

int date = KI(KK(kData)[0])[i];//date=-15337.
col1=KI(KK(kData)[1])[i];  //col1=8394164

Question: How do I convert -15337 to '1993-01-04'? It is before kdb epoch... Question: How do I get actual varbinary "000 00010" from the result?

Thank you very much.


Solution

  • I have found answers, Thank for responding user3629249

    to access date use dj function

     cout << dj(KI(KK(kData)[0])[i]);
    

    produces 19930104

    access var binary as list.

    K col1Data = KK(KK(kData)[6])[i];
    int col1_size = col1Data->n;
    for( int j=0; j<col1_size; j++ )
        cout << KC(col1Data)[j];
    

    produces "000 00010"