Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Pierrefonds, QC Canada
    Posts
    205
    Rep Power
    11
    Originally Posted by r937
    oh, wait... could this be the problem?

    try it like this --
    Code:
    DROP FUNCTION IF EXISTS uc_words;
    
    DELIMITER ||
    CREATE FUNCTION ...
    Doesn't happen anything...
    Not even an error message!

    I used:
    Code:
    DROP FUNCTION IF EXISTS uc_words;
    
    DELIMITER ||
    CREATE FUNCTION uc_words(lastName TEXT)
    	RETURNS TEXT
    	NO SQL
    	DETERMINISTIC
    	COMMENT 'Title Case. Assumes that there arent numbers or weird chars'
    BEGIN
    	-- loop counter
    	-- (change type if you expect input longer than 255 chars)
    	DECLARE i TINYINT UNSIGNED DEFAULT 1;
    	-- limit for i
    	DECLARE maxlen TINYINT UNSIGNED DEFAULT LENGTH(lastName) + 1;
    	-- current char
    	DECLARE ch CHAR(1) DEFAULT '';
    	-- output buffer
    	DECLARE str_out TEXT DEFAULT '';
    	-- a word is already started?
    	DECLARE in_word BOOL DEFAULT FALSE;
    	
    	-- loop chars
    	WHILE i < maxlen DO
    		-- get current char
    		SET ch = SUBSTRING(str_in FROM i FOR 1);
    		
    		IF ch REGEXP '[[:alpha:]]' THEN
    			-- letter
    			IF in_word IS TRUE THEN
    				-- word already started
    				SET str_out = CONCAT(str_out, LOWER(ch));
    			ELSE
    				-- word starts here
    				SET str_out = CONCAT(str_out, UPPER(ch));
    				SET in_word = TRUE;
    			END IF;
    		ELSE
    			-- no letter; add it and remember we're out of word
    			SET str_out = CONCAT(str_out, IF(ch, ch, ' '));
    			SET in_word = FALSE;
    		END IF;
    		
    		SET i = i + 1;
    	END WHILE;
    	
    	RETURN str_out;
    END;
    ||
    DELIMITER ;
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Italy
    Posts
    36
    Rep Power
    2
    That's really strange... can you tell me the value of your SQL_MODE?
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Pierrefonds, QC Canada
    Posts
    205
    Rep Power
    11
    Originally Posted by f_razzoli
    That's really strange... can you tell me the value of your SQL_MODE?
    @@GLOBAL.sql_mode (empty)
    Last edited by Germaris; January 21st, 2013 at 04:44 PM.
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Italy
    Posts
    36
    Rep Power
    2
    What I need is the result of:
    SELECT @@GLOBAL.sql_mode;
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Pierrefonds, QC Canada
    Posts
    205
    Rep Power
    11
    Originally Posted by f_razzoli
    What I need is the result of:
    SELECT @@GLOBAL.sql_mode;
    This is what I get on one and only one row...
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Italy
    Posts
    36
    Rep Power
    2
    Originally Posted by Germaris
    5.1.66

    I replaced str_in by the name of the column on which the function applies.
    Right?
    Sorry, I didn't read this before. I don't think you need to do this, because you will do something like:

    INSERT INTO tab_name SET surname = uc_words('BROWN'), ...

    Please try to insert the function exactly how I wrote it, before trying any changes.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Pierrefonds, QC Canada
    Posts
    205
    Rep Power
    11
    Originally Posted by f_razzoli
    Sorry, I didn't read this before. I don't think you need to do this, because you will do something like:

    INSERT INTO tab_name SET surname = uc_words('BROWN'), ...

    Please try to insert the function exactly how I wrote it, before trying any changes.
    Sorry for the trouble, it works nice.
    It was my mistake...

    Thank you very much!

    PS: How could I mark your answer as THE solution?
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Italy
    Posts
    36
    Rep Power
    2
    I have no idea
    I'm new to this forum, you should ask some experienced user...
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,437
    Rep Power
    1688
    Try editing the first post in the thread and adding [Solved] to subject.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo