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
2918
January 09, 2006 06:22AM
1579
January 09, 2006 08:06AM
1308
January 09, 2006 02:10PM
1887
January 09, 2006 08:02PM
1763
January 10, 2006 12:24AM
1579
January 10, 2006 03:07AM
1782
January 10, 2006 06:51AM
1489
January 10, 2006 01:49PM
1837
January 10, 2006 06:35PM
1636
January 10, 2006 07:22PM
Re: Dynamic Sql Statement in SP
1722
January 10, 2006 10:33PM
1734
January 11, 2006 03:10AM
2288
January 11, 2006 04:27AM
1724
January 11, 2006 06:54AM
1574
January 11, 2006 03:34PM
1751
January 11, 2006 03:56PM
1745
January 12, 2006 03:20AM
1531
January 12, 2006 04:44AM
1516
January 11, 2006 09:08PM
1751
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.