Extracting row values using C++ code

Received: by 10.151.101.20 with SMTP id d20mr364882ybm.21.1228817991812; Tue,
09 Dec 2008 02:19:51 -0800 (PST)
Date: Tue, 9 Dec 2008 02:19:51 -0800 (PST)
X-IP: 171.161.56.16
User-Agent: G2/1.0
X-Google-Token: -jWxnwwAAAAx8wUrmYuSh8cSvWc0700A
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
InfoPath.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET
CLR 3.0.04506.30; MS-RTC LM 8; MS-RTC S; .NET CLR 3.0.04506.648; .NET CLR
3.5.21022),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 mumkcnc1 (NetCache NetApp/6.0.1P3), 1.1 hk2-inetcache1
(NetCache NetApp/6.0.2P1D1)
Message-ID: <046ee361-d2fc-4c93-9601-34bb0694616e@w39g2000prb.googlegroups.com>
Subject: Extracting row values using C++ code
From: Nav <nav.andraste>
To: “Kdb+ Personal Developers”
X-Google-Approved: charlie@kx.com via web at 2008-12-09 20:27:53

Hi,

Assume a table called ‘trade’ having the followiing schema :

Sym| Time| Price |Size|Ex

Assume Sym is the primary key.

Suppose there is a query q which returns ‘n’ no. of rows

The corresponding c++ code is:

K x;
unsigned char* q = “select sumBySym:sum size by sym from trade”;
int socket = khp(“localhost”, 5001);
x = k(socket, q, 0);


As per my understanding, depending on the query, x will refer to a
(subset) of a dict or a table or any other kdb type( x->t=98 means its
a table and x->t = 99 means a table with primary keys). So I needed to
know how to access each individual row of the query.

To illustrate , assume the query returns

sym time price size ex
-----------------------------------
AIG 09:30:00.207 1.778758 3 N
AIG 09:30:00.219 0.9632721 3 N
AIG 09:30:00.279 1.948238 6 T
AIG 09:30:00.326 2.121221 2 A
AIG 09:30:00.404 1.681036 4 A
AIG 09:30:00.433 1.232666 8 T


How do i access the 5th row which is in this case is "AIG |
09:30:00.404| 1.681036| 4| A| " using c++ code … please advice.

Thanks,
Nav

</nav.andraste>

X-Mailer: Apple Mail (2.929.2)

it should be something like this:

x=k(socket,q,0);
if(!x)… // boken socket
if(x->t==-128)… // error
if(x->t==XD) // a dict. force conversion to flip
if(!(K y=ktd(x))… ; // conversion failed
else x=y;
if(x->t!=XT)…; // we don’t have a table

K t=x->k; // the base dict from flip
K c=kK(t)[0]; // the column names
K v=kK(t)[1]; // the column values

K sym=kS(kK(v)[0])[4]; // the fifth row in the first column: AIG

have a look at http://www.kx.com/q/c/other/printq.zip for a detailed
decoding example.

felix