insert inside a C extension function (again)

Dear KDB Users,

Please take a look at this dll defined as:

#include “k.h”
K startAud(K y)
{
int bulkSize=3;
K x=knk(6, ktn(KI, bulkSize), ktn(KC, bulkSize), ktn(KH, bulkSize),
ktn(KI, bulkSize), ktn(KF, bulkSize), ktn(KS, bulkSize));
for(int i=0; ikI(xK[0])[i] = i;
kC(xK[1])[i] = ‘a’;
kH(xK[2])[i] = 100;
kI(xK[3])[i] = 1000;
kF(xK[4])[i] = 99.9;
kS(xK[5])[i] = (S)“hello world”;
}
err=k(0, “insert”, ks((S)“all_dt”), x, (K)0);
k(0,“”,(K)0);
return ki(y->i);
}

When I tested it: the insert somehow did not happen. Could you tell me
what I missed? Do I have to pass X in as a parameter? Or I cannot
allocate x using knk inside the function?

To run the test:

1. compile the code as DLL
2. create table as:
all_dt:(seq:int$();cchar:char$();cshort:short$();cint:int$
();cfloat:float$();csym:symbol$();time:`time$())
3. load the dll and run the test
4. show all_dt in q console.

I altered the code slightly to make it work, the basic problem wasthat the time column had been left out on the C side (the call to knkand - obviously - in the for loop):#include <stdio.h>#include "k.h"K startAud(K y){ int bulkSize=3; int i; K err = NULL; K x=knk(7, // Set to 7 as we are adding time ktn(KI, bulkSize), ktn(KC, bulkSize), ktn(KH, bulkSize), ktn(KI, bulkSize), ktn(KF, bulkSize), ktn(KS, bulkSize), ktn(KT, bulkSize)); // Add time for(i=0; ii; // Time is simple scalar } err = k(0, “insert”, ks((S)“all_dt”), x, (K)0); if (err->t == -128) O(“err = %s \n”, err->s); return ki(y->i);}Creating a nice small test script:cat > t.qall_dt:( seq:int$(); cchar:char$(); cshort:short$(); cint:int$(); cfloat:float$(); csym:symbol$(); time:time$())startAud:t 2:(`startAud; 1)startAudshow all_dt^DLoading the script for a go with the code:q) \l t.q0seq cchar cshort cint cfloat csym time-----------------------------------------------------0 a 100 1000 99.9 hello world 00:00:00.2001 a 100 1000 99.9 hello world 00:00:00.2002 a 100 1000 99.9 hello world 00:00:00.200…seems to have done the trick.H?kan</stdio.h>

Oops… Thanks, H?kan.dbtouchOn Sep 28, 2:05?pm, Lindqvist <lindqvist.h…> wrote:> I altered the code slightly to make it work, the basic problem was> that the time column had been left out on the C side (the call to knk> and - obviously - in the for loop):>> #include <stdio.h>>> #include “k.h”>> K startAud(K y)> {> ? ? int bulkSize=3;> ? ? int i;> ? ? K err = NULL;>> ? ? K x=knk(7, ? ? ? ? ? ? ? ? ?// Set to 7 as we are adding time> ? ? ? ? ? ? ktn(KI, bulkSize),> ? ? ? ? ? ? ktn(KC, bulkSize),> ? ? ? ? ? ? ktn(KH, bulkSize),> ? ? ? ? ? ? ktn(KI, bulkSize),> ? ? ? ? ? ? ktn(KF, bulkSize),> ? ? ? ? ? ? ktn(KS, bulkSize),> ? ? ? ? ? ? ktn(KT, bulkSize)); // Add time>> ? ? for(i=0; i ? ? ? ? kI(xK[0])[i] = i;> ? ? ? ? kC(xK[1])[i] = ‘a’;> ? ? ? ? kH(xK[2])[i] = 100;> ? ? ? ? kI(xK[3])[i] = 1000;> ? ? ? ? kF(xK[4])[i] = 99.9;> ? ? ? ? kS(xK[5])[i] = (S)“hello world”;> ? ? ? ? kI(xK[6])[i] = kt(200)->i; // Time is simple scalar> ? ? }>> ? ? ?err = k(0, “insert”, ks((S)“all_dt”), x, (K)0);>> ? ? if (err->t == -128)> ? ? ? ? O(“err = %s \n”, err->s);>> ? ? return ki(y->i);>> }>> Creating a nice small test script:>> cat > t.q> all_dt:(> ? ? seq:int$();&gt; ? ? cchar:char$();> ? ? cshort:short$();&gt; ? ? cint:int$();> ? ? cfloat:float$();&gt; ? ? csym:symbol$();> ? ? time:time$())&gt;&gt; startAud:t 2:(`startAud; 1)> startAud> show all_dt> ^D>> Loading the script for a go with the code:>> q) \l t.q> 0> seq cchar cshort cint cfloat csym ? ? ? ?time> -----------------------------------------------------> 0 ? a ? ? 100 ? ?1000 99.9 ? hello world 00:00:00.200> 1 ? a ? ? 100 ? ?1000 99.9 ? hello world 00:00:00.200> 2 ? a ? ? 100 ? ?1000 99.9 ? hello world 00:00:00.200>> …seems to have done the trick.>> H?kan</stdio.h></lindqvist.h…>