function.sql 1.22 KB
Newer Older
Marc Egger's avatar
Marc Egger committed
1
2


Marc Egger's avatar
Marc Egger committed
3
4
5
6
7
8
9
10
11
12
13
14
15
###
#
# GETFUNCTIONSHASH() is used for checking whether this file has been played properly in DatabaseUpdate.php
#
DROP FUNCTION IF EXISTS GETFUNCTIONSHASH;
CREATE FUNCTION GETFUNCTIONSHASH ()
RETURNS TEXT
DETERMINISTIC
BEGIN
RETURN '%%FUNCTIONSHASH%%';
END;


16
17
18
19
20
21
22
###
#
# QMORE(input, maxlen)
# inserts a span into `input` after `maxlen` number of characters and returns it.
#
DROP FUNCTION IF EXISTS QMORE;
CREATE FUNCTION QMORE ( input TEXT, maxlen INT )
Marc Egger's avatar
Marc Egger committed
23
24
RETURNS TEXT
DETERMINISTIC
25
26
27
28
29
30
31
32
33
34
35
BEGIN
DECLARE output TEXT;
IF maxlen < 1 THEN
SET maxlen = 1;
END IF;
IF CHAR_LENGTH(input) > maxlen THEN
SET output = CONCAT(INSERT(input, maxlen, 0, '<span class="qfq-more-text">'), '</span>');
ELSE
SET output = input;
END IF;
RETURN output;
Marc Egger's avatar
Marc Egger committed
36
END;
37
38
39
40
41
42
43
44
45


###
#
# QBAR(input)
# replaces '|' in `input` with '\|'
#
DROP FUNCTION IF EXISTS QBAR;
CREATE FUNCTION QBAR ( input TEXT )
Marc Egger's avatar
Marc Egger committed
46
47
RETURNS TEXT
DETERMINISTIC
48
49
50
51
BEGIN
DECLARE output TEXT;
SET output = REPLACE(input, '|', '\\|');
RETURN output;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
END;


###
#
# QNL2BR(input)
# replaces '|' in `input` with '\|'
#
DROP FUNCTION IF EXISTS QNL2BR;
CREATE FUNCTION QNL2BR ( input TEXT )
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE output TEXT;
SET output = REPLACE( REPLACE(input, CHAR(13), ''), CHAR(10), '<br>');
RETURN output;
END