Commit 0dc1ce0224fd2c94a99c8b7a715431086299d18c
1 parent
a8661a46
[*] get_column_name has option to return also primary key. This is useful for ge…
…nerating full insert.
Showing
1 changed file
with
11 additions
and
8 deletions
Show diff stats
src/generation/columns.anubis
| @@ -138,13 +138,14 @@ public define Maybe(String) | @@ -138,13 +138,14 @@ public define Maybe(String) | ||
| 138 | get_column_name | 138 | get_column_name |
| 139 | ( | 139 | ( |
| 140 | HK_Model_Column col, | 140 | HK_Model_Column col, |
| 141 | - Bool insert //true if insert time else false for update | 141 | + Bool p_key_id, //true if the "id" column must be returned |
| 142 | + Bool insert //true if insert time else false for update | ||
| 142 | ) = | 143 | ) = |
| 143 | since col is hk_column(name, col_type, _, _), | 144 | since col is hk_column(name, col_type, _, _), |
| 144 | if col_type is | 145 | if col_type is |
| 145 | { | 146 | { |
| 146 | //anubis(_T) then "constant_byte_array(0,0)", | 147 | //anubis(_T) then "constant_byte_array(0,0)", |
| 147 | - p_key then if name = "id" then failure else success(name), | 148 | + p_key then if name = "id" & p_key_id = false then failure else success(name), |
| 148 | //binary then "constant_byte_array(0,0)", | 149 | //binary then "constant_byte_array(0,0)", |
| 149 | boolean_field then success(name), | 150 | boolean_field then success(name), |
| 150 | date_field(attrs) then success(name), | 151 | date_field(attrs) then success(name), |
| @@ -172,6 +173,7 @@ public define List(String) | @@ -172,6 +173,7 @@ public define List(String) | ||
| 172 | columns_name | 173 | columns_name |
| 173 | ( | 174 | ( |
| 174 | List(HK_Model_Column) columns, | 175 | List(HK_Model_Column) columns, |
| 176 | + Bool p_key_id, //true if we need to have the first primary_key column named "id" | ||
| 175 | Bool insert, //true if insert time else false for update | 177 | Bool insert, //true if insert time else false for update |
| 176 | List(String) so_far | 178 | List(String) so_far |
| 177 | ) = | 179 | ) = |
| @@ -179,14 +181,14 @@ public define List(String) | @@ -179,14 +181,14 @@ public define List(String) | ||
| 179 | { | 181 | { |
| 180 | [] then reverse(so_far), | 182 | [] then reverse(so_far), |
| 181 | [h . t] then | 183 | [h . t] then |
| 182 | - if get_column_name(h, insert) is | 184 | + if get_column_name(h, p_key_id, insert) is |
| 183 | { | 185 | { |
| 184 | - failure then columns_name(t, insert, so_far) | 186 | + failure then columns_name(t, p_key_id, insert, so_far) |
| 185 | success(result) then | 187 | success(result) then |
| 186 | if insert then | 188 | if insert then |
| 187 | - columns_name(t, insert, [result . so_far]) | 189 | + columns_name(t, p_key_id, insert, [result . so_far]) |
| 188 | else | 190 | else |
| 189 | - columns_name(t, insert, [enclose("\\"",result)+" = :v_"+result . so_far]) | 191 | + columns_name(t, p_key_id, insert, [enclose("\\"",result)+" = :v_"+result . so_far]) |
| 190 | } | 192 | } |
| 191 | }. | 193 | }. |
| 192 | 194 | ||
| @@ -198,9 +200,10 @@ public define String | @@ -198,9 +200,10 @@ public define String | ||
| 198 | insert_values | 200 | insert_values |
| 199 | ( | 201 | ( |
| 200 | List(HK_Model_Column) columns, | 202 | List(HK_Model_Column) columns, |
| 203 | + Bool p_key_id, | ||
| 201 | String indent | 204 | String indent |
| 202 | )= | 205 | )= |
| 203 | - with columns_list = columns_name(columns, true, []), | 206 | + with columns_list = columns_name(columns, p_key_id, true, []), |
| 204 | indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")". | 207 | indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")". |
| 205 | 208 | ||
| 206 | 209 | ||
| @@ -214,7 +217,7 @@ public define String | @@ -214,7 +217,7 @@ public define String | ||
| 214 | List(HK_Model_Column) columns, | 217 | List(HK_Model_Column) columns, |
| 215 | String indent | 218 | String indent |
| 216 | )= | 219 | )= |
| 217 | - with columns_list = columns_name(columns, false, []), | 220 | + with columns_list = columns_name(columns, false, false, []), |
| 218 | indent+" "+join(", ", columns_list). | 221 | indent+" "+join(", ", columns_list). |
| 219 | 222 | ||
| 220 | 223 |