Newbie: problem writing to DB with Grid and Dataprocessor

I’m trying to create a small test app, following the logic from the First App sample application.

I have a grid that loads and display data from a single database table using the PHP Connector.
I’ve set up logging which on load returns:

SELECT `ID`,`login`,`fname`,`lname`,`email`,`salt`,`pass`,`planmngr`,`active`,`locked`,`lastlogindt`,`createdt` FROM account Done in 0.00078797340393066s

The grid is set up with:

var accountGrid = layout.cells("a").attachGrid(); accountGrid.setHeader("login,First Name,Last Name,E-Mail,salt,pass,Plan Manager,Active,Locked,Last Login,Created"); accountGrid.setColumnIds("login,fname,lname,email,salt,pass,planmngr,active,locked,lastlogindt,createdt"); accountGrid.setColTypes("ro,ro,ro,ro,ro,ro,ch,ch,ch,dhxCalendar,dhxCalendar"); accountGrid.setColSorting("str,str,str,str,str,str,int,int,int,date,date"); accountGrid.setDateFormat("%Y-%m-%d"); accountGrid.setImagePath("codebase/imgs/"); accountGrid.init();

but when writing to database I get:

[code]DataProcessor object initialized
137_gr_id => 137
137_!nativeeditor_status => updated
ids => 137

Row data [137]
ID => 137
!nativeeditor_status => updated

Incorrect field name used: login
[/code]
And so on, with an Incorrect field name used message for each field, and then ending with:

[code]PDATE account SET login=‘’,fname=‘’,lname=‘’,email=‘’,salt=‘’,pass=‘’,planmngr=‘’,active=‘’,locked=‘’,lastlogindt=‘’,createdt=‘’ WHERE ID=‘137’

exception ‘Exception’ with message ‘MySQL operation failed
Incorrect integer value: ‘’ for column ‘planmngr’ at row 1’ in /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/db_common.php:965
Stack trace:
#0 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/db_common.php(637): MySQLDBDataWrapper->query(‘UPDATE account …’)
#1 [internal function]: DBDataWrapper->update(Object(DataAction), Object(DataRequestConfig))
#2 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/dataprocessor.php(222): call_user_func(Array, Object(DataAction), Object(DataRequestConfig))
#3 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/dataprocessor.php(173): DataProcessor->check_exts(Object(DataAction), ‘update’)
#4 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/dataprocessor.php(102): DataProcessor->inner_process(Object(DataAction))
#5 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/base_connector.php(475): DataProcessor->process(Object(DataConfig), Object(DataRequestConfig))
#6 /usr/share/nginx/html/dhtmlx/4.0.3/codebase/connector/php/base_connector.php(398): Connector->render()
#7 /usr/share/nginx/html/mastersheet/data/account.php(8): Connector->render_table(‘account’, ‘ID’, ‘login,fname,lna…’)
#8 {main}
[/code]

What am I missing here?

It is not clear what code you are using on client side for dataprocessor init.
Normally it must be something like next

var dp = new dataProcessor("some.php"); dp.init(mygrid);

If you are configuring some custom data sending mode for the dataprocessor, it may break the server side processing and lead to the above result.

Hi Stanislav

Yes, I should have included that - my appologies.

I initiate just after the grid creation with:

// load data into the grod from the database
accountGrid.load("data/account.php");

/ add the ability to write updates to the database
var dpg = new dataProcessor("data/account.php");
dpg.enablePartialDataSend(true);
dpg.init(accountGrid);

and account.php is simply:

<?php
  require("../codebase/connector/php/grid_connector.php");
  $res=mysql_connect("localhost", "####", "####");
  mysql_select_db("mastersheet");

  $conn = new GridConnector($res);
  $conn->enable_log("/var/log/php-fpm/mastersheet.log",true);
  $conn->render_table("account", "ID", "login,fname,lname,email,salt,pass,planmngr,active,locked,lastlogindt,createdt");
?>

dpg.enablePartialDataSend(true);
This type of init will not work with connector and can be used only with custom backend.

Hi Stanislav

Thanks for pointing that out.
That made me go further than the previous message.

I assume the dataprocessor doesn’t transform empty strings to null values for fields that doesn’t accept empty string? In my case it’s an optional date field that causing the issue. I know I can use the beforeUpdate event, however it might be good roadmap suggestion to make the conversation for fields that doesn’t accept empty strings.

On a side note, the error message I’ve implemented per the documentation, doesn’t appear to provide the error details. Only that an error occured (the attribute type contains the string value “error”).
When debugging, it doesn’t look like any child nodes are available for the error node. Is this an known issue, or is the error details information found elsewhere in 4.0.3?
Here’s how I define the error pop-up’s

dpg.defineAction("error",function some_error(node) { alert(node.getAttribute("type")); // 'my_error' alert(node.firstChild.data); // Details return false; });
My I also say, I’m really impressed with your activity in the forum Stanislav. It’s invaluable to newbies like me, that we can get the nodge we need, to get going using this library. So thank you so much. It is greatly appreciated.

I assume the dataprocessor doesn’t transform empty strings to null values
Nope, it doesn’t apply any data transformations on its own. You can use beforeProcessing or any other server side event to preprocess data before saving.

As for error message - by defautl connector ( server side ) doesn’t send any error details to the client side. It can be changed by using onDbError server side handler

docs.dhtmlx.com/connector__php__ … event.html

you can use it to place error details in the response, so it can be obtained on client side