I have a datastore using a connector to work with a MySQL database. The datastore provides services to a grid and a form. Update & delete work perfectly. But adding records is a problem.
The table index (“id”) is an autoIncrement field. But when I use the add() method on the datastore, the system creates an index resembling “-1780040036” which populates the grid. If I query the database externally, I see a different id value resembling “1359724592796”.
Any updates I apply to the row with the -1780040036 id do not apply to the record, and are lost. I have to manually reload the grid, at which time the new index value of 1359724592796 exists, and updates and deletes apply correctly.
QUESTIONS:
- can the system be configured to allow MySQL to generate its own id value? If so, how?
- If the answer to question 1 is too involved, how could I automatically refresh the values in the grid so I can retrieve automatically the actual index instead of the bad number?
By default datastore will generate random uid based on current timestamp, which is huge number, which may be greater than int field, which causes problem in your case ( it can’t save its correctly, and because of overflow you have get negative numbers ) So the simplest solution would be change to the bigint field for id
- can the system be configured to allow MySQL to generate its own id value? If so, how?
Yes, and it is the recommended way of usage.
If you have autoincrement field for id, and have not used id in data fields of grid or form ( so it is not directly editable ), server side code can send new id after data saving back to client, where it will be applied to the grid and form. ( if you are using connector it must be done automatically )
Also, try to update datastore.js with the next one.
download/file.php?id=5969
It fixes one problem with id auto-updating.
The updated dataStore.js took care of the problem. Thank you.
Stanislav, I spoke too soon. While the updated row shows the correct id value, if an attempt is made to make an update to that row before refreshing the grid, the negative value shows up again. Apparently the dataStore.js fix only addressed part of the problem.
Can you provide some demo or sample of code ( client side code, without server side scripts and db, will be enough )