try something like this: $counter = 0; 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 ($counter < sizeof($feature->attributes)) { $attributesFieldsSql .= ","; $attributesValuesSql .= ","; } $counter ++; } ----- Original Message ----- From: Claire Chastagnol To: cartoweb-users@lists.maptools.org Sent: Friday, September 26, 2008 12:08 PM Subject: [Cartoweb-users] edit plugin
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 ------------------------------------------------------------------------------ _______________________________________________ Cartoweb-users mailing list Cartoweb-users@lists.maptools.org http://lists.maptools.org/mailman/listinfo/cartoweb-users
_______________________________________________ Cartoweb-users mailing list Cartoweb-users@lists.maptools.org http://lists.maptools.org/mailman/listinfo/cartoweb-users