C++ and spaces in sym

Hi,

I have kdb+ interfacing with c++, and it works fine using the sample
databases as the sym names have no spaces eg:

int port = 5001;
int c = khp(“localhost”, port); //Connect to KDB
Q(!(x=k(c,“select time from trade where sym in `HPQ”,0)),“err”)

However, I have been collecting tick data from Bloomberg and I used
sym names such as `HPQ US Equity which has created a problem as in q
you would query:

select from trade where sym = `$“HPQ US Equity”

But I am not sure there is a way in c++ to handle this as it sees it
as 2 seperate strings:

Q(!(x=k(c,“select time from trade where sym = `$“HPQ US Equity””,
0)),“err”)

ie first string: “select time from trade where sym = `$”, then HPQ US
Equity and a second empty string “”.

Maybe there is a way in c++ to handle this that I have overlooked, or
there is another way to handle spaces in kdb+ which isnt using “”?
Otherwise is there a way to change the syms in my historical database
to remove the ’ US Equity’ part?

Any help would be much appreciated!

escape the "

i.e.
Q(!(x=k(c,“select time from trade where sym = `$"HPQ US Equity"”,0)),“err”)

Yep, that’s pretty much all? pre-processing you’ll need for ansi (\r->\n in case of loaded/user defined queries). Will get just a bit trickier with unicode.

A nice and simple solution! ThanksI have just one further question, is there a way to read variablesinto the string as well?So for example if I wanted to read in the date variable into thestring:const char* date = “2011.07.11”;“select price from trade where date<=“READ THE VARIABLE DATE IN HERE”,sym in $\"MMM US Equity\""ThanksOn Jul 16, 5:27?pm, Charles Skelton <char...> wrote:&gt; escape the "&gt; i.e.&gt; Q(!(x=k(c,"select time from trade where sym = $"HPQ US> Equity"”,0)),“err”)>> On Sat, Jul 16, 2011 at 2:01 PM, tomjg2...@yahoo.com <tomjg2…>wrote:>>>> > Hi,>> > I have kdb+ interfacing with c++, and it works fine using the sample> > databases as the sym names have no spaces eg:>> > int port = 5001;> > int c = khp(“localhost”, port); //Connect to KDB> > Q(!(x=k(c,“select time from trade where sym in HPQ",0)),"err")&gt;&gt; &gt; However, I have been collecting tick data from Bloomberg and I used&gt; &gt; sym names such as HPQ US Equity which has created a problem as in q> > you would query:>> > select from trade where sym = $"HPQ US Equity"&gt;&gt; &gt; But I am not sure there is a way in c++ to handle this as it sees it&gt; &gt; as 2 seperate strings:&gt;&gt; &gt; Q(!(x=k(c,"select time from trade where sym = $“HPQ US Equity””,> > 0)),“err”)>> > ie first string: “select time from trade where sym = `$”, then HPQ US> > Equity and a second empty string “”.>> > Maybe there is a way in c++ to handle this that I have overlooked, or> > there is another way to handle spaces in kdb+ which isnt using “”?> > Otherwise is there a way to change the syms in my historical database> > to remove the ? ?’ US Equity’ part?>> > Any help would be much appreciated!>> > –> >

Submitted via Google Groups</tomjg2…></char…>

:) it’s more about =F3/C++ and the libs that you’re using than it is about =
q

If it’s pure C and clib you can either str_cat or sprintf
If it’s C++ MFC - CString’s + operator coming in handy or Format method
(accepts same format as printf) for trickier cases
etc.

Cheers,
_Oz_

ThanksOn Jul 16, 8:05?pm, Oleg Zakharov <zakharovo…> wrote:> :) it’s more about ?/C++ and the libs that you’re using than it is about q>> If it’s pure C and clib you can either str_cat or sprintf> If it’s C++ MFC - CString’s + operator coming in handy or Format method> (accepts same format as printf) for trickier cases> etc.>> Cheers,> Oz>> On Sat, Jul 16, 2011 at 10:54 PM, tomjg2...@yahoo.com> <tomjg2…>wrote:>>>> > A nice and simple solution! Thanks>> > I have just one further question, is there a way to read variables> > into the string as well?>> > So for example if I wanted to read in the date variable into the> > string:> > const char* date = “2011.07.11”;>> > “select price from trade where date<=“READ THE VARIABLE DATE IN HERE”,> > sym in $\"MMM US Equity\""&gt;&gt; &gt; Thanks&gt;&gt; &gt; On Jul 16, 5:27 pm, Charles Skelton <char...> wrote:&gt; &gt; &gt; escape the "&gt; &gt; &gt; i.e.&gt; &gt; &gt; Q(!(x=k(c,"select time from trade where sym = $"HPQ US> > > Equity"”,0)),“err”)>> > > On Sat, Jul 16, 2011 at 2:01 PM, tomjg2...@yahoo.com <> > tomjg2...@yahoo.com>wrote:>> > > > Hi,>> > > > I have kdb+ interfacing with c++, and it works fine using the sample> > > > databases as the sym names have no spaces eg:>> > > > int port = 5001;> > > > int c = khp(“localhost”, port); //Connect to KDB> > > > Q(!(x=k(c,“select time from trade where sym in HPQ",0)),"err")&gt;&gt; &gt; &gt; &gt; However, I have been collecting tick data from Bloomberg and I used&gt; &gt; &gt; &gt; sym names such as HPQ US Equity which has created a problem as in q> > > > you would query:>> > > > select from trade where sym = $"HPQ US Equity"&gt;&gt; &gt; &gt; &gt; But I am not sure there is a way in c++ to handle this as it sees it&gt; &gt; &gt; &gt; as 2 seperate strings:&gt;&gt; &gt; &gt; &gt; Q(!(x=k(c,"select time from trade where sym = $“HPQ US Equity””,> > > > 0)),“err”)>> > > > ie first string: “select time from trade where sym = `$”, then HPQ US> > > > Equity and a second empty string “”.>> > > > Maybe there is a way in c++ to handle this that I have overlooked, or> > > > there is another way to handle spaces in kdb+ which isnt using “”?> > > > Otherwise is there a way to change the syms in my historical database> > > > to remove the ? ?’ US Equity’ part?>> > > > Any help would be much appreciated!>> > > > –> > > > You received this message because you are subscribed to the Google> > Groups> > > > “Kdb+ Personal Developers” group.> > > > To post to this group, send email to personal-kdbplus@googlegroups.com> > .> > > > To unsubscribe from this group, send email to> > > > personal-kdbplus+unsubscribe@googlegroups.com.> > > > For more options, visit this group at> > > >http://groups.google.com/group/personal-kdbplus?hl=en.-Hide quoted> > text ->> > > - Show quoted text ->> > –> >

Submitted via Google Groups</char…></tomjg2…></zakharovo…>

or do it on the q side

k(c,“{select price from trade where date<=3D"D"$x,sym in `$"MMM US
Equity"}”,date,0)

(or sg like that, I haven’t worked much with this direction of the API

My method:

K x;
x = k(c,“{select price from trade where date<=x,sym in `$"MMM US Equity"}”,ks(const_cast<char*>date),(K)0);