Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Feb 29, 2008 15:04
open dhtmlx forum
Design error in dataprocessor

I use the DHTMLX-tree in combination with autoloading. When I insert a new child with insertNewChild() I do have to specify a node id. But I do not want to calculate this id on the client side, as it is the id of the server sided database. So I choose e.g. -1 as the node's id.

Now I can ignore the sent id in my server script, compute and use the new valid database id X, and return -1 as "inserted". Now I do have a node in the client's tree with the id -1, which is inconsistent with the database.

Second option: I return X as inserted - as is the actual id I inserted into the database. But now the dataprocessor seems to be in some kind of infinite loop, it keeps sending the command to insert node "-1" over and over again! I guess it cannot identify the result X as the result of the "insert -1"-command.

The only workaround I can think of is to call "insert -1", ignore the -1 on server side, insert a valid id instead, return "inserted -1", and refresh the new node's parent node of the tree "manually". But this cannot be the sense of the dataprocessor and the autoupdate!
Answer posted by Support on Mar 04, 2008 06:19
Actually the dataprocessor was created with such situation in mind.

a) When you creating new element you set any unique ID for it ( -1 is not the best choice, because ID still need to be unique, when you creating few new rows ) , ID on client has not any relation to real DB
b) Dataprocessor send data to server, including ID
c) Server side code ignores incoming ID and created record in DB , real ID calculated
d) Server side code sends data back to clietn

<data>
    <action sid="121234" tid="123" type="insert" />
</data>

Where  
    sid - original ID from client
    tid - the real ID which was assigned after inserting data in DB

e) on client side , dataprocessor check the response and change the @sid ID to the @tid ID, so in result newly created element has the same ID as was assigned on server side.

So you just need to return correct @sid , @tid values - all other will be done automatically


Answer posted on Mar 03, 2008 08:33
>> on client side , dataprocessor check the response and change the @sid ID to the @tid ID, so in result newly created element has the same ID as was assigned on server side.

No - the new element has the ID "sid", not "tid". I have to refresh the tree to see the new ID
Answer posted on Mar 03, 2008 08:56
Unfortunately I am not able to create the example database from dhtmlxTree\samples\dataprocessor\php:

#1064 - You have an error in your SQL syntax near 'CURRENT_TIMESTAMP(),
  PRIMARY KEY  (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSE' at line 9


So I am not able to recreate the problem with that example - but I just added a onClick-event to my tree, where I alert() the currently clicked (and the previously selected) ID, it is always -1. Here's what I  send:

GET http://192.168.1.113:8163/dev/server/update.php?tr_id=-1&tr_pid=2&tr_order=4&tr_text=abc&%21nativeeditor_status=inserted

and this is the servers response:

<?xml version="1.0" encoding="UTF-8"?>
<data>
 <action type="inserted" sid="-1" tid="209"/>
</data>

but the alert() in the onClick-event tells me I clicked node -1


Answer posted by Support on Mar 04, 2008 05:48
The issue caused by different version of MySQL ( because the same SQL code works fine locally ), basically your can remove default clause, it has not any critical sense.

>>and this is the servers response:
The text of response is not fully correct, it need to be
   
<?xml version="1.0" encoding="UTF-8"?>
<data>
 <action type="insert" sid="-1" tid="209"/>
</data>

Answer posted on Mar 04, 2008 08:54
...and once again it's my fault :-) I just returned the nativeeditor_status. Funny, that it worked with updated/deleted instead of update/delete
Anyway, thanks a lot

Answer posted by Support on Mar 04, 2008 09:45
The ction@type may contain any value - it allows to create custom server side responses ( which allows to handler server side errors for example), but the behavior with ID changing works only for "insert" type.