opennetadmin / ona

OpenNetAdmin IP Address Management (IPAM) system
opennetadmin.com
GNU General Public License v2.0
136 stars 34 forks source link

problem with ona_sql queries #142

Closed SyBernot closed 5 years ago

SyBernot commented 5 years ago

v18.1.1. Running on php5.6 this works:

dcm.pl -r ona_sql  sql='SELECT * FROM `ona_logs` where `id`=?' 1=1
id:timestamp:username:remote_addr:message:context_name
1:2019-01-30 11:48:42:xxxx:xxxx:INFO => You have not made a change to the value or description.:DEFAULT

this does not

dcm.pl -r ona_sql  sql='SELECT * FROM `ona_logs`'
Input array has 1 params, does not match query: 'SELECT * FROM `ona_logs`'<br>
3
ERROR => SQL query failed: []

I know this works fine with my old install (php5.3 v13.03.01) and I can't see any changes to sql.inc.php. I suspect it's a combination of a bug in sql.inc.php and a change in the php-mysql stuff. What's bothersome about it is the error doesn't show up in the return and there's that

<br>
3 

after the error and I have been unsuccessful at tracking where that comes from down. i.e.

dcm.pl -r ona_sql  sql='SELECT * FROM `boop` where `id`=?' 1=1
ERROR => SQL query failed: [Table 'ona_upgrade.boop' doesn't exist]

actually prints the error and doesn't have the trailing garbage. This could be something else on my end, I'm about ready to spin up a fresh vm and just do a fresh install but I wanted to check just in case. So can you get that simple select to run on newer versions of php?

I tried running on 7.2 but ran into the login issue in one of the other bug reports.

SyBernot commented 5 years ago

After poking at this a bit more I found this: https://github.com/ADOdb/ADOdb/issues/146

so in the case where your not passing any bind variables the query should likely be

$rs = $onadb->Execute($options['sql']);

This seems to fix it for me ~219-sql.inc.php

    if ($sqlopts === NULL){
      $rs = $onadb->Execute($options['sql']);
    }else{
      $rs = $onadb->Execute($options['sql'],$sqlopts);
    }
SyBernot commented 5 years ago

found #84 and #126 so I'll go that route