New event ID isn't the real ID

Hi,

I’m using DHTMLX Scheduler since some months ago. I use the PHP Connector and CI models to interact with the SQL Server database. Today I’ve discovered a bug in our application, and it wasn’t present in the past.

I discovered the bug adding a new event to the timeline, and after that, trying to delete it. It seems deleted but if I reload the page the event remains, and it is still present in the database. I added that in the app:

scheduler.attachEvent("onEventIdChange", function(old_id,new_id){ console.log(old_id); console.log(new_id); });
And I’ve seen that the new_id isn’t the real ID of the event in the database. For example, the eventID of the new event in the database is 43899 (autonumeric key) and the new_id returned by dhtmlx scheduler is 18345.

I don’t know which change have introduced the bug, maybe the latest DHTMLX Scheduler updates? Please, help me to debug that :cry:

Hello,
please try to enable connector logging screencast.com/t/WkIbI2cbJui and check the log file after you add an event
The log entry should contain a full info of current config and operation (including used database id), maybe it will give a clue. Also you may check the server response from the connector (using Network tab of browser dev tools), to see if the response is valid

We can’t reproduce the problem from our side, so probably it’s related to the local configuration.

Connector log:

[code]====================================
Log started, 09/01/2015 08:52:24

DataProcessor object initialized
1420789930543_start_date => 2015-01-09 21:00
1420789930543_end_date => 2015-01-10 06:00
1420789930543_necessitatId => 39
1420789930543_text => EZQUIOGA ROURA DAVID
1420789930543_id => 1420789930543
1420789930543_professionalId => 2687
1420789930543_necessitatDesc => TECNIC DE CAMP
1420789930543_EsGuardiaLocalitzable => 0
1420789930543_categoriaDesc => ADMINISTRATIU/VA
1420789930543_bloqNomina => 0
1420789930543_readonly => 0
1420789930543_teContracte => 1
1420789930543_EventSubstitutId =>
1420789930543_esAbsencia =>
1420789930543_incidencia =>
1420789930543_horariIncidencia =>
1420789930543_coincidencia => 0
1420789930543_dhx_editor_status => inserted
ids => 1420789930543

Row data [1420789930543]
dataInici => 2015-01-09 21:00
dataFi => 2015-01-10 06:00
necessitatId => 39
professionalNom => EZQUIOGA ROURA DAVID
CalendariProfessionalID => 1420789930543
professionalId => 2687
necessitatDesc => TECNIC DE CAMP
EsGuardiaLocalitzable => 0
categoriaDesc => ADMINISTRATIU/VA
bloqNomina => 0
readonly => 0
teContracte => 1
EventSubstitutId =>
esAbsencia =>
incidencia =>
horariIncidencia =>
coincidencia => 0
dhx_editor_status => inserted

data
dataInici => 2015-01-09 21:00
dataFi => 2015-01-10 06:00
necessitatId => 39
professionalNom => EZQUIOGA ROURA DAVID
CalendariProfessionalID => 1420789930543
professionalId => 2687
necessitatDesc => TECNIC DE CAMP
EsGuardiaLocalitzable => 0
categoriaDesc => ADMINISTRATIU/VA
bloqNomina => 0
readonly => 0
teContracte => 1
EventSubstitutId =>
esAbsencia =>
incidencia =>
horariIncidencia =>
coincidencia => 0
dhx_editor_status => inserted

Event code for insert processed

Edit operation finished
0 => action:inserted; sid:1420789930543; tid:19237;

Done in 0.38010907173157s[/code]

While the real database ID is 43987 (i.imgur.com/vEYc5y8.png)

The server response of the get_events?editing=true request:

<?xml version='1.0' ?><data><action type='inserted' sid='1420789930543' tid='19237' ></action></data>

It’s strange that the IDs returned by the DHTMLX connector aren’t random. The next inserted event have the ID 19238 (1420789930543).

Where can I see how DHTMLX Connector calculates the new event ID?

It’s strange that the IDs returned by the DHTMLX connector aren’t random. The next inserted event have the ID 19238 (1420791742015).

Hi,
can you please show a configuration of the connector?

Configuration? Do you mean that?

[code]require_once(“assets/dhtmlx/dhtmlxConnector/codebase/scheduler_connector.php”);
require_once(“assets/dhtmlx/dhtmlxConnector/codebase/db_phpci.php”);
require_once(“plan_events.php”);
DataProcessor::$action_param =“dhx_editor_status”; // Necessari per integració amb CI

$this->load->model(‘calendariprofessional_model’);
$conn = new SchedulerConnector($this->db, “PHPCI”);
$conn->enable_log(“conn.log”, true);

$conn->event->attach(new Plan_events()); // Update/Delete/…
$events = $this->calendariprofessional_model->get_events_by_necessitat($this->session->userdata(‘usuari_necessitats’), $this->input->get(‘from’), $this->input->get(‘to’)); // Select
$conn->render_array($events,“CalendariProfessionalID”, “dataInici,dataFi,professionalNom,professionalId,professionalNif,necessitatCodi,necessitatId,necessitatDesc,upId,teContracte,categoriaDesc,categoriaId,incidencia,descripcioCP,horariIncidencia,EsGuardiaLocalitzable,EsGuardiaPresencial,bloqNomina,coincidencia,EventSubstituitId,EventSubstitutId,esAbsencia”);[/code]

Plan_events :

public function beforeInsert($data) { $this->load->model('calendariprofessional_model'); $this->calendariprofessional_model->insert($data); }

CalendariProfessional_model :

[code]$data = array();
$data[‘ProfessionalId’] = $action->get_value(“professionalId”);
$data[‘DataInici’] = $action->get_value(“dataInici”);
$data[‘DataFi’] = $action->get_value(“dataFi”);
$data[‘NecessitatId’] = $action->get_value(“necessitatId”);
$data[‘EventSubstituitId’] = ($action->get_value(“EventSubstituitId”) == “”) ? NULL : $action->get_value(“EventSubstituitId”);
$this->db->insert(“GT_CalendariProfessional”, $data);

$action->success($this->db->insert_id());[/code]

Where can I find how DHTMLX Connector calculates the new event ID?

db_phpci.php

public function get_new_id(){ return $this->connection->insert_id(); }

Basically it asks CodeIgniter’s db driver about last inserted id.

Is it possible to not use CodeIgniter to get the last inserted id? I suspect that the problem is the CI connector for the SQL Server database.

Or please, have you got any idea how to bypass this problem? :’( People are deleting events other than which they are selecting.

Isces, thx to pointing me to the key of the problem! I edited the sqlsrv_driver.php from the CodeIgniter installation and found that in the insert_id() function:

return $this->query(‘select @@IDENTITY as insert_id’)->row(‘insert_id’);

and changed if to:

return $this->query(‘select SCOPE_IDENTITY() as insert_id’)->row(‘insert_id’);

And the problem is solved! I think @@IDENTIFY was returning a trigger identitiy.

Big big thx :smiley: