/
country.sql
executable file
·108 lines (78 loc) · 1.68 KB
/
country.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
-- Countries
-- get all countries
PROCEDURE getAll(
IN status INT,
IN search CHAR,
IN start INT,
IN limit INT,
OUT fetch_all,
OUT fetch_one,
)
BEGIN
-- country
SELECT *
FROM country AS country WHERE 1 = 1
@IF isset(:status) AND :status != ""
THEN
AND status = :status
END @IF
-- search
@IF isset(:search) AND !empty(:search)
THEN
AND country.name LIKE CONCAT('%',:search,'%')
END @IF
ORDER BY status DESC, country_id
@IF !empty(:limit)
THEN
@SQL_LIMIT(:start, :limit)
END @IF
;
SELECT count(*) FROM (
@SQL_COUNT(country.country_id, country) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
END
-- get country
PROCEDURE get(
IN country_id INT,
OUT fetch_row,
)
BEGIN
-- country
SELECT *
FROM country as _ WHERE country_id = :country_id;
END
-- add country
PROCEDURE add(
IN country ARRAY,
IN language_id INT,
OUT insert_id
)
BEGIN
-- allow only table fields and set defaults for missing values
:country_data = @FILTER(:country, country)
INSERT INTO country
( @KEYS(:country_data) )
VALUES ( :country_data );
END
-- edit country
CREATE PROCEDURE edit(
IN country ARRAY,
IN country_id INT,
OUT affected_rows
)
BEGIN
-- allow only table fields and set defaults for missing values
@FILTER(:country, country)
UPDATE country
SET @LIST(:country)
WHERE country_id = :country_id
END
-- delete country
PROCEDURE delete(
IN country_id ARRAY,
OUT affected_rows,
)
BEGIN
-- country
DELETE FROM country WHERE country_id IN (:country_id);
END