SQL CONCAT on serverside

SQL CONCAT on serverside

bacalovbacalov Posts: 22Questions: 3Answers: 0
edited November 2013 in Editor
Hi everybody,
Does anybody figured a way to update on server one column in the DB, using data provided from multiple user-side columns? Something like:
[code]
Field::inst( 'COLUMN1' ),
Field::inst( 'COLUMN2' ),
Field::inst( 'COLUMN3' )->setFormatter( \'CONCAT(COLUMN1, $constant, COLUMN2)\' ),
[/code]

Thank you.

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    Hi,

    I'm sorry to say that the Editor PHP libraries currently do not support SQL functions. The SQL would need to be executed directly (with the sql() method for example: https://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_sql ) or the logic performed outside of the SQL engine.

    This is certainly an area that is going to be looked at for improvements in future, but that the moment the logic just doesn't handle SQL functions and it tries to escape them...

    Allan
  • bacalovbacalov Posts: 22Questions: 3Answers: 0
    edited November 2013
    Thank you, Allan - sign me up for the new 1.3, when it`s released.

    But for now... is there a way to modify the submited field before submision, something like:
    [code]
    "events": {
    "onPreSubmit": function ( o ) {
    $('#DTE_Field_FIELD_1').attr( 'value', $('#DTE_Field_FIELD_1').val() + $('#DTE_Field_FIELD_2').val() )
    }
    [/code]
    I tried the code above, but no luck so far... I guess the field should be called as a data array element, data[FIELD_1] ?
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    onPreSubmit is exactly the correct event to work with:

    [code]
    onPreSubmit: function ( o ) {
    o.data.myField1 = o.data.myField1 + o.data.myField2;
    }
    [/code]

    The format of `o` is the same as the data submitted to the server as described here: https://editor.datatables.net/server/ (in fact, it is exactly the data submitted to the server, so whatever you do to manipulate `o` will be reflected in what is sent to the server.

    Regards,
    Allan
  • bacalovbacalov Posts: 22Questions: 3Answers: 0
    Excelent. Thank you, Allan.
This discussion has been closed.