Add task with java connector

Hello.

First congratulations for dhtmlxGantt ! I use it with the java connector on a mysql and it works well.

But I have a problem :
when I modify or when I delete a task, it is immediately performed in mysql -> this is ok.
but when I add a task, it is never performed in mysql (never add the row in mysql).
(I think mysql is not the problem because I can well add lines manually)

Thank you for your help.

Regards.

Hi,
make sure that id column is set as a primary key and the autoincrement is enabled.
If it not helps - please provide a configuration code of your connector and a schema of mysql table

Hello.
the id column is set as a primary key and the autoincrement is enabled.

My XHTML :

[code] <h:outputScript name=“js/dhtmlxConnector_java/connector.js” />

        <h:outputStylesheet name="dhtmlxgantt/codebase/dhtmlxgantt.css" />
        <h:outputScript name="dhtmlxgantt/codebase/dhtmlxgantt.js" />
        <h:outputScript name="dhtmlxgantt/codebase/locale/locale_fr.js" />

        <div id="idConteneurGantt" style="width:100%; height:300px;">
        </div>
        <script>
            gantt.config.xml_date = "%Y-%m-%d %H:%i";
            gantt.config.scale_unit = "day";
            gantt.config.duration_unit = "day";
            gantt.config.date_scale = "%d";
            gantt.config.scale_height = "130";
            gantt.config.scale_row = "130";
            
            gantt.init("idConteneurGantt");

            gantt.load('/Poc/faces/data');
            
            var dp = new dataProcessor('/Poc/faces/data');
            dp.init(gantt);
            
        </script>[/code]

My connector :

[code]package dhtmlx;

import java.sql.Connection;
import java.sql.DriverManager;
import com.dhtmlx.connector.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = “JSONDataServlet”, urlPatterns = {"/data"})
public class JsonGanttDataServlet extends ThreadSafeConnectorServlet {

@Override
protected void configure(HttpServletRequest req, HttpServletResponse res) {
    System.out.println("JsonGanttDataServlet configure in");

    Connection conn = null;
    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_dhtmlx", "root", "mysql");
    } catch (Throwable e) {
        e.printStackTrace();
    }

    JSONGanttConnector gantt = new JSONGanttConnector(conn, DBType.MySQL);
    gantt.servlet(req, res);

    gantt.mix("open", "1");

    gantt.render_links("gantt_links", "id", "source,target,type");
    gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");

    System.out.println("JsonGanttDataServlet configure out");
}

}[/code]

My schema MySQL :

[code]-- MySQL Administrator dump 1.4


– Server version 5.0.45-community-nt

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/
!40101 SET NAMES utf8 */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/
!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 /;
/
!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO’ */;


– Create schema test_dhtmlx

CREATE DATABASE IF NOT EXISTS test_dhtmlx;
USE test_dhtmlx;


– Definition of table gantt_links

DROP TABLE IF EXISTS gantt_links;
CREATE TABLE gantt_links (
id int(11) NOT NULL auto_increment,
source int(11) NOT NULL,
target int(11) NOT NULL,
type varchar(1) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


– Dumping data for table gantt_links

/*!40000 ALTER TABLE gantt_links DISABLE KEYS /;
/
!40000 ALTER TABLE gantt_links ENABLE KEYS */;


– Definition of table gantt_tasks

DROP TABLE IF EXISTS gantt_tasks;
CREATE TABLE gantt_tasks (
id int(11) NOT NULL auto_increment,
text varchar(255) NOT NULL,
start_date datetime NOT NULL,
duration int(11) NOT NULL,
progress float NOT NULL,
sortorder int(11) NOT NULL,
parent int(11) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;


– Dumping data for table gantt_tasks

/*!40000 ALTER TABLE gantt_tasks DISABLE KEYS /;
INSERT INTO gantt_tasks (id,text,start_date,duration,progress,sortorder,parent) VALUES
(1,‘Tâche 1’,‘2014-01-06 00:00:00’,13,0.965934,0,0),
(3,‘Tâche 1-1’,‘2014-01-16 00:00:00’,9,0.0238095,0,1),
(4,‘aaaa’,‘2014-01-06 00:00:00’,5,0.5,0,0),
(5,‘bbb’,‘2014-02-06 00:00:00’,25,0.25,0,0);
/
!40000 ALTER TABLE gantt_tasks ENABLE KEYS */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE /;
/
!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS /;
/
!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS /;
/
!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/
!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/
!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION /;
/
!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
[/code]

Hello.

I still have the problem :
when I modify or when I delete a task, it is immediately performed in mysql -> this is ok.
but when I add a task, adding works well on screen, but is never performed in mysql.
(everything works with links)

If I do not find the solution to this problem, I will be forced to abandon dhtmlxgantt. :cry:

Best regards.

Hi,

Code, that you have posted, looks fine

Try to change your code like next

gantt.enable_log("some.log"); gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,parent");

It will create a log file with details about data saving operation, it will contain exact sql code and details of data saving error.

I have the same problem, please help… version: 3.1.1

Excuseme i have the same problem with php and mysql.

mygantt.php

	echo "<!DOCTYPE HTML>";
	echo "<html><head><title></title>";
	echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>";
	echo "<meta http-equiv='X-UA-Compatible' content='IE=edge'/>";
	echo "<link rel=\"icon\" href=\"./favicon.ico\" type=\"image/x-icon\" />";
	echo "<style type='text/css'>";
	echo "@import url(\"/v2/intradoc/css/intradoc_task_list.css\");";
	echo "@import url(\"/v2/intradoc/css/cssmenu.css\");";
	echo "@import url(\"/v2/intradoc/css/font-awesome/css/font-awesome.min.css\");";
	echo "</style>";
	echo "<script src='/v2/intradoc/jquery/jquery.js'></script>";
	echo "<script src='/v2/intradoc/jquery/jquery_functions.js'></script>";
	echo "<script src='codebase/dhtmlxgantt.js'></script>";
	echo "<script src='codebase/locale/locale_it.js' charset='utf-8'></script>";
	echo "<link href='codebase/dhtmlxgantt.css' rel='stylesheet'>";
	echo "<style type='text/css' media='screen'>".
		"html, body{".
        "margin:0px;".
        "padding:0px;".
        "height:100%;".
        "overflow:hidden;".
    "}".
	"</style>";
	echo "</head>";
	echo "<body".($onload!=""?" onload=\"$onload\"":"").">";	
	echo "<div id='gantt_here' style='width:100%; height:100%;'></div>".
		"<script type='text/javascript'>
		
		gantt.config.xml_date = '%Y-%m-%d %H:%i'; 		
		gantt.config.scale_unit = 'month';
		gantt.config.date_scale = '%F, %Y';

		gantt.config.scale_height = 60;

		gantt.config.subscales = [
			{
				unit:'day', step:1, date:'%j, %D' 
			}
		];	
		
		gantt.init('gantt_here');
		gantt.load('data.php');
		
		var dp=new dataProcessor('data.php');
		dp.init(gantt);

		gantt.enable_log('log_gantt.txt');
		
		</script>";	

data.php

include ('codebase/connector/gantt_connector.php');
include ('codebase/connector/db_mysqli.php');

$dbtype = "MySQL"; 
 
$res=mysql_connect("localhost","root","mysqlroot");
mysql_select_db("gantt");
 
$gantt = new JSONGanttConnector($res, $dbtype);

$gantt->render_links("gantt_links","id","source,target,type");
$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,sortorder,parent");

i followed the instruction on the guide, all command are correctly upload on database except add new task.

Hi Stanislav,

Here is my log :
(I have 2 new colomns compared to my code : “responsable” and “priorite”)

[code]====================================
Log started, Mon Jan 12 10:11:53 CET 2015

DB query
SELECT id,start_date,duration,text,progress,parent,responsable,priorite FROM gantt_tasks

DB query
SELECT id,source,target,type FROM gantt_links

Done in : 72ms

-----------------> Gantt loading : OK

====================================
Log started, Mon Jan 12 10:12:48 CET 2015

DB query
INSERT INTO gantt_tasks (start_date,duration,text,progress,parent,responsable,priorite) VALUES (‘2014-11-07 00:00:00’,‘2’,‘New task’,null,‘0’,‘Harry’,‘0’)

Done in : 8ms

-----------------> Gantt add task OK on screen but NOT in mysql

====================================
Log started, Mon Jan 12 10:13:52 CET 2015

DB query
DELETE FROM gantt_links WHERE id=‘18’

====================================
Log started, Mon Jan 12 10:13:52 CET 2015

DB query
DELETE FROM gantt_tasks WHERE id=‘11’

DB query
DELETE FROM gantt_links WHERE id=‘19’

DB query
DELETE FROM gantt_links WHERE source = ‘11’

DB query
DELETE FROM gantt_links WHERE target = ‘11’

Done in : 16ms
Done in : 21ms

-----------------> Gantt delete task OK on screen and OK in mysql

====================================
Log started, Mon Jan 12 10:14:30 CET 2015

DB query
UPDATE gantt_tasks SET start_date=‘2015-03-01 00:00:00’,duration=‘10’,text=‘Tâche 12’,progress=‘0.82’,parent=‘0’,responsable=’’,priorite=‘0’ WHERE id=‘12’

Done in : 8ms

-----------------> Gantt update task OK on screen and OK in mysql[/code]
Thank you for the help.

Hi.

Compared to my code, I added “sortorder” on :

gantt.render_table("gantt_tasks", "id", "start_date,duration,text,progress,sortorder,parent");

And I deleted the “NOT NULL” attribute on “sortorder” and “progress” in mysql.

And it works !
(log is very cool :wink: )

Is it normal that when I create a task, the values “sortorder” and “progress” have the value NULL ? While on page “desktop__how_to_start.html”, it is written :

CREATE TABLE `gantt_tasks` ( ... `progress` float NOT NULL, `sortorder` int(11) NOT NULL, ...
Thanks for all.

i have already inserted sortorder and progress.

i have modified my table as you told me (deleted the NULL value) but still not work.

Instead i have tested the code without sortorder and progress:

$gantt->render_table("gantt_tasks","id","start_date,duration,text,parent");

in this case add task command work correctly, why???

There is an error in the sql insert syntax:

log_gantt.txt

data
id => 1421070079515
start_date => 2015-01-11 00:00
text => test1
duration => 3
end_date => 2015-01-14 00:00
parent => 0
!nativeeditor_status => inserted

INSERT INTO gantt_tasks(`start_date`,`duration`,`text`,`progress`,`sortorder`,`parent`) VALUES ('2015-01-11 00:00','3','test1','','','0')

exception 'Exception' with message 'MySQL operation failed
Data truncated for column 'progress' at row 1' in C:\htdocs\codebase\connector\db_common.php:1091

fields sortorder and progress can not be ‘’ for the types of data required in the table.

Is it normal that when I create a task, the values “sortorder” and “progress” have the value NULL ?

Not really, we will update task adding code to set the initial 0 value for both attributes.

fields sortorder and progress can not be ‘’ for the types of data required in the table.

With default settings mysql does accept empty string values for any kind of fields. It seems you have used more strict settings for mysql.

Ok, this is possible.

In any way a solved the problem editing row 925 of db_common.php:

if ($data->get_value($v["name"])===Null||($data->get_value($v["name"])==""))
   $temp_v[$k]="0";

and set field progress and sortorder as NOT NULL.