Database error: SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'radians'

1,622 views
Skip to first unread message

Troy Borja

unread,
Jun 25, 2013, 4:06:10 AM6/25/13
to porp...@googlegroups.com
Hello,

I installed a PorPoise server and extended the default sqlpoiconnector.class.php to select the fields in the database that Dashboard uses. Does anyone have any idea why this error shows up on Dashboard?

Database error: SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'radians'

If I go to Layar and test my POI Server I get this JSON response.

{
    "hotspots": [], 
    "layer": "smar", 
    "errorString": "Database error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'latitude' in 'field list'", 
    "morePages": false, 
    "errorCode": 20, 
    "nextPageKey": null
}

Here is my extended SQLPOIConnector

<?php

class DashboardPOIConnector extends SQLPOIConnector {
    protected function buildQuery(Filter $filter = NULL) {
        if (empty($filter)) {
            $sql = "SELECT Id AS id, anchor_geolocation_lat AS lat, anchor_geolocation_lon AS lon, text_description  as line2, text_footnote as line3, text_title  as title FROM$
        } else {
            $sql = "SELECT Id AS id, anchor_geolocation_lat AS lat, anchor_geolocation_lon AS lon, text_description  as line2, text_footnote as line3, text_title  as title, " .$
                sqrt(
                    pow(sin((radians(" . addslashes($filter->lat) . ") - radians(latitude)) / 2), 2)
                    +
                    cos(radians(" . addslashes($filter->lat) . ")) * cos(radians(latitude)) * pow(sin((radians(" . addslashes($filter->lon) . ") - radians(longitude)) / 2), 2)
                )
            ) AS distance
            FROM POI";
            if (!empty($filter->radius)) {
                $sql .= " HAVING distance < (" . addslashes($filter->radius) . " + " . addslashes($filter->accuracy) . ")";
            }
            $sql .= " ORDER BY distance ASC";
        }

        return $sql;
    }
}

Any help would be greatly appreciated.

Troy Borja

unread,
Jun 25, 2013, 4:11:34 AM6/25/13
to porp...@googlegroups.com
Sorry this is the query in the extended class

        /**
         * Build SQL query based on $filter
         *
         * @param Filter $filter
         *
         * @return string
         */
        protected function buildQuery(Filter $filter = NULL) {
                /** @var array Contains all "WHERE" clauses for the query */
                $aWhereClauses = array();
                $aOrderBy = array();

                // Start with the minimal query
                $sql = 'SELECT P.Id AS id, P.anchor_geolocation_lat AS lat, P.anchor_geolocation_lon AS lon, P.text_description  as line2, P.text_footnote as line3, P.text_title  as title';

                // If the filter requires so, add distance calculation
                if ($filter->lat !== NULL && $filter->lon !== NULL) {
                        $sql .= " , " . GeoUtil::EARTH_RADIUS . " * 2 * asin(sqrt(pow(sin((radians(" . addslashes($filter->lat) . ") - radians(anchor_geolocation_lat)) / 2), 2)$
                        $aOrderBy[]='distance';
                }

                $sql.=' FROM POI P , Layer L';
                $aWhereClauses[]='P.LayerID = L.id';

                if ($filter->layerName) {
                        $aWhereClauses[]="L.Layer='".$filter->layerName."'";
                }

                /*if (!empty($filter->requestedPoiId)) {
                        $aWhereClauses[]="id='" . addslashes($filter->requestedPoiId) . "'";
        }*/
                if (count($aWhereClauses)>0) {
                        $sql .= " WHERE ".implode(' AND ', $aWhereClauses);
                }
                if (!empty($filter->radius) && ($filter->lat !== NULL && $filter->lon !== NULL)) {
                        $sql .= ' HAVING ( distance<('.addslashes($filter->radius).'+'.addslashes($filter->accuracy).') OR anchor_referenceImage!="" )';
                }
                if (count($aOrderBy)>0) {
                        $sql .= ' ORDER BY '.implode(',', $aOrderBy).' ASC';
                }

                return $sql;
Reply all
Reply to author
Forward
0 new messages