Categories | Question details Back To List | ||
sql attach I am scheduling tasks (actually called jobs) in the schedule system, storing the event is working but I also want to update a single field in another table. In the connector information I found: $gridConn->sql->attach("Update","Update tableA set name='{name}', price={price} where id={a.id}"); My version is (used hard coded value in where to try and find why it wasn't working): $scheduler->sql->attach("Insert","UPDATE job SET scheduled='1' WHERE idjob='2'"); I was hoping this would mean that on Insert action it would attach that SQL statement and update the field in the other table. I get a XML pop up error when I do a create even on the calender page. In the log I get: Trying to get property of non-object at F:\program\xampp\htdocs\application\schedule\samples\initialization_loading\php\events.php line 16 Line 16 is the $scheduler->sql->attach line. Full code: <?php include ('../../../codebase/connector/scheduler_connector.php'); include ('../../common/config.php'); $res=mysql_connect($server, $user, $pass); mysql_select_db($db_name); $scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); // Set jobId in table. // If 0 is to prevent nulling of set field when updating. function set_jobId($action){ if ($action->get_value("job_idjob") == 0){ $action->set_value("job_idjob",$_GET["jobId"]); $scheduler->sql->attach("Insert","UPDATE job SET scheduled='1' WHERE idjob='2'"); } } $scheduler->event->attach("beforeProcessing","set_jobId"); //called before render_table $scheduler->render_table("booking","idbooking","dateStart,dateEnd,fullName,section_id,job_idjob"); ?> Thanks Answer posted by Support on Aug 25, 2009 01:59 When using sql code - it will replace build in logic, so it will use your update code instead of native inserting. If you want to use build in inserting code and just made some extra update you can use function my_update($action){ mysql_query("UPDATE Countries SET item_nm='{$action->get_value('name')}' WHERE item_id='{$action->get_new_id()}'"); } $scheduler->event->attach("afterInsert","my_update"); get_value and get_new_id methods can be used to get values of updated records and id of newly added record |