Categories | Question details Back To List | ||||||||||||||||||||||||||
Primary key Looks like dataProcessor assigns its own primary key (timestamp). Is it possible to force my own primary key values? Answer posted by Alex (support) on Jan 22, 2010 08:04 Could you please explain what primary key do you mean ? DataProcessor sends row data that contains the actual row id. But ids must be unique. So if you doesn't use unique ids when rows added, the ids are changed automatically. Answer posted by Eugene on Jan 22, 2010 08:54 I have a simple mysql table with column 'id' as a primary key. I am
adding a new row through grid. It puts "0" in 'id' column and debugger
says: "row 1264178880418 marked [inserted,valid]" Grid still shows 0 until I refresh the page. Then it shows 1264178880418, the same as in a table. Answer posted by Alex (support) on Jan 22, 2010 09:35 row id is passed to the addRow method in the 1st parameter: grid.addRow(rowId,[column1_value,column2_value,...,columnN]); rowId must be unique (there shouldn't be rows with the same ids in grid). In addition it's better not to use rowID=0 (0 is the same as null in JS). If you use dataprocessor and connector, after saving in database the row id in grid will be changed to the id of this row in database automatically.
Answer posted on Jan 22, 2010 09:46 > t's better not to use rowID=0 I do not. I click "add row" and "0" appears in grid automatically. >row id in grid will be changed to the id of this row in database automatically. No, it stays "0" until I refresh the whole page. See snapshot attached. I clicked on "add row" twice. Attachments (1)
Answer posted by Alex (support) on Jan 22, 2010 10:25 dataProcessor doesn't change values in grid rows. You can set the necessary value when you call addRow method: var id = (new Date()).valueOf() grid.addRow(id,[id,"value2",...,"value N"]); Answer posted on Jan 22, 2010 11:05 Maybe I am not explaining it clear. I would prefer "id" field to remain blank (just like other columns) when adding a new row. Then I can edit "id" field and put there any value I'm pleased. If there is a conflict I'd rather get an error message. It could be some setting like grid.allowIdBlank(true) In this case column "id" must be populated first in case setUpdateMode("cell") or error will be displayed. Answer posted by Stanislav (support) on Jan 23, 2010 01:37 >>I would prefer "id" field to remain blank (just like other columns) when adding a new row When row is added it must have some temporary ID ( because in other case it will be non-operable) Dataprocessor assigns temporary ID and sends data to the database where it need to be replaced with actual ID during saving. ( in default samples it organized by auto-increment field in DB ) >>Grid still shows 0 until I refresh the page. Then it shows 1264178880418, the same as in a table. Value of column ID in grid and value of row ID are different entities. When you are adding new row - there are two parameters ID and set of data If you are using column which duplicates ID then server side code can be non-consistent, because it may receive different row_id and value of "id" column - so its not clear , which of them need to be used for DB operation. As default rule - you must not use the same field for row_id and column of grid. Answer posted on Jan 26, 2010 06:25 >When row is added it must have some temporary ID ( because in other case it will be non-operable) Unfortunate it is not how database GUIs work (TOAD, MySQL query browser, etc.). As I said before it should be user-defined, otherwise key column is useless. Guys, we are seriously evaluating you product (and love it a lot) but this restriction puts our decision on hold. At least you could make it configurable. Thanks. Spasibo. Answer posted on Jan 26, 2010 07:38 >>As I said before it should be user-defined, otherwise key column is useless. If key value can be enetered by the user - it possible to enter two equals keys , which will break data consistence ( row need be identified by key, so one key must point to the one row ) If you want to enter key value manually , you need to have two fields some_id - unique ID per row, autoincrement or similar key - you custom ID which is editable in the grid In such case some_id can be used to sync data and key will be freely editable in the same Please post any other questions at the forum http://forum.dhtmlx.com Answer posted on Jan 26, 2010 07:48 > If key value can be enetered by the user - it possible to enter two equals keys Yes, yes, and yes. If a table is not keyed - allow it, otherwise - throw a warning and do NOT ALLOW to proceed. It should only affect new entries of course. Answer posted by Stanislav (support) on Jan 27, 2010 05:25 On client side dp.setVerificator(0); //will prevent sending data to DB , while key is not entered On server side function changeId($action){ $action->set_new_id($action->get_value("key")); } $grid->event->attach("afterInsert",changeId); With such logic data will be sent to server only when key is entered and key value will be correctly used for next updates. Answer posted by Eugene on Jan 29, 2010 13:40 OK, let's try it again. A customer has a simple MySQL table and I cannot change it's schema. CREATE TABLE `db`.`test` ( `a` varchar(100) NOT NULL default '', `b` varchar(100) default '', PRIMARY KEY (`a`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; It has a primary key, column "a". I want to insert one more row with values "GOOG", "Google". I load Grid, edit column a=GOOG and column b=google. I am using dp.setUpdateMode("row"); That is what I see in a log: DB query INSERT INTO test (a,b) VALUES ('1264800081969','google') DB query SELECT LAST_INSERT_ID() as new_id A question is simple: How do I enter "GOOG" in a column "a" and see it saved in a database? Here is my connector (client is attached): conn = DriverManager.getConnection(connStr); GridConnector c = new GridConnector(conn); c.enable_log("/tmp/grid.log", true); c.render_table("test", "a", "a,b"); Guys, we are seriously considering buying enterprise license. But need to sort this out first. Thanks. Attachments (1)
Answer posted by Stanislav (support) on Feb 01, 2010 08:51 a) unzip attached file in connector directory b) write connector file as <?php require_once("../config.php"); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); require("../../codebase/keygrid_connector.php"); $grid = new KeyGridConnector($res); $grid->enable_log("temp.log",true); $grid->render_table("test","a","a,b"); ?> The main difference - KeyGridConnector used instead of the connector Attachments (1)
Answer posted by Eugene on Feb 01, 2010 09:06 Thank you for a solution. We need one in Java (we do not use php at all). How to place a purchase order (dhtmlxSuite enterprise license)? What is an upgrade price after 12 month? Do we ever need to renew a license? We'd also ask for a small (I believe) change: make grid for non-keyed tables read-only (but allow to add new rows). Thank you. Answer posted by Stanislav (support) on Feb 01, 2010 10:14 Updated JAR is attached in email, same as in above php sample , replace GridConnector with KeyGridConnector Attachments (1)
Answer posted by Stanislav (support) on Feb 01, 2010 10:15 >>How to place a purchase order (dhtmlxSuite enterprise license)? What is an upgrade price after 12 month? Do we ever need to renew a license? Please use the form at the bottom of this page to ask licenses related quiestions: http://www.dhtmlx.com/docs/products/licenses.shtml |