[Cartoweb-users] edit plugin
Oliver Christen
oliver.christen at camptocamp.com
Fri Sep 26 06:14:53 EDT 2008
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 at 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 at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/cartoweb-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/cartoweb-users/attachments/20080926/80c7a53d/attachment.html
More information about the Cartoweb-users
mailing list