Open Source Training Seminar FreePBX Paid Support

Ticket #2778 (closed Bugs: fixed)

Opened 5 months ago

Last modified 1 month ago

sql error in core_trunks_list() - no such column: d.value

Reported by: tzafrir Assigned to: ethans
Priority: minor Milestone: 2.5
Component: Sqlite3 Version: 2.3.1
Keywords: Cc:
Confirmation: Need Feedback SVN Revision (if applicable):
Backend Engine: All Backend Engine Version:

Description

The following text in core/functions.inc.php:core_trunks_list() generates a database error.

        if ($amp_conf["AMPDBENGINE"] == "sqlite3")
        {
                // TODO: sqlite work arround - diego
                // TODO: WILL NOT WORK, need to remove the usage of SUBSTRING
                // need to reorder the trunks in PHP code
                $sqlstr  = "SELECT t.variable, t.value, d.value state FROM `globals` t ";
                $sqlstr .= "JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\_%') d ";
                $sqlstr .= "ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\_%' ";
                $sqlstr .= "UNION ALL ";
                $sqlstr .= "SELECT v.variable, v.value, concat(substring(v.value,1,0),'off') state  FROM `globals` v ";
                $sqlstr .= "WHERE v.variable LIKE 'OUT\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ";
                $sqlstr .= " ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\_%' ) ";
                $sqlstr .= "ORDER BY variable";

                //$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");
                $unique_trunks = sql($sqlstr,"getAll");
        }

The error:

sqlite> SELECT t.variable, t.value, d.value state FROM globals t JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\_%') d ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\_%' UNION ALL SELECT v.variable, v.value, concat(substring(v.value,1,0),'off') state FROM globals v WHERE v.variable LIKE 'OUT\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\_%' );

SQL error: no such column: d.value

The table:

sqlite> .schema globals
CREATE TABLE `globals` (
  `variable` char(20) NOT NULL default '',
  `value` char(50) NOT NULL default '',
  PRIMARY KEY  (`variable`)
);

Attachments

sqlite_trunk_query (1.6 kB) - added by tzafrir on 04/07/08 13:16:34.
sqlite3 patch in Debian package

Change History

04/07/08 10:44:39 changed by tzafrir

Frankly, I don't fully understand all the exact details of the above SQL query. I know what it's supposed to do. Here's a simpler replacement.

$possible_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable,value","getAll");
$disabled_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUTDISABLE_%' ORDER BY variable,value","getAll");
$unique_trunks = array_diff($possible_trunks, $disabled_trunks);

The MySQL version should quote the '_'.

I figure that this is the simple and wrong solution. So please prove it so :-)

04/07/08 12:50:59 changed by p_lindheimer

  • confirmation changed from Unreviewed to Need Feedback.
  • milestone changed from Cut Line to 3.0.

I don't think this was ever tested against sqlite, The MySQL version works. If you have a query or solution that works with sqlite that you have tested I will be glad to submit it since it will not effect the MySQL main code. I don't want to mess with the MySQL version since all of this is going to go away when we replace all of the trunks/routing code which is hopefully in the coming release.

04/07/08 13:16:34 changed by tzafrir

  • attachment sqlite_trunk_query added.

sqlite3 patch in Debian package

04/07/08 13:17:46 changed by tzafrir

I attach the patch I include in the Debian package. I only tested it so far in very simple cases, though.

04/08/08 01:14:00 changed by tzafrir

So what have others done here?

The astfin guys seem to just use:

$unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");

And ignore the case of disabled trunks.

http://freetel.svn.sourceforge.net/viewvc/freetel/freepbx-sandbox/patch/freepbx.patch?revision=13

07/24/08 17:48:51 changed by lazytt

  • owner changed from diego_iastrubni to ethans.

07/31/08 09:35:25 changed by ethans

  • status changed from new to closed.
  • resolution set to fixed.

(In [6228]) Finalizes sqlite3 support for core functions.inc.php. Fixes #2778. Adjusts SQL syntax for sqlite3 queries dealing with "globals" table variables with _ in their name. Sqlite3 doesn't escape the same as MySQL does.

Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads