Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Invoking A MySql Stored Procedure From C In Unix


I've this problem where I have to invoke a MySql stored procedure from my C program. I searched a lot for this. But I couldn't find any solution to this problem.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Can A Stored Procedure In Db1 On My Pc CALL Stored Procedure In Db2 On Remote Pc?
i have two database, one is residing on remote pc pc1 and another is residing on another pc pc2, the deal is i want to call a stored procedure in db of pc1, which in turn calls another stored procedure in db of pc2. i knw it sound weird but it solve my problem.

Call A Stored Procedure From Another Stored Procedure
I have a stored procedure which selects based on a parameter (and has alot of "if's" and "concat's"), and I want to call it from another stored procedure which does the following

Select timesheet_time,
(IF(player = "P1", membdet, 0)) AS "Player1",
(IF(player = "P2", membdet, 0)) AS "Player2",
(IF(player = "P3", membdet, 0)) AS "Player3",
(IF(player = "P4", membdet, 0)) AS "Player4"
FROM timesheet
Group by timesheet_time

(membdet is a concatenated field from the first sp)

How do I call one stored proc from another?

Can't Edit A Stored Procedure/procedure Already Exists
mySQL server: 5.0.24A
client: Administrator: 1.2.3rc
It's a clean installation with no other versions of mySQL

I have no problems to create and run a stored procedure, but when i edit the stored procedure i get the error "MySQL error number 1304 PROCEDURE xxx already exists"

Anyone know what i am doing wrong?

Mysql Stored Procedure Help
I am trying to create a stored procedure with the following query. However it fails to execute. Can someone tell me what the problem is and how to rectify it.

DELIMITER $$

DROP PROCEDURE IF EXISTS `eftdb`.`Get_BondNav` $$
CREATE PROCEDURE `eftdb`.`Get_BondNav` (querydate DATE)
BEGIN
select sum(TRUNCATE(( d.etf_nav_change ) * (d.etf_tna / (SELECT sum( d.etf_tna )
FROM tbl_etfdaily d, tbl_etfmaster m
WHERE d.etf_ticker = m.etf_ticker
AND m.etf_type = 'Bonds'
AND d.etf_date = querydate)),4) * 100) as wnav
FROM tbl_etfdaily d, tbl_etfmaster m
WHERE d.etf_ticker = m.etf_ticker
AND m.etf_type = 'Bonds'
AND d.etf_date = querydate group by d.etf_date
END $$

DELIMITER ;

Error message

Script line: 4You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select sum(TRUNCATE(( d.etf_nav_change ) * (d.etf_tna / (SELECT sum( d.etf_tna )' at line 3

MySQL Stored Procedure
Below is an Oracle SP (works fine).

CREATE OR REPLACE PROCEDURE addPerson
(Id IN varchar2, name IN varchar2, age IN varchar2, address IN varchar2)
IS
BEGIN
INSERT INTO Person_tab
(Id, name, age, address)
VALUES
(Id, name, age, address);
END;

I use my VB app to add data to Person_tab. Basically I want to do exactly the same only for MySQL.

Stored Procedure In MYSQL
I am a newbie in MYSQL and I have to write a stored prcedure. Below is my code. It is not working and am getting an error 1064 in the all these lines.

CREATE PROCEDURE add_purchases (
IN P_buyer_id INT,
IN P_item_id INT,
IN P_num_items INT )
DECLARE v_num INT DEFAULT 0,
DECLARE v_num_sold INT DEFAULT 0 ,
DECLARE v_cost FLOAT (7,2) default 0.00,
DECLARE v_total FLOAT (7,2) default 0.00 ,
DECLARE v_tax_rate FLOAT (4,4) default 0.0000,
DECLARE v_buyer_state CHAR(2) default "OH";
-- This Procedure will add a new purchase record into the PURCHASE Table
-- 1- First make sure number of items requested are available in the ITEMS_FOR_SALE table
-- update the appropriate fields
-- 2- Insert a new purchase record with buyer_id passed as a first parameter
-- 3- Diplay an error message if not enough Items are available
-- 4- Set default tax rate to OH State
BEGIN
-- Get Buyers State From Table
SELECT state into v_buyer_state
FROM BUYERS
WHERE buyer_id = P_buyer_id;
-- Check if number of Items requested in available in ITEMS_FOR_SALE table
SELECT sale_price, num_sold into v_num, v_cost,v_num_sold
FROM items_for_sale
WHERE item_id = P_item_id;
If (v_num_sold >= P_num_itmes) then
-- Update Items_for_sale record to display new Num_sold as a result of the purchase
SET v_num_sold = v_num_sold + P_num_itms;

MySQL Stored Procedure
Can someone name a few links where I can find good tutorials or ebooks on MySQL 5 Stored Procedure, Triggers, Views and Cursors?

MySQL Stored Procedure
I have the following Stored Procedure and it is working fine for me by passing the parameter param1

BEGIN
SELECT user_name, reg_date from user_auth where uid=param1;
END

Now what i want is instead of
"Select user_name from user_auth" i want to use

"Select param1 from user_auth" and param1 will decide which field to fetch.

But it is not replacing with its value and it searches for the field param1 in the table instead of value of param1 like fname, DOB etc

MySql From MS SQL - What's Wrong With This Stored Procedure?
I just switched from MS SQL 2000/2005 to MySql.

What's wrong with this stored procedure:

DELIMITER $$

DROP PROCEDURE IF EXISTS `listing`.`SaveUser` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `SaveUser`(Id INT, Username
VARCHAR(50), EmailAddress VARCHAR(255), Salutation VARCHAR(10),
FirstName VARCHAR(50), LastName VARCHAR(50), Password VARCHAR(50),
Status INT)
BEGIN

DECLARE EmailAddressExists BIT;
DECLARE UsernameExists BIT;
DECLARE ActionDate DATETIME;

SET EmailAddressExists = 0;
SET UsernameExists = 0;

SET EmailAddressExists = !ISNULL((SELECT 1 FROM user WHERE
user.EmailAddress = EmailAddress AND NOT user.Id = Id));
SET UsernameExists = !ISNULL((SELECT 1 FROM user WHERE user.Username =
Username AND NOT user.Id = Id));

IF EmailAddressExists = FALSE AND UsernameExists = FALSE THEN
SET ActionDate = NOW();
IF ID 0 THEN
UPDATE user SET user.Username = Username, user.EmailAddress =
EmailAddress, user.Password = Password, user.Salutation = Salutation,
user.FirstName = FirstName, user.LastName = LastName, user.Status =
Status, user.Modified = ActionDate WHERE user.Id = Id;
ELSE
INSERT INTO user (Username, EmailAddress, Password, Salutation,
FirstName, LastName, Created) VALUES (Username, EmailAddress, Password,
Salutation, FirstName, LastName, ActionDate);
SET Id = @@IDENTITY;
END IF;
END IF;

SELECT Id, ActionDate, EmailAddressExists, UsernameExists;

END $$

DELIMITER ;

Basically,
I want the procedure to return Id, ActionDate, EmailAddressExists,
UsernameExists as a result set.

EmailAdressExists needs to be set true or false.
In MS SQL, I could do SELECT @EmailAddressExists = 1 FROM User where
username = 'asdsa';

It looks like that doesn't work in MySql???

The MySql syntax doesn't look very standard. Who the hell came up with
LIMIT instead of TOP?

Mysql & External Stored Procedure
can we access external program code (i.e like external java program access in Oracle) using mysql if yes how?

How To Call MySQL Stored Procedure Through VB???
I am using MYSQL 5.0 and ODBC 3.51 driver. I have created some stored procedure. How can I use that stored procedure in my VB application????

exim@nn.pp121.biz
exim@uu.pp121.biz
exim@tt.pp121.biz
exim@nn.pp121.com
exim@uu.pp121.com
exim@tt.pp121.com
exim@nn.pp121.net
exim@uu.pp121.net
exim@tt.pp121.net

MySql Stored Procedure Debugger
3 mounth ago I serfed web to find some kind of mysql stored procedure
debugger. But I found nothing.

Last week at last a tool with integrated debugger was released. MySql
Developer Studio 2.0 http://crlab.com/mysqldev/. It uses debug engine
like an oracle dbms_debug, and supports breakpoints, watches, call
stack, and stepping through code facilities. May be it can help you
developing complex stored routines.

Fetching MySQL Stored Procedure
Can anyone confirm it's not yet possible to retrieve the result set from a stored procedure in MySQL5?
I found some posts regarding this issue but no answers yet. I'd like to keep data-model specific stuff out of my Perl DBI code...

MySQL Stored Procedure Pass Array Of Ids Into It
I need to pass Array of Ids into it MySQL Stored Procedure, is this possible? I am running mysql 5.1.20.

Exec Dos Command From MySql Stored Procedure
I must convert a SQL Server Database in a MySql Database. In This SQL Server database there is a Stored Procedure that exec a dos command using system stroed procedure

XP_CMDSHELL 'dos-command ex: DIR'

Is there some way to do this in a MySql Stored Procedure?

Select Into Varirable In Stored Procedure In Mysql
the following procedure is returns Null value why ??? select into variable is not working in mysql ????

delimiter $$

drop procedure if exists test_proc$$
create procedure test_proc
(
o_Value integer
)
Begin
declare v_string varchar(100);
declare v_Cnt integer;
declare v_outpara varchar(20);

set v_string = concat('select count(*) into ',v_Cnt,' from employee where department_id = ''10'');

if v_cnt = 0 then
' Do Some thing here
else
' Do Some thing here
end if;

set v_outparam = v_cnt;

END$$

delimiter ;

my Question is in above procedure the v_cnt is giving null value why as there are 10 records in the employee table so why Null in v_cnt variable.

Syntax Error In MySQL Stored Procedure.
I have written a stored procedure in mySql (ver 5.0) and I am getting an error which just says that there is a syntax error at 2nd line. I have done a lot of research and checked this code many times but can't figure out what could be the problem. Code:

Mysql Stored Procedure With Variable Table Name
I have a small question concerning mysql! I would like to create a stored procedure that will take as input the teable name from which to select all columns. something like
"select * from variable_that_came_as_input"
Is there anyone who can help me out on that? I've seen it work but I don't know how to do it.

Passing NULL Values To MySQL Stored Procedure
I have created a MySQL stored procedure to insert new records into a table that has a number of fields that accept NULL values.On my Frontend Access database I have a form for inputting the values for the new record.I am encountering problems passing NULL values to the MySQL SP.The NULL's get converted to empty strings for text columns and to empty fields for numeric columns.

I am using an ADO command object to pass the call to the SP using its CommandText property.  The actual text passed contains a series of variables initialized and set inside the VBA environment.These act as IN parameters within the SP.

Does anyone have a workable technique they could share for passing NULL values from VBA to MySQL Stored Procedures?

Invoking Mysql Error
System Info:
RedHat Linux 9 (text only)
Mysql 3

When I execute mysql from the command line I receive an error:

"error 2002: Mysql cannot connect to socket /var/lib/mysql.sock"

(or something similar) - the socket was definately not
"/tmp/mysql.sock"

It was installed by the RedHat 9 installer. Do I have to edit some
configuration file.

Stored Procedure
I am trying to migrate sql from mssql server. Unfortunately, mysql seems to be very different.

Can someone show me how to convert following procedures for mysql?

create procedure sp_get_id as
Begin
declare @id int
begin transaction
select @id = isnull(max(id),0)+1
from id_table
update id_table
set id = @id
select id=@id
commit transaction
End
go
/* simply returns next id. id_table contains one record */

create proc sp_get_data @id int as
Begin
select id1 = c.id1, id2= c.id2, data_table = c.data_table into #filter1
from data_table c, data_table_cache k where ( (k.id=0 or k.id=@id) and c.id1 = k.ticker)

select id1 = c.id1, id2= c.id2, data_table = c.data_table into #filter2
from #filter1 c, data_table_cache k where ( (k.id=0 or k.id=@id) and c.id2= k.ticker)

select id1,id2,data_table from #filter2
End

Stored Procedure
Can someone help me with the syntax to my stored procedure? Every time
I try to run it I receive the error code 1064. I checked my syntax
against the documentation on mysql.com and it seems to be correct, but
of course I could be wrong. Here's my Code:

Stored Procedure
I'm trying to create a stored procedure for user login as follow

DELIMITER $$

DROP PROCEDURE IF EXISTS USER_LOGIN $$
CREATE PROCEDURE USER_LOGIN (
IN P_USERNAME VARCHAR(50),
IN P_PASSWORD VARCHAR(50)
)
BEGIN
SELECT U.USER_ID
FROM USERS U
WHERE U.USER_USERNAME = P_USERNAME
AND U.USER_PASSWORD = MD5(P_PASSWORD)
END $$

DELIMITER ;

when I try to complie the above code, it gives error. Could anyone point out my error, since I really don't know what's go wrong. The mysql version I'm using is 5.0.37.

Stored Procedure?
I am having trouble getting this procedure to properly enter the data into a table. It works when I do not add the @ToName info and only ask to insert the AccountID and FromName data. When i add the @ToNamevariable, no data is inserted.

I think it might have to do with the select statement. I have two TerritoryID, RegionID, DivisionID, and EmpID because I want this information to be entered for both the FromName and the ToName selected. Does anyone know what my problem is? Code:

Stored Procedure
I have a database and I am writing stored procedures for that. I have to insert a record into the database for which I have this procedure:

PROCEDURE `insert_price`(pc_id int, pc_level INT, price INT, from_date DATETIME, to_date DATETIME)BEGIN INSERT INTO price VALUES (pc_id, pc_level, price, from_date, to_date);
END

But I before doing this I have to check whether the pc_id column is unique and then finding the maximum pc_id and incrementing the value by one. This value then goes into the first argument of insert_price.

The sql scripts for these are pretty straightforward but I am having trouble converting these to procedures.

For example, I can find that pc_id is unique by executing show indexes in price;

And, also I can use the following select max(pc_id) + 1 from price;

But how do I get all this into a procedure and connect with the last Stored Pro?

Stored Procedure
I'm trying to create a stored procedure using the following syntax,
but I'm getting an error.

CREATE PROCEDURE `site`.`sp_ValidateInvite_SEL` (invitecode
varchar(10))
BEGIN

-- Check that the code exists (deleted/blocked users' invites will be
deleted)
IF NOT EXISTS (SELECT * FROM `invitations` WHERE `InvitationCode` =
invitecode) THEN
SELECT 'Error' As `Status`, 'Invitation Code is invalid.'
As `Details`;
ELSE
SELECT 'Invited' As `Status`, 'blahblah' As `Details`;
END IF

END

Could someone tell me what the problem could be? Can you use the EXIST
function as a condition (or a parameter within a EXIST function/
subquery)? I'm using MySQL Administrator which automatically add the delimiter
statement.

Stored Procedure
I am trying to convert a stored procedure written for sql to one that will work in mysql. I understand that I have to set the variables as IN for incoming variables, but I don't know what to do with the rest of the code. The following is the sql stored procedure: Code:

Stored Procedure
I ve got create an stored procedure and it work very well. But now i want to have a more bit difficult stored procedure. So i want to create a new procedure as this :

CREATE FUNCTION proUser(In nbr1 INT,OUT cur1 CURSOR)
BEGIN
DECLARE cur2 CURSOR FOR SELECT * FROM Users WHERE Users_Id = nbr1;
cur1 = cur2;
END

So i have an error on (In nbr1 INT,OUT cur1 CURSOR) ?????

Is it possible to realize a procedure returning cursor. Have you got some eg ???

Stored Procedure
I have a table for customers with various field, two of which are clientnumber and password.

I have a website where a user has to log in using their clientnumber and password and if it is correct it goes to another page.

What sort of stored procedure would I use to check that the user name and password are correct?

Would I have it return say true if it is true and then have an if else in the webpage that says that if it is true go to this page?

Stored PROCEDURE
Here is my sql statement:

DROP PROCEDURE IF EXISTS `check_user`;

CREATE PROCEDURE `check_user`(IN userid VARCHAR(25))
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT ''
BEGIN
select loginid from user where loginid=userid;
END;


I am using:

# Server version: 5.0.41-community-nt
# Protocol version: 10
# Server: localhost via TCP/IP
# User: root@localhost
# phpmyadmin

when i try to run above mentioned statement I get following error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select loginid from user where loginid=userid' at line 6 .

Stored Procedure
i'm using MySql 5.0 and i wanna know how many Stored Procedures can i add to my DataBase, because until now only can create 2 SP. When i wanna create the third SP, it always delete SP created previously.

Stored Procedure
I created procedure which create user as well as give him all privileges..
-----------------------------
-----------------------------
DELIMITER $$

DROP PROCEDURE IF EXISTS `tsmdb`.`tsw_createuser_proc` $$
CREATE PROCEDURE `tsmdb`.`tsw_createuser_proc` (login char(10),pass char(10))
BEGIN
GRANT ALL PRIVILEGES ON *.* TO login@"%"
IDENTIFIED BY 'pass' WITH GRANT OPTION;
END $$

DELIMITER ;

CALL tsw_createuser_proc('Sansrati','sansrati')
-----------------------
------------------------
While executing it is creating user by parameter name (login) not by Sansrati.
What is the use of procedure if it is still static.

Stored Procedure
I'm facing a problem with stored procedures in MySQL 5.0.10.
My application is in ASP.NET and I'm using Corelab's MySQL library to transact with the database. The problem is that all stored procs return an error message "Can't return resultset in the given context." Calling the stored procs directly through the DBTools client interface also gives the same error.
I'm just not able to resolve this one. My client had given me the code and when I set it up on my local server I get this error and moreover, it is working fine at the client's site. Any idea why this is happening and a possible solution to this?

Stored Procedure
I just started using MySQL 5.0.3 and am playing around with stored procedures. I'm trying to find an example of calling a stored procedure from PHP. Any help pointing me in the right direction would be great.

Stored Procedure
I write a stored procedure as below but the like statement is always incorect.
What is the correct way for the like in select statement?
--------------------------------------------------------------------
CREATE PROCEDURE `usp_Product_Search`(IN varProductCode varchar(50))
BEGIN
IF varProductCode IS NOT NULL THEN
select * from tbproduct
where 1=1
and ProductCode LIKE varProductCode + '%';
End IF;

Stored Procedure
The Manual Reference says that I have to run the script fix_privilege_tables.sql, but I don“t have it. Only out extension(.sql).

Stored Procedure
I'm working on this database, and I used to put all of my queries in the php code itself and execute from there. Now, I've started moving everything into stored procedures, and just passing parameters.
So..is this bad? The benefits I see are that I dont have to find and replace code everywhere, I can just make a procedure and its instantly accessible everywhere.
Since I'm doing it this way, passing parameters, do i still need to worry about sql injection?

Stored Procedure
Im writing a asp.net webapp and I need some help with scheduling of a
stored procedure.
I'd like to know if it's possible to have a stored produdere (that I
have written) to be schedualed for execution. I'd like it to exec on
the mysql server on predetermined hours.

Stored Procedure
I'm connected remotely to a mysql-server as root. No problem, i can do everything (insert, update .. to all tables of all databases.).
But when i try to make a stored procedure, i get the error:
"access denied for user 'root'@'%' to the database reserv".
When i do it on the mysql-server itself, it works.

Stored Procedure
i have created a stored procedure for an assignment i haev, the procedure is called getschoolorder, this procedure worked i implemented it into thte database then somehow i didnt save a copy of it and i lost hte code for the procedure, i have to hand hte code in, is there anyway i can get the code with an sql querie or somethign im using oracle 9i,

Stored Procedure
i'm trying to create my first stored procedure.this is what i have so far. No procedural statements yet as I want to get this working first and then i'll add in more.
now i'm still getting errors on every line.what am I doing wrong?

DELIMITER //

CREATE PROCEDURE spinsertnew (_filesource int,_firstname char(200),_lastname char(200))

BEGIN

DECLARE _Random int;
DECLARE _Upper int;
DECLARE _Lower int;
DECLARE _MyIdentity int;
DECLARE _isdouble int;

END;
//

Stored Procedure Syntax
I'm used to the SQL Server world but am working with MYSQL but i can't seem to find the syntax through the documentation of MYSQL. I have this stored procedure, could somebody help me out on what i'm missing. Is it that i'm not specifying IN or OUT for the results? ...

How To Return A Value From A Stored Procedure?
In my stored procedure, I wrote an INSERT query and now I want to return the ID of newly inserted record.

I can get that ID by LAST_INSERT_ID() function. but how can I return this ID?

What's Wrong With This Stored Procedure?
I have this stored procedure
CREATE PROCEDURE `documents`.`insert_documents_by_id`(in_DocumentId integer, in_DocumentLanguage varchar(255))
BEGIN
IF in_DocumentId= -1 THEN
insert into document(language) values( in_DocumentLanguage );
select LAST_INSERT_ID();
ELSE
update document set language=in_DocumentLanguage where id=in_DocumentId;
select in_id;
END IF;
END $$
I keep getting the following error when I execute it
"No database selected"

What's wrong... the database is already selected and it's called documents

Problem In Stored Procedure Through C#.Net
i m facing a problem with my stored procedure,named "procPayment".
I am doing update or insert through this stored procedure depending on whether that empid exist in table Paymentmaster.if data exist in table "procPayment" will upadte the other details if not it will insert the details...
i wud like to get whether my syntax is fine or not'my stored procedure is like this :
DELIMITER $$;
DROP PROCEDURE IF EXISTS `jaldb`.`procPayment`$$
CREATE DEFINER=`jaldb`@`badda` PROCEDURE `procPayment`
(
in yr integer,in mnth integer,in varempid text,
p_conveyenceAllownce text,p_deputation text,p_Exgratia text,p_GPF text,p_HouseLoan text,
p_HRA text,p_HillDevAllowance text,p_MedicalAdvance text,p_MedicalReimb text,p_Other1 text,
p_Other2 text,p_OverTime text,p_Personal text,p_TABill text,p_TravelAdvance text,p_MedicalAllowance text,p_Basic text,p_Add text,p_AdditionalDA text,p_DA text,p_employeeid text,p_monthid text,p_special text,p_TotalPayment text,p_ToBank text
)
BEGIN
declare empidnew text;
declare paydate varchar(10);
declare tempempid text;
if mnth <10 then
set paydate = concat(&#3901;','/0',mnth,'/',yr);
else
set paydate = concat(&#3901;','/',mnth,'/',yr);
end if;
set tempempid = concat(&#390;', varempid);
set empidnew=(Select empid from paymentmaster where payrolldate=paydate and empid=varempid);
if (empidnew != null) then
update paymentmaster
set
Basic=p_Basic,
add50per=p_Add,
special=p_special,
conveyanceallowance=p_conveyenceAllownce,
deputation=p_deputation,
personal=p_Personal,
DA=p_DA,
additionalDA=p_AdditionalDA,
HRA=p_HRA,
hilldevAllowance=p_HillDevAllowance,
overtime=p_OverTime,
MedicalAdvance=p_MedicalAdvance,
GPFAdvance=p_GPF,
medicalallowance=p_MedicalAllowance,
exgratia=p_Exgratia,
houseloan=p_HouseLoan,
medicalreimb=p_MedicalReimb,
traveladvance=p_TravelAdvance,
TABill=p_TABill,
other1=p_Other1,
other2=p_Other2,
totalpayment=p_TotalPayment,
tobank=p_ToBank
where empid=varempid;
ELSE
nsert into paymentmaster
(
empid,payrollDate, Basic, Add50per, Special,ConveyanceAllowance,
Deputation,Personal,DA,AdditionalDA,HRA,HillDevAllowance,OverTime,
MedicalAdvance,GPFAdvance,MedicalAllowance,
Exgratia,HouseLoan,MedicalReimb,TravelAdvance,TABill,Other1,Other2,
TotalPayment,ToBank,ltaMasterId
)
values
(
empidnew, paydate,p_Basic,p_Add,p_special,p_conveyenceAllownce,
p_deputation,p_Personal,p_DA,p_AdditionalDA,p_HRA,p_HillDevAllowance,p_OverTim e,
p_MedicalAdvance,p_GPF,p_MedicalAllowance,
p_Exgratia,p_HouseLoan,p_MedicalReimb,p_TravelAdvance,p_TABill,p_Other1,p_Othe r2,
p_TotalPayment,ToBank,0
);
end if;
END$$
DELIMITER ;$$

Stored Procedure Vs Views
I am a little confused on the benefits of views when compared to stored procedures. When should you use a view and when should you use a stored procedure? Do either technology have a performance edge over the other?

Calling Php From Stored Procedure!
I was wondering if we can call a php program in stroed procedure in mysql so that I can produce reports for the tables.If possible please write the procedure to call the php from stored procedure.

Stored Procedure Problem
DELIMITER //
CREATE FUNCTION `ADD_DATE`(BaseDate DATE, PeriodOffset VARCHAR(20)) RETURNS DATE
BEGIN
DECLARE iDuration INT;
DECLARE iPeriod VARCHAR(10);
SET iDuration = SUBSTRING(PeriodOffset,1,INSTR(PeriodOffset,' '));
SET iPeriod = SUBSTRING(PeriodOffset,INSTR(PeriodOffset,' ')+1);
if iPeriod='DAYS' THEN
RETURN BaseDate;
else if iPeriod='MONTHS' then
RETURN DATE_ADD(BaseDate,INTERVAL iDuration MONTH);
else if iPeriod='YEARS' then
RETURN DATE_ADD(BaseDate,INTERVAL iDuration YEAR);
end if ;

END //
DELIMITER ;

Stored Procedure Needed
I have a table named players with these fields:

playerid {int}
teamid {int}
jersey {int}
playername {varchar(50)}
age {int}
And a table named pitchcounts with these fields:

id {int}
gamenum {int}
playerid {int}
pitchcount {int}
Now, what I need is a stored procedure to return the number of pitches each player pitched in a week where the weekno is passed
and the days rest required and next availability date of the pitcher based on the criteria below:

In-House Ages 13-16 (Babe Ruth)
--------------------------------------------------------
Pitches Days Rest
-------------------------------
0-20 0 Rest
21-40 1 Rest
41-60 2 Rest
61-95 3 Rest

********************************************************
In-House Ages 11 & 12 (Majors-American, National & Continental)
--------------------------------------------------------
Pitches Days Rest
-------------------------------
0-20 0 Rest
21-40 1 Rest
41-60 2 Rest
61-85 3 Rest
No more than 125 pitches in a week. 4 12's can pitch but no more than 240 pitches no matter how many games in a week.

********************************************************
Travel Ages 8, 9, 10, 11 & 12
--------------------------------------------------------
Player can pitch up to three innings in a weekend. Two innings doesn't affect In-House the next day, but prior In-House pitching does apply. If 61 or more pitches on Thurs or Sat no travel that weekend. A travel manager must obtain approval from the In-House manager in order to pitch a player for more than one inning if the in-house team has a game following the travel team on the same day. If pitchers does pitch more than 1 inning in travel, pitcher limited to 60 pitches In-House.
If travel follows In-House on same day, player can pitch in travel if no more than 60 pitches thrown in-house. These rules will be in place until may 1st. We want these rules to be followed in spirit as well as literally. If abuses are found, even if within rules, we will change them after may 1st. Under no circumstances is a player able to be made ineligible for In-House play.

********************************************************
In-House Ages 10 and 9'S in Majors (Majors American, National, Continental)
--------------------------------------------------------
Pitches Days Rest
-------------------------------
0-20 0 Rest
21-40 1 Rest
41-60 2 Rest
61-75 3 Rest
********************************************************
Double A In-House (AA)
--------------------------------------------------------
No more than 40 pitches in a game or 80 for a week.

********************************************************
Additional In-House Notes
--------------------------------------------------------
If a pitcher gets to 85 (75 at age 10) pitches in a game in the middle of a batter, they can finish the batter only. Pitching results must be reported by email to Director within 24 hours of the game by the winning manager. Pitcher can not re-enter to pitch in the same In-House game once removed from the mound. Pitcher receives seven warm-up pitches before their first inning on mound and five every inning thereafter. Warmup pitches no not count toward total counts. Pitches to final batter, if count gets past game or week totals, don't count toward totals. 12 year olds in Continental League can not pitch.

Rest Examples:

if 20 or less on Monday, available on Tuesday
if 21-40 on Monday, available on Wednesday
if 41-60 on Monday, available on Thursday
if 61 or more on Monday, available on Friday


Copyright © 2005-08 www.BigResource.com, All rights reserved