MySQL Forums
Forum List  »  Stored Procedures

Re: Dynamic Sql Statement in SP
Posted by: Ming Yeung
Date: January 10, 2006 10:33PM

Oh Roland,

I'vd just done more tests.
You are right, There shouldn't be any problem by initializing the user variables each time before using them.

I got that silly problem is because one connection(Session) is being used by many web users, which managed by the Pool. So, user variables are connection-specific, not as I thought of 'user-specific'.

http://dev.mysql.com/doc/refman/5.0/en/variables.html

Quote

User variables are connection-specific. That is, a variable defined by one client cannot be seen or used by other clients. All variables for a given client connection are automatically freed when that client exits.

Thanks for your help.

Now, I created a function to CONCAT the sql statement dynaimically.

IF inUsername IS NOT NULL THEN
SET varSql = joinSql(varSql, 'AND', CONCAT("username LIKE '%", inUsername, "%'"));
END IF;

CREATE FUNCTION `joinSql`(inSql TEXT, inHow TEXT, inValue TEXT) RETURNS text
BEGIN

IF (inSql <> '') THEN
SET inSql = CONCAT(inSql, ' ', inHow);
END IF;

SET inSql = CONCAT(inSql, ' ', inValue);

RETURN inSql;

END

Regards,
Ming

Options: ReplyQuote


Subject
Views
Written By
Posted
2766
January 09, 2006 06:22AM
1487
January 09, 2006 08:06AM
1226
January 09, 2006 02:10PM
1806
January 09, 2006 08:02PM
1689
January 10, 2006 12:24AM
1466
January 10, 2006 03:07AM
1678
January 10, 2006 06:51AM
1404
January 10, 2006 01:49PM
1747
January 10, 2006 06:35PM
1552
January 10, 2006 07:22PM
Re: Dynamic Sql Statement in SP
1636
January 10, 2006 10:33PM
1637
January 11, 2006 03:10AM
2205
January 11, 2006 04:27AM
1662
January 11, 2006 06:54AM
1494
January 11, 2006 03:34PM
1656
January 11, 2006 03:56PM
1648
January 12, 2006 03:20AM
1457
January 12, 2006 04:44AM
1422
January 11, 2006 09:08PM
1673
January 12, 2006 03:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.