Last problem : Inserts

Hi,

In an other thread you gave me an advice on correcting the insert function.
You wrote :

I have been studying the docs to try to find out what that means. It’s to hard. The docs are to summerized to understand it (at least for me :mrgreen: )

Is there no sample for the php backend, what to do exactly in case of insert, while using the dataprocessor ?

Thanks in advance,
Steven

the server side must return response as

<data> <action type="insert" sid="origninal id here" tid="new id here" /> </data>

docs.dhtmlx.com/doku.php?id=dhtm … s#response
update.zip (1015 Bytes)

Wow, that’s completely different from the way i am working.
can I mix the 2 ?

I attached my version of update.php that I use now.
No, that is not allowed, so i’ll insert it here (the board does not accept .php, nor .txt file, what does it accept ?)

[code]

<?php require_once('/home/webxxx/settings.php'); require_once('./dhtmlx/dhtmlxConnector/codebase/grid_connector.php'); $id = $_GET["code"]; if (!$id) die("No id, cant do anything yet, save first the gite data, then retry"); $feed = file_get_contents('../../../'.APP_DIR.'/xxx/yyy/config.xml'); $xml = new SimpleXmlElement($feed); $dbuser = $xml->dbuser; $dbpassword = $xml->dbpassword; $db = $xml->db; $dbserver = $xml->dbserver; $link = mysql_pconnect ($dbserver, $dbuser, $dbpassword); if ( !mysql_ping( $link ) ) { $link = mysql_pconnect( $dbserver, $dbuser, $dbpassword ); } if (! $link) { die ('Could not connect to mysql server, tell steven '); } if (!mysql_select_db ($db, $link) ) { die ('Could not open the database, mysql returned: '.mysql_error().', tell steven '); } mysql_set_charset('utf8',$link); $rest = mysql_query("SELECT prix1_nom, prix2_nom FROM gite where id = $id",$link); if ($rest) { $row = mysql_fetch_object($rest); $mon1 = $row->prix1_nom; if ($mon1 == "") $mon1 = "Prix 1"; $mon2 = $row->prix2_nom; if ($mon2 == "") $mon1 = "Prix 2"; } else { $mon1 = "Prix 1"; $mon2 = "Prix 2"; } $mon2 .= " €"; $mon1 .= " €"; function my_code($data) { $id = $_GET['code']; $data->set_value("id_gite", $id); } function formatting($row){ //render field as details link $data = $row->get_value("start"); $row->set_value("start",date("d-M",strtotime($data))); $data = $row->get_value("end"); $row->set_value("end",date("d-M",strtotime($data))); $data = $row->get_value("Arrtime"); $row->set_value("Arrtime",date("H:i",strtotime($data))); $data = $row->get_value("Deptime"); $row->set_value("Deptime",date("H:i",strtotime($data))); $var = $row->get_value("price"); // format this for europe $row->set_value('price', number_format($var,2,","," ")); $var = $row->get_value("price_2"); // format this for europe $row->set_value('price_2', number_format($var,2,","," ")); } function my_update($data){ // TO DO : Check on overlapping dates : forbidden ! $var = $data->get_value("start"); // we have just a daynumber and a month, lets add a year $arr = explode("-",$var); $var = "2010-".$arr[1]."-".$arr[0]; $date = date_create($var); if ($date) { $var = date_format($date, 'Y-m-d'); $data->set_value("start", $var); } $var = $data->get_value("end"); // we have just a daynumber and a month, lets add a year $arr = explode("-",$var); $var = "2010-".$arr[1]."-".$arr[0]; $date = date_create($var); if ($date) { $var = date_format($date, 'Y-m-d'); $data->set_value("end", $var); } $var = $data->get_value("price"); // format this for europe $data->set_value('price', str_replace(',','.',(str_replace(' ', '',$var)))); $var = $data->get_value("price_2"); // format this for europe $data->set_value('price_2', str_replace(',','.',(str_replace(' ', '',$var)))); } function my_filter($obj) { $id = $_GET['code']; $obj->add("id_gite",$id,"="); //filter for this gite, since render_sql does not work } $grid = new GridConnector($link); $config = new GridConfiguration(); $config->setHeader("gite,Nom,Début,Fin,Arrivé,Départ,$mon1,$mon2,Couleur,Actif"); $config->setInitWidths("1,160,70,70,70,70,90,90,60,60"); $config->setColAlign("Left,left,left,left,left,left,right,right,center,center"); $config->setColTypes("ro,ed,ed,ed,ed,ed,ed,ed,cp,ch"); $config->setColSorting("na,str,str,str,str,str,str,str,str,str"); $grid->set_config($config); $grid->event->attach("beforeRender","formatting"); $grid->event->attach("beforeUpdate","my_update"); $grid->event->attach("beforeFilter","my_filter"); $grid->event->attach("beforeProcessing", "my_code"); // $grid->enable_log("error.log", true); $grid->enable_live_update('period'); $grid->render_table('period', "id","id_gite,name,start,end,Arrtime,Deptime,price,price_2,color,active"); // $sqlStr = "SELECT * from period WHERE id_gite = $id"; // $grid->render_sql($sqlStr, "id", "id_gite, name,start,end,Arrtime,Deptime,price,price_2,color,active"); ?>[/code]

So, I suppose, I take just the parts on insert, and use them, and that, just in case of insert ?
The update and delete is done automatically.

Steven

If you are using connector and do not replace default insert routine with custom one - you need not care about return values, they will be set automatically ( assuming that you have autoincrement for ID field )

Yes I do.
All works well exept insert.

I have to do 2 things : Set the fixed field (problem you solved) and, as you told me, return
this xml.

As you can see in my coding, i attached the routines to the grid that handles the different changements i need in case of update / filter / display; that all works just fine.

So, I suppose I have to either :

  1. look if my update routine receives an insert, and then return the XML or
  2. Integrate the coding you’ve send me in the update.php file.

If I do nothing, insert are done as many times as I fill in a field for the new record in the grid.
Each time I enter data, a new record is written, with that data added.

Can you enable log in the connector and send results for incorrect operation.
The code snippet, which you have published above, doesn’t change the logic of insert of update, but just alter some values, which must not break functionality.

Ok, this is the log for the insert.
I inserted one row and filled it with values (on the screen).

Hope this helps.

For each operation log ends with

Edit operation finished
0 => action:error; sid:1295077062462; tid:43;

action:error - means that connector doesn’t count operation as finished
it can occurs when

  • $action->error() was called from some event - seems not your case
  • error occurs during SQL execution

basically, because of error connector doesn’t count operation as finished, and repeat it each time.

The next code from the log
“INSERT INTO period (DATAID, TYPE, USER) VALUES (‘43’, ‘inserted’, ‘’)”
how it is executed? There is no logic in previouly provided code, which can cause it.

Hi,

This is done in update.php from the connector codebase.
The code is :

[code] private function log_update_action($actions_table, $dataId, $status, $user) {

	$sql = "INSERT INTO {$actions_table} (DATAID, TYPE, USER) VALUES ('{$dataId}', '{$status}', '{$user}')";

	$this->sql->query($sql);

    if ($this->demu)

        file_get_contents($this->demu);

}

[/code]

So, it’s something your software is doing…
Why ? Beats me !

only the $actions_table var is filled with my table name. Of course these fields donnot exists there.

By the way : if I comment “$this->sql->query($sql);” out, all works just fine !!!
(but that is not a very good solution)

Steven

comment the next line in your php code

$grid->enable_live_update('period');

This one enable update-sync mode, which is not used in your scenario, and not necessary for default CRUD operations.

Great, thanks a lot Stanislav.

All is working perfect now
(untill I find the next problem :laughing:

Thanks,
Steven