[SOLVED] CBSubs to change username first time user subscrib

8 years 11 months ago #147037 by Ducatiklubben
Problem solved!

Since we needed to verify if username was a number or not, we had to use a Stored Procedure in the database to make this work.
Here's the code that we used:
[code:1]CREATE PROCEDURE updateUser(IN user_id CHAR(64))
BEGIN
declare user_name varchar(64);

SET user_name = (select username from ducati_users where id = user_id);

if user_name REGEXP '^-?[0-9]+$' = 0 then

UPDATE ducati_users as a
INNER JOIN (
SELECT * FROM ducati_users
WHERE username>1 ORDER BY username DESC LIMIT 1
) AS b on a.id = user_id AND b.username>1
SET a.username = b.username + 1;
END IF;
END;
//
[/code:1]

In the SQL Action tab in CBSubs we use the "call" command to make the Stored procedure to be used:
[code:1]call updateUser([user_id]);
[/code:1]

Thanks for all your help

Post edited by: Ducatiklubben, at: 2010/11/25 18:02
Moderators: beatnantkrileon
Time to create page: 0.384 seconds
Facebook Twitter Google LinkedIn