/
weight_type.sql
executable file
·128 lines (92 loc) · 2.73 KB
/
weight_type.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
-- Currencies
-- get all weight types
PROCEDURE getAll(
IN language_id INT,
IN start INT,
IN limit INT,
OUT fetch_all,
OUT fetch_one,
)
BEGIN
-- weight_type
SELECT *
FROM weight_type AS weight_type
INNER JOIN weight_type_content ON weight_type_content.weight_type_id = weight_type.weight_type_id
WHERE 1 = 1
@IF !empty(:language_id)
THEN
AND weight_type_content.language_id = :language_id
END @IF
@SQL_LIMIT(:start, :limit);
SELECT count(*) FROM (
@SQL_COUNT(weight_type.weight_type_id, weight_type) -- this takes previous query removes limit and replaces select columns with parameter product_id
) as count;
END
-- get weight type
PROCEDURE get(
IN weight_type_id INT,
IN language_id INT,
OUT fetch_row,
)
BEGIN
-- weight_type
SELECT *
FROM weight_type as _
INNER JOIN weight_type_content ON weight_type_content.weight_type_id = _.weight_type_id
WHERE _.weight_type_id = :weight_type_id
@IF !empty(:language_id)
THEN
AND weight_type_content.language_id = :language_id
END @IF
;
END
-- add weight_type
PROCEDURE add(
IN weight_type ARRAY,
IN language_id INT,
OUT insert_id
OUT insert_id
)
BEGIN
-- allow only table fields and set defaults for missing values
:weight_type_data = @FILTER(:weight_type, weight_type)
INSERT INTO weight_type
( @KEYS(:weight_type_data) )
VALUES ( :weight_type_data);
-- allow only table fields and set defaults for missing values
:weight_type_content_data = @FILTER(:weight_type, weight_type_content)
INSERT INTO weight_type_content
( @KEYS(:weight_type_content_data), language_id, weight_type_id )
VALUES ( :weight_type_content_data, :language_id, @result.weight_type);
END
-- edit weight_type
CREATE PROCEDURE edit(
IN weight_type ARRAY,
IN weight_type_id INT,
OUT affected_rows,
OUT affected_rows
)
BEGIN
-- allow only table fields and set defaults for missing values
:weight_type_data = @FILTER(:weight_type, weight_type)
UPDATE weight_type
SET @LIST(:weight_type_data)
WHERE weight_type_id = :weight_type_id;
-- allow only table fields and set defaults for missing values
:weight_type_content_data = @FILTER(:weight_type, weight_type_content)
UPDATE weight_type_content
SET @LIST(:weight_type_content_data)
WHERE weight_type_id = :weight_type_id AND language_id = :language_id;
END
-- delete weight_type
PROCEDURE delete(
IN weight_type_id ARRAY,
OUT affected_rows,
OUT affected_rows,
)
BEGIN
-- weight_type
DELETE FROM weight_type_content WHERE weight_type_id IN (:weight_type_id);
-- weight_type_content
DELETE FROM weight_type WHERE weight_type_id IN (:weight_type_id);
END