[SOLVED] SQL field names with hyphen minus

[SOLVED] SQL field names with hyphen minus

fobosfobos Posts: 14Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
Hi,

I wanted to compliment the work done on this component. It 'really well done!

But I have a small problem, basically I'm using the example :

http://datatables.net/release-datatables/examples/data_sources/server_side.html

but having the column names with the hyphen (- minus) the output is null, I tried to put the quotes sql but nothing, I can not make a print screen of the values ​​in my database. Is there anyone who can help me.

Thanks in advance

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    The first thing I would suggest is to modify the server-side processing script and echo out the SQL that is being used to query the database (assuming you are using my demo PHP scripts then use echo $sQuery; just after sQuery is constructed). You will get an alert error when you do that, but look at the return in Firebug and you'll see the SQL.

    Then run that against your DB using pgMyAdmin or whatever and see what modifications are required (most like assign ` around the field names). If that is the case, then you know what modifications need to be made to the script.

    Allan
  • fobosfobos Posts: 14Questions: 0Answers: 0
    edited November 2011
    Thanks for the quick response,
    I changed manually the select query sql inserting quotes.
    In the file connector.php I echo the output from all fields, except that I get this error:

    DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
  • fobosfobos Posts: 14Questions: 0Answers: 0
    edited November 2011
    I have tried to validate JSON http://jsonlint.com/, and is valid.

    It may be that the error is given by the large number of records in the database. because there are 80 000 records
  • fobosfobos Posts: 14Questions: 0Answers: 0
    [code]
    {
    "sEcho": 0,
    "iTotalRecords": "81665",
    "iTotalDisplayRecords": "1",
    "aaData": [
    [
    "02790",
    "1",
    "1",
    "D01",
    "2011-10-04",
    null,
    "attach.tif"
    ]
    ]
    }
    [/code]

    jSON is validate, but in output display this warning :

    DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
  • fobosfobos Posts: 14Questions: 0Answers: 0
    Ok, I solved.
    I changed manually the select query:

    [code]
    $sQuery = "
    SELECT SQL_CALC_FOUND_ROWS `A-1`, `A-2`, `SHEET`, `REVISION`, `D-IMPORT`,`FILE-NAME`
    FROM $sTable
    $sWhere
    $sOrder
    $Desc
    $sLimit

    ";
    [/code]

    After that for every SQL statement I manually add the quotes that I recommend to any SQL way of putting it.

    [code]
    /*
    * Ordering
    */
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Excellent - thanks for posting a follow up on this. The reason you would have been getting a JSON warning from DataTables when you added the SQL output, is because that SQL output would make the returned string as a whole invalid JSON. But that's okay for debugging, and then remove the echo when you want it to work :-)

    I think adding these quotes to the default server-side processing script is probably quote a good idea. I can't see any harm in doing so, so I'll do that soon.

    Regards,
    Allan
This discussion has been closed.