Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Call a stored procedure from Run Activity

Locked
clinterman
Posts: 24
Joined: Thu Apr 05, 2012 7:53 am

Call a stored procedure from Run Activity

Unread post by clinterman »

I have a stored procedure that I would like to call from Run Activity.

Running the procedure from TOAD works fine.

The Activity is defined as
nuRunQuery("CALL DELETE_SPIDER();");
and I tried
nuRunQuery("CALL DELETE_SPIDER()",false);
nuRunQuery("CALL DELETE_SPIDER()",true);


Run Activity doesn't. I get the errorscreen:
SQL

SELECT ``.* FROM `` WHERE = '14f7f4a062527c'
Transaction

No Transaction.
Error

1103: Incorrect table name ''
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Call a stored procedure from Run Activity

Unread post by admin »

clinterman,

nuBuilder doesn't work with stored procedures.

Sorry about that.

Steven
clinterman
Posts: 24
Joined: Thu Apr 05, 2012 7:53 am

Re: Call a stored procedure from Run Activity

Unread post by clinterman »

Problem solved:

I can call a stored procedure using in "Custom Code after save"
$s = "CALL my_stored_procedure(" . $recordID . ")";
db_query($s);

Also with one modification and an extra php you can call stored procedures from Run Activity

I added to common.php after line 22: include('dbfunctions.php');
include ('mydbfunctions.php');

then I setup mydbfunctions.php as a copy of dbfunctions.php and started to add functions
function dbCallStoredProcedure1() {

$db = nuRunQuery(''); // returns $db[0]=$DBHost; $db[1]=$DBName; $db[2]=$DBUserID; $db[3]=$DBPassWord;
$link = mysql_connect($db[0], $db[2], $db[3]);
if (!$link) { die('Could not connect: ' . mysql_error());}
mysql_select_db($db[1]);
$t = mysql_query("CALL Stored_Procedure1");
return $t;
}

I just have not yet figured out how in this last option I can pass variables. Maybe somebody knows and want to update this post as we can all learn from this
anorman
Posts: 66
Joined: Wed Apr 04, 2012 11:34 pm

Re: Call a stored procedure from Run Activity

Unread post by anorman »

Maybe this will help?

I have NOT tried this yet, as I am working on another problem, and happened to run across this accidentally.. It will be of value to me, and I will be trying it at some point soon as I would LOVE to use Stored Procedures (I'm a PostGreSQL fan myself, and use stored procedures for everything, so I'm hopeful this will work)..

If anyone tries it before I do, let me know the result, and I certainly shall respond here with my success/failure.

- Andre
-------------

http://php.net/manual/en/function.mysql-connect.php

specifically:


If you're using stored procedures and mysql_error() returns "PROCEDURE storedProcedureName can't return a result set in the given context", you need to pass an additional flag (CLIENT_MULTI_RESULTS) to mysql_connect() as such:
mysql_connect($hostname, $username, $password, true, 131072);

Some other sources say that you should use 65536. 65536 is actually the flag to allow multiple statements in a single mysql_query(), and is a security issue. The reason it allows you to receive results from stored procedures is because it implies 131072. To be safe, use 131072 over 65536.
pcdinh at phpvietnam dot net 13-Feb-2010 12:54
Other client flags extracted from MySQL client source

#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */
#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
#define CLIENT_COMPRESS 32 /* Can use compression protocol */
#define CLIENT_ODBC 64 /* Odbc client */
#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */
#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
#define CLIENT_MULTI_STATEMENTS 65536 /* Enable/disable multi-stmt support */
#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */
#define CLIENT_REMEMBER_OPTIONS (((ulong) 1) << 31)
Contact at LinuxIntro dot com 27-Oct-2008 09:33
When you connect and expect to use a stored procedure,you must pass a special flag to MySQL via the connect command, otherwise you will not get the results returned, and it will result in this error:
PROCEDURE AlexGrim.GetStats_ForumCategories can't return a result set in the given context

To fix this, change you connection string, adding ",false,65536" as the last 2 fields:
$this->con = mysql_connect($this->h,$this->u,$this->p,false,65536);


Also, refer to this:

http://www.joeyrivera.com/2009/using-my ... set-w-php/
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Call a stored procedure from Run Activity

Unread post by admin »

.
Locked