View Issue Details

IDProjectCategoryView StatusLast Update
1031RackTablesdefaultpublic2013-11-10 18:19
Reporterarichard Assigned Toadoom42  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version0.20.5 
Target Version0.20.6Fixed in Version0.20.6 
Summary1031: Search and object update fails and return a blank page
DescriptionSearching an object returns a blank page.

Modifying an object returns a blank page.

In the httpd log :


[Tue Oct 15 12:09:37 2013] [error] [client 192.168.0.3] PHP Fatal error: Call to a member function execute() on a non-object in /opt/RackTables-0.20.5/wwwroot/inc/database.php on line 3733, referer: http://racktables/index.php?page=object&tab=edit&object_id=17

The line 3733 is the line $prepared->execute ยง$args); in the function usePreparedSelectBlade :


function usePreparedSelectBlade ($query, $args = array())
{
        global $dbxlink;

        try
        {
                $prepared = $dbxlink->prepare ($query);
                $prepared->execute ($args);
                return $prepared;
        }
        catch (PDOException $e)
        {
                throw convertPDOException ($e);
        }
}


Steps To ReproduceA simple search :

http://racktables/index.php?page=search&last_page=object&last_tab=default&q=uranus301

triggers the problem.

Additional InformationAfter debugging, I have found and corrected several errors :

1) no test for $dbxlink->prepare() returning null in usePreparedSelectBlade

After adding some debug, I found out that $dbxlink->prepare ($query); returns a null object without triggering an exception (this is a well known beavior of PDO).

It seams that a new select was issued on the transaction without fetching the previous results.

2) The real fault is in getStickerSearchResults


function getStickerSearchResults ($tablename, $what)
{
        $result = usePreparedSelectBlade
        (
                'SELECT object_id, attr_id FROM AttributeValue AV ' .
                "INNER JOIN ${tablename} O ON AV.object_id = O.id " .
                'WHERE string_value LIKE ? ORDER BY object_id',
                array ("%${what}%")
        );

        $map = getAttrMap();
        $ret = array();
        while ($row = $result->fetch (PDO::FETCH_ASSOC))
        {
                if ($map[$row['attr_id']]['type'] == 'string')
                {
                        $ret[$row['object_id']]['id'] = $row['object_id'];
                        $ret[$row['object_id']]['by_sticker'][] = $row['attr_id'];
                }
        }
        return $ret;
}

Here the call to $map = GetAttrMap() use the same transaction and triggers the problem.

A very simple correction is to put $map = GetAttrMap() on the top of the function :

function getStickerSearchResults ($tablename, $what)
{
       $map = getAttrMap();
       $result = usePreparedSelectBlade
        (
                'SELECT object_id, attr_id FROM AttributeValue AV ' .
                "INNER JOIN ${tablename} O ON AV.object_id = O.id " .
                'WHERE string_value LIKE ? ORDER BY object_id',
                array ("%${what}%")
        );

        $ret = array();
        while ($row = $result->fetch (PDO::FETCH_ASSOC))
        {
                if ($map[$row['attr_id']]['type'] == 'string')
                {
                        $ret[$row['object_id']]['id'] = $row['object_id'];
                        $ret[$row['object_id']]['by_sticker'][] = $row['attr_id'];
                }
        }
        return $ret;
}

This will correct the search case.

3) Syntax error in update query

The update of an object fails because of a syntax error in commitIdateAttrValue. There is a missing space in the first select :


        $result = usePreparedSelectBlade
        (
                "SELECT type AS attr_type, av.* FROM Attribute a " .
                "LEFT JOIN AttributeValue av ON a.id = av.attr_id AND av.object_id = ?" .
                "WHERE a.id = ?",
                array ($object_id, $attr_id)
        );

You need to add a space between the ? and the WHERE clause :

        $result = usePreparedSelectBlade
        (
                "SELECT type AS attr_type, av.* FROM Attribute a " .
                "LEFT JOIN AttributeValue av ON a.id = av.attr_id AND av.object_id = ? " .
                "WHERE a.id = ?",
                array ($object_id, $attr_id)
        );

TagsNo tags attached.

Activities

infrastation

infrastation

2013-10-17 16:59

administrator   ~0001869

Would you like to author a git commit to fix these issues?
adoom42

adoom42

2013-11-10 18:19

administrator   ~0001927

I was unable to reproduce the errors, but committed your changes anyway as they seem reasonable. Thanks for the patch.

Issue History

Date Modified Username Field Change
2013-10-15 14:39 arichard New Issue
2013-10-17 16:59 infrastation Note Added: 0001869
2013-11-10 18:19 adoom42 Note Added: 0001927
2013-11-10 18:19 adoom42 Assigned To => adoom42
2013-11-10 18:19 adoom42 Status new => closed
2013-11-10 18:19 adoom42 Resolution open => fixed
2013-11-10 18:19 adoom42 Fixed in Version => 0.20.6
2013-11-10 18:19 adoom42 Target Version => 0.20.6