How do I call my own stored procedure and what is the syntax?


You can call any of your own stored procedures in a couple of ways. The first way is through a callback. There are a few resources (XmNUpdateProc, XmNDeleteProc and XmNInsertProc) that take a stored procedure string as a parameter. Another option is to use the predefined callback, XiDBDoProcedureCB, and supply a stored procedure string as the parameter. The final option is to call XiDBDoProcedure (no CB) from anywhere within your application to run a stored procedure.

The XmNinsertProc and XmNdeleteProc resources are on the query widget. These resources provide users with a place to declare a stored procedure to be called in place of the dynamically generated SQL. This is useful when users want to perform additional tasks before an insert of delete.

The XmNupdateProc is a resource on each data presentation widget. This resource provides a place for users to declare a stored procedure to be called to perform the update of this field. Again, this stored procedure will take the place of the standard DBPak generated SQL.

All three of these resources are expecting a string of the syntax:

outparam1, outparam2 <- storedProcedureName([widget instance name 1], [widgetinstance name 2], [widget instance name 3])

Where outparam1 and outparam2 are variables that will receive the results of the stored procedure. The brackets around a widget instance name is equivalent to an @value(widget instance name) this provides the database value that this data presentation widget holds. The number of input and output paramaters is dependent on your stored procedure.

Here's an example using the newPart stored procedure described on page 125 of the DX manual and in DXHOME/examples/OrderEntry/sybase/procs.

inventory_Part_Number, inventory_Description, inventory_Price, inventory_Quantity_On_Hand, inventory_Reorder_Quantity <- newPart([inventory_Part_Number],[inventory_Description],[inventory_Price])

This same syntax is required when using XiDBDoProcedureCB.

When calling a stored procedure using XiDBDoProcedure from anywhere within your code you'll need to follow this syntax:


void
mycall(w, client_data, call_data)
 Widget w;
 XtPointer client_data;
 XtPointer call_data;
{
 Widget table;
 long errorval;
 RowSet *rs;
 c_DBValue *value;

 table = XtNameToWidget(XtParent(w), "*q_Accounts");

 if (!table)
  {
  printf("table widget not found \n");
  }

 rs = XiDBDoProcedure(table, "accounts_State, accounts_State1<- test2()", &errorval);

 value = XiDBRowSetGetCell(rs,0,0);
 printf("Row retrieved: %s \n", XiDBValueToString(value));

 value = XiDBRowSetGetCell(rs,0,1);
 printf("Row retrieved: %s \n", XiDBValueToString(value));

 XiDBFreeDBValue(value);
 XiDBRowSetDestroy(rs);

 printf("error = %d\n", errorval);


}




BACK HOME Send Email