KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Solutions KX Developer – how to extract query text from the request sent to kdb+

  • KX Developer – how to extract query text from the request sent to kdb+

    Posted by yguo on March 30, 2022 at 12:00 am

    Environment:

    KDB+ 4.0, KDB Developer  1.5.1

    Background:

    We are currently evaluating if KX developer can be used as our KDB IDE. One of the requirements is to keep track of all the queries sent from a client (web browser) to the KDB Developer port. To achieve this, we try to create our customized .z.ws implementation and calls KX developer .z.ws within our implementation as follows. Thanks Tim and Jonathan for their help on this!

    ows:.z.ws;
    .z.ws:{[ows;query] 
    if[4h=type query; if[.sys.queryLogging; upsert[`.sys.QueryLog;(.z.P;.z.u;0Nj;query)]];`.sys.lastQueryTime set .z.P; ];ows[query];
    }[ows];

     

    As far as I can tell, “query” is a serialized object sent from the web browser client. And I can find the query text within it if I convert the byte array to a string directly.

     

    00000000: 0000 0065 0000 001c 7b00 2200 7200 6500 ...e....{.".r.e. 00000001: 7100 4900 4400 2200 3a00 3100 3000 3100 q.I.D.".:.1.0.1. 00000002: 3500 7d00 0000 008a 0101 0000 8a00 0000 5.}............. 00000003: 0000 0200 0000 0a00 0800 0000 2e61 782e .............ax. 00000004: 6361 6c6c 6300 0002 0000 00f5 666e 00f5 callc.......fn.. 00000005: 6461 7461 0000 0002 0000 000a 0019 0000 data............ 00000006: 002e 6178 6564 692e 7765 622e 6469 7370 ..axedi.web.disp 00000007: 6c61 7941 6e64 4772 6964 0000 0100 0000 layAndGrid...... 00000008: 6300 0002 0000 00f5 6578 7072 6573 7369 c.......expressi 00000009: 6f6e 00f5 6374 7800 0000 0200 0000 0a00 on..ctx......... 0000000a: 0700 0000 6162 6364 653a 320a 0001 0000 ....abcde:2..... 0000000b: 002e ..

     

    My question is how to properly extract the query text from the serialized object. (“abcde:2” in this case)

    I’ve tried to deserialize it with -9!. A badmsg error was returned. I guess the object was not serialized with the serialize function defined in kdb/c.js at master KxSystems/kdb GitHub. And KX developer must have its own way of serializing/deserializing objects.

    Any suggestion is appreciated!

    yguo replied 9 months, 1 week ago 2 Members · 1 Reply
  • 1 Reply
  • leahs

    Member
    March 31, 2022 at 12:00 am

    Hello @yguo,

    Firstly, welcome to the KX Community! Thank you for sharing your question with us.

    One option that you have is in your developer plugin to define:

    .axedi.plugin.preprocess: { x } // takes a string, returns a string

    This is run before executing any line, and the result of this is sent on for execution (could return “” to deny execution, which will return :: ).

    This will catch execution from the scratchpad, files, VI, transformer, etc.

    We hope this helps you achieve your objective!

    Kind regards,

    Leah

Log in to reply.