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>