Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

This job is used as a standalone solution or triggered by orders to execute statements in a database.
These can be database procedures or SQL statements.

The description JobSchedulerManagedDatabaseJob.xml is stored in the ./jobs directory of your Job Scheduler installation.

The SQL instructions are written in the command parameter.
It is possible to define more than one instruction in the command parameter.
Such instructions are then carried out in the order in which they are written and must be separated by a semicolon and a subsequent new line.

The Managed Jobs PHP web interface provides a textarea for this, while in the Job Scheduler Object Editor (JOE), only an input field is available.
PHP converts the textarea hexadecimal because a newline cannot be written in an XML attribute.
If you want to use the job with multiple statements without the Managed Jobs, then the statements must be changed hexadecimal.

The following is an example of a job chain in which the statements are converted before launching.

The job chain launchDB.job_chain.xml:

 <[ job_chain] orders_recoverable="yes" visible="yes">
     <[ job_chain_node] state="prepare" job="prepareStatements" next_state="launch"  error_state="error"/>
     <[ job_chain_node] state="launch"  job="launchDB"          next_state="success" error_state="error"/>
     <[ job_chain_node] state="success"/>
     <[ job_chain_node] state="error"/>

The order launchDB,updateMyTable.order.xml:
It contains an update statement and a commit. The value of the statement_newline parameter is used as separator.

 <[ order] title="update MY_TABLE">
         <param name="statement_newline" value="__xA0__"/>
         <param name="statements"        value="update MY_TABLE set a='foo' where b='bar';__xA0__commit;"/>

The first job prepareStatements.job.xml:
It reads order parameter statements and statement_newline, replaces statement_newline to a real newline, converts statements hexadecimal and writes the result in the command parameter.

 <[ job] order="yes" stop_on_error="no" title="set command param hexadecimal">
     <script language="javascript">
 function spooler_process()\{ + " tries to set command parameter.")
   var orderParams = spooler_task.order.params;  
   var stmts       = orderParams.value("statements");
   var sep         = orderParams.value("statement_newline");"param statements = " + stmts);"param statement_newline = " + sep);
   stmts           = stmts.split(sep).join("\n").bin2hex();
   orderParams.set_var("command", stmts);"param command = " + orderParams.value("command"));  
   return true;
 String.prototype.bin2hex = function() \{
   var hex     = "";
   var str     = this;  
   var sLength = this.length;
   for( var i = 0; i < sLength; i++ ) \{ 
     hex += str.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
   return hex;

The second job launchDB.job.xml:
It executes the statements.

 <[ job] title="Launch Database Statement" order="yes" stop_on_error="no">
         <include file="jobs/JobSchedulerManagedDatabaseJob.xml"/>
         <param name="db_class"        value="SOSMySQLConnection"/>
         <param name="db_driver"       value="com.mysql.jdbc.Driver"/>
         <param name="db_url"          value="jdbc:mysql://localhost:3306/scheduler"/>
         <param name="db_user"         value="scheduler"/>
         <param name="db_password"     value="scheduler"/>
         <param name="command"         value=""/>
     <script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/>

If you prefer a shell solution, then you need only one (standalone) job and a database client:

 <[ job] title="Launch Database Statement">
         <param name="statement_newline"       value="__xA0__"/>
         <param name="statements"              value="update MY_TABLE set a='foo' where b='bar';__xA0__commit;"/>
         <param name="db"                      value="scheduler"/>
         <param name="db_user"                 value="scheduler"/>
         <param name="db_password"             value="scheduler"/>
     <script language="shell">
  rm myupdate.sql
  exit $mysqlErr
  • No labels
Write a comment…