Gant - Postgres DB connection

Hi,
i followed your beginner guide at docs.dhtmlx.com/gantt/desktop__how_to_start.html, everything works great when i use MySQL as DB but i need to use PostrgresSQL as DB but in this case data are not loaded, the gant remains empty. I customized php code shown in the guide in this way:

<?php include ('codebase/connector/gantt_connector.php'); $connection_string = "host=myaddress port=5432 dbname=mydb user=myuser password=mypass"; $res = pg_connect($connection_string); $gantt= new JSONGanttConnector($res); $gantt->render_links("gantt_links","id","source,target,type"); $gantt->render_table( "gantt_tasks", "id", "start_date,duration,text,progress,sortorder,parent" ); postgress connection have to be setted in a different way? Thanx for your help.

Hi,
try specifying a type of connection in the constructor

$gantt = new JSONGanttConnector($res, "PDO","Postgre");

If still no use - please open a connector file in browser and check the error response there

It still doesn’t work, in connector file I’ve got those errors:

Warning: PDO::__construct() expects parameter 1 to be string, resource given in
…\codebase\connector\base_connector.php on line 357

This is jason file printed:
{ “model”: false, “access”: {}, “sql”: null, “event”: {}, “limit”: false, “exec_time”: 1437375668.7455, “render”: {} }

Warning: PDO::__construct() expects parameter 1 to be string, resource given in …\codebase\connector\base_connector.php on line 357

Fatal error: Call to a member function select() on null in …\codebase\connector\base_connector.php on line 533

Valid command line must be like follows

require_once("db_postgre.php");
$gantt = new JSONGanttConnector($res, "Postgre");
  • db_postgre.php file is included
  • “Postgre” string is provided as second parameter of constructor

Thanks, now it works and show tasks stored in Postgre DB but, when I add new tasks or links from the page the DB doesn’t update. With MySQL I used this code and it works:

<script> gantt.config.xml_date = "%Y-%m-%d %H:%i"; gantt.init("gantt_here"); gantt.load('data.php') var dp=new dataProcessor("data.php"); dp.init(gantt); </script>

but with postgre I don’t have the same results.

The data saving logic must work the same for all kind of DBs

Try to enable logging for the connector and check what it outputs for the problematic operation.

$gantt = new JSONGanttConnector($res, "Postgre"); $gantt->enable_log("./some.log");

This happens when I add a task:

[code]

====================================
Log started, 22/07/2015 09:35:12

DataProcessor object initialized
1437550488415_id => 1437550488415
1437550488415_start_date => 2015-07-24 00:00
1437550488415_text => New task
1437550488415_duration => 3
1437550488415_end_date => 2015-07-27 00:00
1437550488415_parent => 0
1437550488415_!nativeeditor_status => inserted
ids => 1437550488415

Row data [1437550488415]
id => 1437550488415
start_date => 2015-07-24 00:00
text => New task
duration => 3
end_date => 2015-07-27 00:00
parent => 0
!nativeeditor_status => inserted

Incorrect field name used: progress

data
id => 1437550488415
start_date => 2015-07-24 00:00
text => New task
duration => 3
end_date => 2015-07-27 00:00
parent => 0
!nativeeditor_status => inserted

Incorrect field name used: progress

data
id => 1437550488415
start_date => 2015-07-24 00:00
text => New task
duration => 3
end_date => 2015-07-27 00:00
parent => 0
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
id => 1437550488415
start_date => 2015-07-24 00:00
text => New task
duration => 3
end_date => 2015-07-27 00:00
parent => 0
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
id => 1437550488415
start_date => 2015-07-24 00:00
text => New task
duration => 3
end_date => 2015-07-27 00:00
parent => 0
!nativeeditor_status => inserted

INSERT INTO gantt_tasks(start_date,duration,text,progress,sortorder,parent) VALUES (‘2015-07-24 00:00’,‘3’,‘New task’,’’,’’,‘0’)

pg_query(): Query failed: ERROR: invalid syntax in input for data type real: “”
LINE 1: …parent) VALUES (‘2015-07-24 00:00’,‘3’,‘New task’,’’,’’,‘0’)
^ at C:\xampp\htdocs\Gant\codebase\connector\db_postgre.php line 13

exception ‘Exception’ with message ‘Postgre - sql execution failed
ERROR: invalid syntax in input for data type real: “”
LINE 1: …parent) VALUES (‘2015-07-24 00:00’,‘3’,‘New task’,’’,’’,‘0’)
^’ in C:\xampp\htdocs\Gant\codebase\connector\db_postgre.php:14
Stack trace:
#0 C:\xampp\htdocs\Gant\codebase\connector\db_common.php(721): PostgreDBDataWrapper->query(‘INSERT INTO gan…’)
#1 [internal function]: DBDataWrapper->insert(Object(DataAction), Object(DataRequestConfig))
#2 C:\xampp\htdocs\Gant\codebase\connector\dataprocessor.php(221): call_user_func(Array, Object(DataAction), Object(DataRequestConfig))
#3 C:\xampp\htdocs\Gant\codebase\connector\dataprocessor.php(168): DataProcessor->check_exts(Object(DataAction), ‘insert’)
#4 C:\xampp\htdocs\Gant\codebase\connector\dataprocessor.php(97): DataProcessor->inner_process(Object(DataAction))
#5 C:\xampp\htdocs\Gant\codebase\connector\gantt_connector.php(294): DataProcessor->process(Object(DataConfig), Object(DataRequestConfig))
#6 C:\xampp\htdocs\Gant\codebase\connector\base_connector.php(411): JSONGanttConnector->render()
#7 C:\xampp\htdocs\Gant\data.php(25): Connector->render_table(‘gantt_tasks’, ‘id’, ‘start_date,dura…’)
#8 {main}

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

Done in 0.048799991607666s[/code]

I’ve noticed that the query:

INSERT INTO gantt_tasks(start_date,duration,text,progress,sortorder,parent)
VALUES (‘2015-07-24 00:00’,‘3’,‘New task’,’’,’’,‘0’)

can be executed with no errors in MySQL but in postgre sortorder and parent values can’t be empty. In fact if I try to execute this query:

INSERT INTO gantt_tasks(start_date,duration,text,progress,sortorder,parent)
VALUES (‘2015-07-24 00:00’,‘3’,‘New task’,‘0’,‘0’,‘0’)

it gives no errors. I tried to set 0 as default value for the colums in DB but it still doens’t work. How can i fix it?

More over if I tryed to add a link instead of a task and it works; in fact the insert query have no empty spaces.

I fixed it by changeing column type from integer to varchar.
I still think thas isn’t an appropriate solution.

Yep, I see the problem
Connector process all incoming values as strings by default, and it can cause a problem if DB doesn’t cast strings to other types automatically.

We will check how this behavior can be improved.

As i see this probleme is already open…