using ja: c interface

Hi ,

This is about using the function ja ( join -atom ) , C interfacing
code.

i have table called ‘trade’ having sym, date,time,price,exchange as
columns

i created a K variable called row :

  1. K row = ktn(0,5);
    and like wise for sym, date etc
  2. K symcol=kK(row)[0] = ktn(KS,0)
  3. K datecol= kK(row)[1] = ktn (KI,0)
    and similarly for other cols
    then created data for sym,date etc using
  4. js (&symcol,“GOOG”);
  5. ja(&date,cdate); // cdate is an representing the number of days
    since 2000.01.01
    similarly for time, price and then for exchange (using ja or js
    whichever is appropriate)
    Followed by joining K vars to the K row variable
  6. jk( &row, symcol)
    7.jk(&row, datecol)
    etc

but when i do an insert using
k(-c,“insert”,“trade”,row, 0)

it throws up a segmentation fault.

i have tried K row = knk (5, KS,KI,KI,KF,KS) at (1) and removed calls
of (6) and (7) … but it hasnt helped.

Any ideas?

Regards
Nav

One problem is that the “trade” argument in the k call should be a Kvariable. The following works for me (just the first two columns):int main() { int h=khp(“localhost”,5001); int cdate=2000; K row=ktn(0,0); K symcol=ktn(KS,0); K datecol=ktn(KI,0); js(&symcol,“GOOG”); ja(&datecol,&cdate); jk(&row,symcol); jk(&row,datecol); k(-h,“insert”,ks(“trade”),row,(K)0); return 0;}On May 21, 10:32?pm, Nav <nav.andra…> wrote:> Hi ,>> This is about using the function ja ( join -atom ) , C interfacing> code.>> i have table called ‘trade’ having sym, date,time,price,exchange as> columns>> i created a K variable called row :> 1. K row = ktn(0,5);> and like wise for sym, date etc> 2. K symcol=kK(row)[0] = ktn(KS,0)> 3. K datecol= kK(row)[1] = ktn (KI,0)> and similarly for other cols> then created data for sym,date etc using> 4. js (&symcol,“GOOG”);> 5. ja(&date,cdate); // cdate is an representing the number of days> since 2000.01.01> similarly for time, price and then for exchange (using ja or js> whichever is appropriate)> Followed by joining K vars to the K row variable> 6. jk( &row, symcol)> 7.jk(&row, datecol)> etc>> but when i do an insert using> k(-c,“insert”,“trade”,row, 0)>> it throws up a segmentation fault.>> i have tried K row = knk (5, KS,KI,KI,KF,KS) at (1) and removed calls> of (6) and (7) … but it hasnt helped.>> Any ideas?>> Regards> Nav</nav.andra…>

X-Mailer: iPhone Mail (5H11)
Subject: Re: [personal kdb+] Re: using ja: c interface
Date: Fri, 22 May 2009 07:13:53 +0100
Cc: Kdb+ Personal Developers

Hi Chris,

It was really nice to see you at the party.

Nice catch, but im surprised that it works because “GOOG” should be
internalized with ss as well.

Regards,
Attila

My apologies , but it is k(-c,“insert”,ks(“trade”),row, K(0)) ;and js(&symcol,ss(“GOOG”) );Sorry i missed that when creating this post.using fixed length records like1. row = knk (5, KS,KI,KI,KF,KS)2. symcol= kK ( row [0]) = ktn(KS,100);3 datecol =kK (row[0]) = ktn (KI,100);etcseems to be working fine. But when i need to create ‘dynamic’ lengthrecords, it seems to be failing.RegardsNavOn May 22, 11:13?am, Attila Vrabecz <attila.vrab…> wrote:> Hi Chris,>> It was really nice to see you at the party.>> Nice catch, but im surprised that it works because “GOOG” should be ?> internalized with ss as well.>> Regards,> ? ?Attila>> On 22 May 2009, at 05:52, Chris Burke <cdbu…> wrote:>>>>>> > One problem is that the “trade” argument in the k call should be a K> > variable. The following works for me (just the first two columns):>> > int main() {> > int h=khp(“localhost”,5001);> > int cdate=2000;> > K row=ktn(0,0);> > K symcol=ktn(KS,0);> > K datecol=ktn(KI,0);> > js(&symcol,“GOOG”);> > ja(&datecol,&cdate);> > jk(&row,symcol);> > jk(&row,datecol);> > k(-h,“insert”,ks(“trade”),row,(K)0);> > return 0;> > }>> > On May 21, 10:32 pm, Nav <nav.andra…> wrote:> >> Hi ,>> >> This is about using the function ja ( join -atom ) , C interfacing> >> code.>> >> i have table called ‘trade’ having sym, date,time,price,exchange as> >> columns>> >> i created a K variable called row :> >> 1. K row = ktn(0,5);> >> and like wise for sym, date etc> >> 2. K symcol=kK(row)[0] = ktn(KS,0)> >> 3. K datecol= kK(row)[1] = ktn (KI,0)> >> and similarly for other cols> >> then created data for sym,date etc using> >> 4. js (&symcol,“GOOG”);> >> 5. ja(&date,cdate); // cdate is an representing the number of days> >> since 2000.01.01> >> similarly for time, price and then for exchange (using ja or js> >> whichever is appropriate)> >> Followed by joining K vars to the K row variable> >> 6. jk( &row, symcol)> >> 7.jk(&row, datecol)> >> etc>> >> but when i do an insert using> >> k(-c,“insert”,“trade”,row, 0)>> >> it throws up a segmentation fault.>> >> i have tried K row = knk (5, KS,KI,KI,KF,KS) at (1) and removed calls> >> of (6) and (7) … but it hasnt helped.>> >> Any ideas?>> >> Regards> >> Nav- Hide quoted text ->> - Show quoted text -</nav.andra…></cdbu…></attila.vrab…>

X-Mailer: Apple Mail (2.935.3)

nav,

of course it fails. ja will relocate our object if needs to be extended.

delay the column assignment in the list after all insertions were done
and
don’t forget that you need to pass pointer to your data and not
variable name to ja.

point 6&7 are not needed since you will assign it statically after
data insertion in the vectors.

felix

Felix,can you explain what you mean by ‘delay the column assignment in thelist after all insertions were done’ a bit more … I dont followyou.Thanks,NavOn May 22, 3:01?pm, Felix Lungu <felix.lu…> wrote:> nav,>> of course it fails. ja will relocate our object if needs to be extended.>> delay the column assignment in the list after all insertions were done ?> and> don’t forget that you need to pass pointer to your data and not ?> variable name to ja.>> point 6&7 are not needed since you will assign it statically after ?> data insertion in the vectors.>> felix>> On 21 May 2009, at 17:32, Nav wrote:>>>>>> > Hi ,>> > This is about using the function ja ( join -atom ) , C interfacing> > code.>> > i have table called ‘trade’ having sym, date,time,price,exchange as> > columns>> > i created a K variable called row :> > 1. K row = ktn(0,5);> > and like wise for sym, date etc> > 2. K symcol=kK(row)[0] = ktn(KS,0)> > 3. K datecol= kK(row)[1] = ktn (KI,0)> > and similarly for other cols> > then created data for sym,date etc using> > 4. js (&symcol,“GOOG”);> > 5. ja(&date,cdate); // cdate is an representing the number of days> > since 2000.01.01> > similarly for time, price and then for exchange (using ja or js> > whichever is appropriate)> > Followed by joining K vars to the K row variable> > 6. jk( &row, symcol)> > 7.jk(&row, datecol)> > etc>> > but when i do an insert using> > k(-c,“insert”,“trade”,row, 0)>> > it throws up a segmentation fault.>> > i have tried K row = knk (5, KS,KI,KI,KF,KS) at (1) and removed calls> > of (6) and (7) … but it hasnt helped.>> > Any ideas?>> > Regards> > Nav- Hide quoted text ->> - Show quoted text -</felix.lu…>

X-Mailer: Apple Mail (2.935.3)

don’t do this.

>>> 2. K symcol=kK(row)[0] = ktn(KS,0)
>>> 3. K datecol= kK(row)[1] = ktn (KI,0)
>>> and similarly for other cols
>>> then created data for sym,date etc using
>>> 4. js (&symcol,“GOOG”);
>>> 5. ja(&date,cdate); // cdate is an representing the number of days

ja() will relocate the object if the old objects can’t hold the new
data and your kK(row) will point to old address which will be invalid.

first create and append your data to the objects, then assign them to
the “row”.

felix

Hi Felix,I have tried your suggestion, unfortunately it isnt working for me.Not sure what I am doing wrong.This is what i do ,1. K symcol= ktn(KS,0) ;2. ja (&symcol, ss( (S) “GOOG”) );3. K row = knk (5, KS,KI ,… )4. K symcol = kK(row)[0];5. Now I do the insert: k(-c,“insert”,ks(“trade”),row, K(0))Step 5 is where i get the seg fault.The backtrace from the debugger: (not sure if this helps)#0 0x0000002a957981f5 in nx () from …/c.o#1 0x0000002a957983c6 in nx () from …/c.o#2 0x0000002a957983c6 in nx () from …/c.o#3 0x0000002a95798c1a in b9 () from …/c.o#4 0x0000002a957993c9 in ww () from …/c.o#5 0x0000002a9579959f in k () from …/c.oThanks for the help so far.Regards,NavOn May 26, 10:26?am, Felix Lungu <felix.lu…> wrote:> don’t do this.>> >>> 2. K symcol=kK(row)[0] = ktn(KS,0)> >>> 3. K datecol= kK(row)[1] = ktn (KI,0)> >>> and similarly for other cols> >>> then created data for sym,date etc using> >>> 4. js (&symcol,“GOOG”);> >>> 5. ja(&date,cdate); // cdate is an representing the number of days>> ja() will relocate the object if the old objects can’t hold the new ?> data and your kK(row) will point to old address which will be invalid.>> first create and append your data to the objects, then assign them to ?> the “row”.>> felix</felix.lu…>

X-Mailer: Apple Mail (2.935.3)

nav,

paste the actual code you are using in an email.

felix

Hi Felix,

this is the code

/************************jaTest.h********************************/

#include
#include <k.h>

using namespace std;

class jaTest
{
public:
int insert(int Date, int Time, float Open);
void clearBulkInsertObject();
void bulkInsert();

typedef struct DataRecord
{
int DateRecord;
int TimeRecord;
char TypeRecord;
float OpenRecord;
} DRECORD;

vector DataVector;
};

/ jaTest.h /


/ jaTest.cpp /

#include <stdio.h>
#include
#include
#include
#include
#include
#include <string.h>
#include “jaTest.h”

using namespace std;

K dataRow,dateCol,timeCol,typeCol,openCol;
int countE = 0;

int main(int argc, const char argv[])
{
jaTest jatest;

int Time = 3600;
int Date = 3500;
float Open = 5.0;

jatest.insert(Date, Time, Open);

jatest.insert(Date, Time, Open);

jatest.bulkInsert();
}

int jaTest::insert(int Date, int Time, float Open)
{
char feedType = ‘F’;
char tableName[20];
DRECORD DRecord;

sprintf(tableName, “trade”);

if ((string)tableName == “trade”)
{
DRecord.DateRecord = Date;
DRecord.TimeRecord = Time;
DRecord.TypeRecord = ‘F’;
DRecord.OpenRecord = Open;
DataVector.push_back(DRecord);

countE++;

cout << "countE value: " << countE << endl;

}
return 0;
}

void jaTest::bulkInsert()
{
if (countE > 0)
{
stringstream temp;
cout << “Bulk Insert into trade table being done. Records inserted:
” << countE << endl;
vector::iterator DataVectorItr;
clearBulkInsertObject();
cout << “After clearing K col objects, DataVector size is:” <<
DataVector.size() << endl;
for(DataVectorItr = DataVector.begin(); DataVectorItr !=
DataVector.end(); DataVectorItr++)
{
ja(&dateCol, &DataVectorItr->DateRecord);
ja(&timeCol, &DataVectorItr->TimeRecord);
ja(&typeCol, &DataVectorItr->TypeRecord);
ja(&openCol, &DataVectorItr->OpenRecord);
}

cout << “All values appended from vector, now they are being
assigned to the row” << endl;

dataRow = knk(4, KD,KT,KC,KF);
dateCol =kK(dataRow)[0];
timeCol =kK(dataRow)[1];
typeCol =kK(dataRow)[2];
openCol =kK(dataRow)[3];

cout << “All values from the vector assigned to the K data row” <<
endl;

int c=khp(“localhost”,5001);
cout << “Connection made”<< endl;

k(-c,“a:123”,0); // test statement insert

k(-c, “insert”, ks((S)“trade”), dataRow, (K)0); // This is where the
segmentation fault occurs

cout << “All values from the vector sent to trade table” << endl;

clearBulkInsertObject();

while(!DataVector.empty())
DataVector.pop_back();

countE = 0;

cout << “After cleaning data vector and countE object”;
}
}

void jaTest::clearBulkInsertObject()
{
cout << "clearBulkInsertObject called " << endl;

//data = knk(11, KS,KI,KD,KT,KC,KF,KF,KF,KF,KF,KF);
dateCol = ktn(KD,0);
timeCol = ktn(KT,0);
typeCol = ktn(KC,0);
openCol = ktn(KF,0);
countE = 0;
cout << “Before leaving clearBulkInsertObject()” << endl;
}
/ jaTest.cpp
*** /



To reiterate, the segmentation fault occurs at k(-c, “insert”, ks
((S)“trade”), dataRow, (K)0);

Thanks,

Nav

</string.h></stdio.h></k.h>

X-Mailer: Apple Mail (2.935.3)

note that kdb+ float is double (so change to double everywhere
accordingly)

and also

dataRow = knk(4, KD,KT,KC,KF);
dateCol =kK(dataRow)[0];
timeCol =kK(dataRow)[1];
typeCol =kK(dataRow)[2];
openCol =kK(dataRow)[3];

is wrong for two reasons:

  1. KD/KT/KC/KF are not K objects for a start
  2. assignment should be other way around: kK(dataRow)[0]=dateCol

probably you wanted to say
dataRow = ktn(0,4);
kK(dataRow)[0]=dateCol;
kK(dataRow)[1]=timeCol;
kK(dataRow)[2]=typeCol;
kK(dataRow)[3]=openCol;

but what’s even better is
dataRow=knk(4,dateCol,timeCol,typeCol,openCol);
Attila

Thanks Attila, that seemed to have worked for the most part.
Except that for sym ( which is a char* ) there seems to be a seg
fault.

/**********************jaTest.h*************************/

#include
#include <k.h>

using namespace std;

class jaTest
{
public:
int insert(char * Symbol, int Date, int Time, float Open);
void clearBulkInsertObject();
void bulkInsert();

typedef struct DataRecord
{
char SymbolRecord[32];
int DateRecord;
int TimeRecord;
char TypeRecord;
double OpenRecord;
} DRECORD;

vector DataVector;
};

/ jaTest.h*** /



/ jaTest.cpp*** /
#include <stdio.h>
#include
#include
#include
#include
#include
#include <string.h>
#include “jaTest.h”

using namespace std;

K dataRow,symCol,dateCol,timeCol,typeCol,openCol;
int countE = 0;

int main(int argc, const char argv[])
{
jaTest jatest;

char Symbol[32];
strcpy(Symbol,“GOOG”);
int Time = 3600;
int Date = 3500;
double Open = 5.0;

jatest.insert(Symbol, Date, Time, Open);

jatest.insert(Symbol, Date, Time, Open);

jatest.bulkInsert();
}

int jaTest::insert(char * Symbol, int Date, int Time, double Open)
{
char feedType = ‘F’;
char tableName[20];
DRECORD DRecord;
string symb1(Symbol); // This is for some testing. Removing it or
keeping doesn’t the error
Symbol = (char
)symb1.c_str(); // This is for some testing. Removing
it or keeping doesn’t the error

sprintf(tableName, “trade”);

if ((string)tableName == “trade”)
{
strcpy(DRecord.SymbolRecord, Symbol);
DRecord.DateRecord = Date;
DRecord.TimeRecord = Time;
DRecord.TypeRecord = ‘F’;
DRecord.OpenRecord = Open;
DataVector.push_back(DRecord);

countE++;

cout << "countE value: " << countE << endl;

}
return 0;
}

void jaTest::bulkInsert()
{
if (countE > 0)
{
stringstream temp;
cout << “Bulk Insert into trade table being done. Records inserted:
” << countE << endl;
vector::iterator DataVectorItr;
clearBulkInsertObject();
cout << “After clearing K col objects, DataVector size is:” <<
DataVector.size() << endl;
for(DataVectorItr = DataVector.begin(); DataVectorItr !=
DataVector.end(); DataVectorItr++)
{
ja(&symCol, DataVectorItr->SymbolRecord);------------>-(A)
ja(&dateCol, &DataVectorItr->DateRecord);
ja(&timeCol, &DataVectorItr->TimeRecord);
ja(&typeCol, &DataVectorItr->TypeRecord);
ja(&openCol, &DataVectorItr->OpenRecord);
}

cout << “All values appended from vector, now they are being
assigned to the row” << endl;

dataRow = knk(5,KS,KD,KT,KC,KF);
symCol =kK(dataRow)[0];
dateCol =kK(dataRow)[1];
timeCol =kK(dataRow)[2];
typeCol =kK(dataRow)[3];
openCol =kK(dataRow)[4];

cout << “All values from the vector assigned to the K data row” <<
endl;

int c=khp(“localhost”,5001);
cout << “Connection made”<< endl;

k(-c,“a:123”,0); // test statement insert

k(-c, “insert”, ks((S)“trade”), dataRow, (K)0);

cout << “All values from the vector sent to trade table” << endl;

clearBulkInsertObject();

while(!DataVector.empty())
DataVector.pop_back();

countE = 0;

cout << “After cleaning data vector and countE object”;
}
}

void jaTest::clearBulkInsertObject()
{
cout << "clearBulkInsertObject called " << endl;

//data = knk(11, KS,KI,KD,KT,KC,KF,KF,KF,KF,KF,KF);
symCol = ktn(KS,0);
dateCol = ktn(KD,0);
timeCol = ktn(KT,0);
typeCol = ktn(KC,0);
openCol = ktn(KF,0);
countE = 0;
cout << “Before leaving clearBulkInsertObject()” << endl;
}



/ jaTest.cpp*** /



The seg fault seems to be occuring at the same place as before,that
is : k(-c, “insert”, ks((S)“trade”), dataRow, (K)0);
If we remove SymbolRecord from DataRecord and replace with a char
variable, the program works fine.
Line (A) seems to be the culprit. Have tried using js instead of ja at
(A), but doesnt seem to help.

Appreciate the help so far, any ideas about this?

Regards,
Nav

</string.h></stdio.h></k.h>

X-Mailer: Apple Mail (2.935.3)> ja(&symCol, DataVectorItr->SymbolRecord);------------>-(A)you miss a & in front DataVec… Attila

User-Agent: G2/1.0X-Google-Token: OHhI9wwAAAD__s_JbUc3LwrprjCjaPBdX-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 S; MS-RTC LM 8),gzip(gfe),gzip(gfe)Message-ID: <4e74b3a6-a75a-4f1d-ae64-6249c8f0c4ab@e20g2000vbc.googlegroups.com>Subject: Re: using ja: c interfaceFrom: vcd To: “Kdb+ Personal Developers” X-Google-Approved: charlie@kx.com via web at 2009-05-29 12:56:02Thanks, Atilla. We tried with the & in front of the DataVectorItr asfollows ::: ja(&symCol, &DataVectorItr->SymbolRecord);but it still gives a seg fault even with that. Is it a problem withthe char array being assigned to the K object? or is it some syntaxthat we could be missing?If we remove the SymbolRecord (and other Symbol references) from thecode it works just fine.-- vcdOn May 29, 5:19?pm, Attila Vrabecz <attila.vrab…> wrote:> > ? ? ? ? ? ? ? ? ? ?ja(&symCol, DataVectorItr->SymbolRecord);------------>-(A)>> you miss a & in front DataVec…> ? ? Attila</attila.vrab…>

X-Mailer: Apple Mail (2.935.3)right, ja is join atomso it should bejs(&symCol,ss(DataVectorItr->SymbolRecord)note the ss() to internalize the symbol AttilaOn 29 May 2009, at 13:47, vcd wrote:>> Thanks, Atilla. We tried with the & in front of the DataVectorItr as> follows ::: ja(&symCol, &DataVectorItr->SymbolRecord);> but it still gives a seg fault even with that. Is it a problem with> the char array being assigned to the K object? or is it some syntax> that we could be missing?> If we remove the SymbolRecord (and other Symbol references) from the> code it works just fine.>> – vcd>> On May 29, 5:19 pm, Attila Vrabecz <attila.vrab…> wrote:>>> ja(&symCol, DataVectorItr- >>> >SymbolRecord);------------>-(A)>>>> you miss a & in front DataVec…>> Attila>> ></attila.vrab…>

Hi Atilla,Thanks for the suggestion! Still no luck though. It gives a seg faulteven after changing the line below from //ja(&symCol, &DataVectorItr->SymbolRecord);TO js(&symCol,ss(DataVectorItr->SymbolRecord));The seg fault now comes at the js line and it doesn’t even reach the"insert" portion of the code (Rest of the code is the same as pastedabove).-- vcd.On May 29, 5:58?pm, Attila Vrabecz <attila.vrab…> wrote:> right, ja is join atom> so it should be>> js(&symCol,ss(DataVectorItr->SymbolRecord)>> note the ss() to internalize the symbol> ? ? Attila>> On 29 May 2009, at 13:47, vcd wrote:>>>>>> > Thanks, Atilla. We tried with the & in front of the DataVectorItr as> > follows ::: ja(&symCol, &DataVectorItr->SymbolRecord);> > but it still gives a seg fault even with that. Is it a problem with> > the char array being assigned to the K object? or is it some syntax> > that we could be missing?> > If we remove the SymbolRecord (and other Symbol references) from the> > code it works just fine.>> > – vcd>> > On May 29, 5:19 pm, Attila Vrabecz <attila.vrab…> wrote:> >>> ? ? ? ? ? ? ? ? ? ?ja(&symCol, DataVectorItr-> >>> >SymbolRecord);------------>-(A)>> >> you miss a & in front DataVec…> >> ? ? Attila- Hide quoted text ->> - Show quoted text -</attila.vrab…></attila.vrab…>

X-Mailer: Apple Mail (2.935.3)from http://kx.com/q/c/c/readme.txt"must call khp before generating k data."same can be found at https://code.kx.com/trac/wiki/Cookbook/InterfacingWithC with different wordsapparently it is fine with ja(), but not with ss()so, move the khp call in front of everything AttilaOn 29 May 2009, at 14:27, vcd wrote:>> Hi Atilla,>> Thanks for the suggestion! Still no luck though. It gives a seg fault> even after changing the line below from> //ja(&symCol, &DataVectorItr->SymbolRecord);> TO> js(&symCol,ss(DataVectorItr->SymbolRecord));>> The seg fault now comes at the js line and it doesn’t even reach the> “insert” portion of the code (Rest of the code is the same as pasted> above).>> – vcd.>> On May 29, 5:58 pm, Attila Vrabecz <attila.vrab…> wrote:>> right, ja is join atom>> so it should be>>>> js(&symCol,ss(DataVectorItr->SymbolRecord)>>>> note the ss() to internalize the symbol>> Attila>>>> On 29 May 2009, at 13:47, vcd wrote:>>>>>>>>>>>>> Thanks, Atilla. We tried with the & in front of the DataVectorItr as>>> follows ::: ja(&symCol, &DataVectorItr->SymbolRecord);>>> but it still gives a seg fault even with that. Is it a problem with>>> the char array being assigned to the K object? or is it some syntax>>> that we could be missing?>>> If we remove the SymbolRecord (and other Symbol references) from the>>> code it works just fine.>>>>> – vcd>>>>> On May 29, 5:19 pm, Attila Vrabecz <attila.vrab…> wrote:>>>>> ja(&symCol, DataVectorItr->>>>>> SymbolRecord);------------>-(A)>>>>>> you miss a & in front DataVec…>>>> Attila- Hide quoted text ->>>> - Show quoted text -> ></attila.vrab…></attila.vrab…>

Hi Atilla,Even that doesn’t help. After doing the above it still gives a segfault in the insert code statement.Even hardcoding the statement from js(&symCol,ss(DataVectorItr->SymbolRecord));TO js(&symCol, ss((S)“GOOG”));gives a seg fault at the above line. Of course by removing the symColline it works great but that doesn’t solve the problem for me assymCol is needed. Any suggestions?-- vcdOn May 29, 7:45?pm, Attila Vrabecz <attila.vrab…> wrote:> fromhttp://kx.com/q/c/c/readme.txt> “must call khp before generating k data.”> same can be found athttps://code.kx.com/trac/wiki/Cookbook/InterfacingWithC> ? with different words> apparently it is fine with ja(), but not with ss()> so, move the khp call in front of everything> ? ? Attila>> On 29 May 2009, at 14:27, vcd wrote:>>>>>> > Hi Atilla,>> > Thanks for the suggestion! Still no luck though. It gives a seg fault> > even after changing the line below from> > ? ? ? ? ? ? ? ? ? ? ? ?//ja(&symCol, &DataVectorItr->SymbolRecord);> > TO> > ? ? ? ? ? ? ? ? ? ? ? ?js(&symCol,ss(DataVectorItr->SymbolRecord));>> > The seg fault now comes at the js line and it doesn’t even reach the> > “insert” portion of the code (Rest of the code is the same as pasted> > above).>> > – vcd.>> > On May 29, 5:58 pm, Attila Vrabecz <attila.vrab…> wrote:> >> right, ja is join atom> >> so it should be>> >> js(&symCol,ss(DataVectorItr->SymbolRecord)>> >> note the ss() to internalize the symbol> >> ? ? Attila>> >> On 29 May 2009, at 13:47, vcd wrote:>> >>> Thanks, Atilla. We tried with the & in front of the DataVectorItr as> >>> follows ::: ja(&symCol, &DataVectorItr->SymbolRecord);> >>> but it still gives a seg fault even with that. Is it a problem with> >>> the char array being assigned to the K object? or is it some syntax> >>> that we could be missing?> >>> If we remove the SymbolRecord (and other Symbol references) from the> >>> code it works just fine.>> >>> – vcd>> >>> On May 29, 5:19 pm, Attila Vrabecz <attila.vrab…> wrote:> >>>>> ? ? ? ? ? ? ? ? ? ?ja(&symCol, DataVectorItr-> >>>>>> SymbolRecord);------------>-(A)>> >>>> you miss a & in front DataVec…> >>>> ? ? Attila- Hide quoted text ->> >> - Show quoted text – Hide quoted text ->> - Show quoted text -</attila.vrab…></attila.vrab…></attila.vrab…>

X-Mailer: Apple Mail (2.935.3)

I have no idea what you are actually doing because the code you sent
last still has some stuff from earlier which i think we have already
discussed, but anyway see the code that works for me below

Regards,
Attila

/**********************jaTest.h*********************/
#include
#include “q/k.h”

using namespace std;

class jaTest
{
public:
int insert(char* Symbol,int Date, int Time, double Open);
void clearBulkInsertObject();
void bulkInsert();

typedef struct DataRecord
{
char SymbolRecord[32];
int DateRecord;
int TimeRecord;
char TypeRecord;
double OpenRecord;
} DRECORD;

vector DataVector;
};

/ jaTest.cpp /

#include <stdio.h>
#include
#include
#include
#include
#include
#include <string.h>
#include “jaTest.h”

using namespace std;

K dataRow,symCol,dateCol,timeCol,typeCol,openCol;
int countE = 0;

int main(int argc, const char argv[])
{
jaTest jatest;

char Symbol[32];
strcpy(Symbol,“GOOG”);

int Time = 3600;
int Date = 3500;
double Open = 5.0;

jatest.insert(Symbol, Date, Time, Open);

jatest.insert(Symbol, Date, Time, Open);

jatest.bulkInsert();
}

int jaTest::insert(char
Symbol,int Date, int Time, double Open)
{
char feedType = ‘F’;
char tableName[20];
DRECORD DRecord;

sprintf(tableName, “trade”);

if ((string)tableName == “trade”)
{
strcpy(DRecord.SymbolRecord, Symbol);
DRecord.DateRecord = Date;
DRecord.TimeRecord = Time;
DRecord.TypeRecord = ‘F’;
DRecord.OpenRecord = Open;
DataVector.push_back(DRecord);

countE++;

cout << "countE value: " << countE << endl;

}
return 0;
}

void jaTest::bulkInsert()
{
int c=khp(“localhost”,5001);
cout << “Connection made”<< endl;

if (countE > 0)
{
stringstream temp;
cout << “Bulk Insert into trade table being done. Records inserted:”
<< countE << endl;
vector::iterator DataVectorItr;
clearBulkInsertObject();
cout << “After clearing K col objects, DataVector size is:” <<
DataVector.size() << endl;
for(DataVectorItr = DataVector.begin(); DataVectorItr !=
DataVector.end(); DataVectorItr++)
{
js(&symCol, ss((S)DataVectorItr->SymbolRecord));
ja(&dateCol, &DataVectorItr->DateRecord);
ja(&timeCol, &DataVectorItr->TimeRecord);
ja(&typeCol, &DataVectorItr->TypeRecord);
ja(&openCol, &DataVectorItr->OpenRecord);
}

cout << “All values appended from vector, now they are being
assigned to the row” << endl;

dataRow=knk(5,symCol,dateCol,timeCol,typeCol,openCol);
// dataRow = ktn(0,4);
// kK(dataRow)[0]=dateCol;
// kK(dataRow)[1]=timeCol;
// kK(dataRow)[2]=typeCol;
// kK(dataRow)[3]=openCol;
//dataRow = knk(4, KD,KT,KC,KF);
//dateCol =kK(dataRow)[0];
//timeCol =kK(dataRow)[1];
//typeCol =kK(dataRow)[2];
//openCol =kK(dataRow)[3];

cout << “All values from the vector assigned to the K data row” <<
endl;

// int c=khp(“localhost”,5001);
// cout << “Connection made”<< endl;

k(-c,“a:123”,0); // test statement insert

k(-c, “insert”, ks((S)“trade”), dataRow, (K)0); // This is where the
segmentation fault occurs

cout << “All values from the vector sent to trade table” << endl;

clearBulkInsertObject();

while(!DataVector.empty())
DataVector.pop_back();

countE = 0;

cout << “After cleaning data vector and countE object”;
}
}

void jaTest::clearBulkInsertObject()
{
cout << "clearBulkInsertObject called " << endl;

//data = knk(11, KS,KI,KD,KT,KC,KF,KF,KF,KF,KF,KF);
symCol = ktn(KS,0);
dateCol = ktn(KD,0);
timeCol = ktn(KT,0);
typeCol = ktn(KC,0);
openCol = ktn(KF,0);
countE = 0;
cout << “Before leaving clearBulkInsertObject()” << endl;
}
/ jaTest.cpp
**** /
On 1 Jun 2009, at 10:01, vcd wrote:

>
> Hi Atilla,
>
> Even that doesn’t help. After doing the above it still gives a seg
> fault in the insert code statement.
>
> Even hardcoding the statement from
> js(&symCol,ss(DataVectorItr->SymbolRecord));
> TO
> js(&symCol, ss((S)“GOOG”));
>
> gives a seg fault at the above line. Of course by removing the symCol
> line it works great but that doesn’t solve the problem for me as
> symCol is needed. Any suggestions?
>
> – vcd
>
>
> On May 29, 7:45 pm, Attila Vrabecz <attila.vrab…> wrote:
>> fromhttp://kx.com/q/c/c/readme.txt
>> “must call khp before generating k data.”
>> same can be found athttps://code.kx.com/trac/wiki/Cookbook/
>> InterfacingWithC
>> with different words
>> apparently it is fine with ja(), but not with ss()
>> so, move the khp call in front of everything
>> Attila
>>
>> On 29 May 2009, at 14:27, vcd wrote:
>>
>>
>>
>>
>>
>>> Hi Atilla,
>>
>>> Thanks for the suggestion! Still no luck though. It gives a seg
>>> fault
>>> even after changing the line below from
>>> //ja(&symCol, &DataVectorItr->SymbolRecord);
>>> TO
>>> js(&symCol,ss(DataVectorItr->SymbolRecord));
>>
>>> The seg fault now comes at the js line and it doesn’t even reach the
>>> “insert” portion of the code (Rest of the code is the same as pasted
>>> above).
>>
>>> – vcd.
>>
>>> On May 29, 5:58 pm, Attila Vrabecz <attila.vrab…> wrote:
>>>> right, ja is join atom
>>>> so it should be
>>
>>>> js(&symCol,ss(DataVectorItr->SymbolRecord)
>>
>>>> note the ss() to internalize the symbol
>>>> Attila
>>
>>>> On 29 May 2009, at 13:47, vcd wrote:
>>
>>>>> Thanks, Atilla. We tried with the & in front of the
>>>>> DataVectorItr as
>>>>> follows ::: ja(&symCol, &DataVectorItr->SymbolRecord);
>>>>> but it still gives a seg fault even with that. Is it a problem
>>>>> with
>>>>> the char array being assigned to the K object? or is it some
>>>>> syntax
>>>>> that we could be missing?
>>>>> If we remove the SymbolRecord (and other Symbol references) from
>>>>> the
>>>>> code it works just fine.
>>
>>>>> – vcd
>>
>>>>> On May 29, 5:19 pm, Attila Vrabecz <attila.vrab…>
>>>>> wrote:
>>>>>>> ja(&symCol, DataVectorItr-
>>>>>>>> SymbolRecord);------------>-(A)
>>
>>>>>> you miss a & in front DataVec…
>>>>>> Attila- Hide quoted text -
>>
>>>> - Show quoted text – Hide quoted text -
>>
>> - Show quoted text -
> >


</attila.vrab…></attila.vrab…></attila.vrab…></string.h></stdio.h>