[Cartoweb-users] edit plugin

Claire Chastagnol chastagnol.claire at wanadoo.fr
Fri Sep 26 06:08:34 EDT 2008


Hi everybody,

I'm trying to extend the edit plugin because I need to update some geographic data with atrributes which come from a different table.



 The sql query generated isn't right : I have some "," problems:
 I have this error message indeed:
 
 Userinfo: INSERT INTO public.evenements_evolution (id_route, id_ev, id_etat, localisation_pr, date, heure, description, )
VALUES ('850', '2', '2', 'pr8 pr9', '1 octobre 08', '12h', 'chaussee glissante', )  [nativecode=ERREUR:  erreur de syntaxe sur ou près de « ) »
LINE 1: ..._etat, localisation_pr, date, heure, description, )VALUES ('... 
This is the code I put in my extension for updating:

    protected function updateFeature($feature) {
        $db = $this->getDb($this->layer);
        
        $editableAttributes = $this->getEditableAttributes($this->attributes);
        
        $this->editSchema = 'public';
        $this->editTable = $this->getMetadataValueString($this->layer, 'edit_table');
        $editTables = explode(',', $this->editTable);
        

         if (isset($feature->attributes) && $feature->attributes) {
            $attributesFieldsSql = $attributesValuesSql = '';
            foreach ($feature->attributes as $key => $val) {
                $val = ($val == '') ? 'NULL' : 
                       sprintf("'%s'", Encoder::decode(Utils::addslashes($val), 
                                                       'config'));
                if (in_array($key, $editableAttributes)) {
                    $attributesFieldsSql .= "$key, ";
                    $attributesValuesSql .= "$val, ";
                }
            }
            if ($attributesValuesSql == '')
                $attributesValuesSql = NULL;
        } else {
            $attributesFieldsSql = '';
            $attributesValuesSql = NULL;
        }
            $sql = sprintf ('INSERT INTO %s.%s (%s)' .
                        "VALUES (%s) ",
                        $this->editSchema,
                        $editTables[1],
                        $attributesFieldsSql,
                        $attributesValuesSql
                       ); 
        $this->log->debug($sql);
        $queryId = $db->query($sql);
        
        Utils::checkDbError($queryId, 'Unable to insert feature in edit database');
        return $queryId;
        
    }

How can I do? (I tried with the substr function but without success...)

Thanks.
Claire



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/cartoweb-users/attachments/20080926/c6ca0e2f/attachment-0001.html


More information about the Cartoweb-users mailing list