Scripting & Programming

MySQL procedure for converting UTF8 to CP1251 encoding and vice versa

CREATE FUNCTION STR_UTF8_1251(@s varchar(8000)) RETURNS VARCHAR(8000) AS BEGIN declare @i int, @c int, @byte2 int, @c1 int, @new_c1 int, @new_i int, @new_c2 int, @out_i int declare @out varchar(8000), @a int SET @i = 1 SET @byte2 = 0 SET @out = ” WHILE (@i<=len(@s)) BEGIN SET @c=ascii(SUBSTRING(@s,@i,1)) if (@c<=127) SET @out=@out+SUBSTRING(@s,@i,1) if (@byte2>0) BEGIN SET […]