@@ -259,28 +259,27 @@ defmodule SQL.Parser do
259259 @ order % { select: 0 , from: 1 , join: 2 , where: 3 , group: 4 , having: 5 , window: 6 , order: 7 , limit: 8 , offset: 9 , fetch: 10 }
260260 defp sort ( acc ) , do: Enum . sort_by ( acc , fn { tag , _ , _ } -> Map . get ( @ order , tag ) end , :asc )
261261
262- defp validate ( _ , % { sql_lock: nil } , errors ) , do: errors
263- defp validate ( { tag , _ , _ } , % { sql_lock: % { columns: [ ] } } , errors ) when tag in ~w[ select having where on by order group] a , do: errors
264- defp validate ( { tag , _ , values } , % { sql_lock: % { columns: columns } } , errors ) when tag in ~w[ select having where on by order group] a do
265- case validate_columns ( columns , values , [ ] ) do
262+ defp validate ( _ , % { validate: nil } , errors ) , do: errors
263+ defp validate ( { tag , _ , values } , % { validate: fun } , errors ) when tag in ~w[ select having where on by order group] a do
264+ case validate_columns ( fun , values , [ ] ) do
266265 [ ] -> errors
267266 e -> e ++ errors
268267 end
269268 end
270- defp validate ( { tag , _ , _ } , % { sql_lock: % { tables: [ ] } } , errors ) when tag in ~w[ from join] a , do: errors
271- defp validate ( { tag , _ , values } , % { sql_lock: % { tables: tables } } = context , errors ) when tag in ~w[ from join] a do
269+ defp validate ( { tag , _ , _ } , % { validate: nil } , errors ) when tag in ~w[ from join] a , do: errors
270+ defp validate ( { tag , _ , values } , % { validate: fun } = context , errors ) when tag in ~w[ from join] a do
272271 values
273272 |> Enum . reduce ( [ ] , fn
274273 { :paren , _ , _ } , acc -> acc
275274 { :on , _ , _ } = node , acc -> validate ( node , context , acc )
276- { tag , _ , _ } = node , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
277- { :as , _ , [ { tag , _ , _ } = node , _ ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
278- { :dot , _ , [ _ , { tag , _ , _ } = node ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
279- { :dot , _ , [ _ , { :bracket , _ , [ { :ident , _ , _ } = node ] } ] } , acc -> validate_table ( tables , node , acc )
280- { :comma , _ , [ { :dot , _ , [ _ , { :bracket , _ , [ { :ident , _ , _ } = node ] } ] } ] } , acc -> validate_table ( tables , node , acc )
281- { :comma , _ , [ { :dot , _ , [ _ , { tag , _ , _ } = node ] } ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
282- { :comma , _ , [ { :as , _ , [ { tag , _ , _ } = node , _ ] } ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
283- { :comma , _ , [ { tag , _ , _ } = node ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( tables , node , acc )
275+ { tag , _ , _ } = node , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
276+ { :as , _ , [ { tag , _ , _ } = node , _ ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
277+ { :dot , _ , [ _ , { tag , _ , _ } = node ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
278+ { :dot , _ , [ _ , { :bracket , _ , [ { :ident , _ , _ } = node ] } ] } , acc -> validate_table ( fun , node , acc )
279+ { :comma , _ , [ { :dot , _ , [ _ , { :bracket , _ , [ { :ident , _ , _ } = node ] } ] } ] } , acc -> validate_table ( fun , node , acc )
280+ { :comma , _ , [ { :dot , _ , [ _ , { tag , _ , _ } = node ] } ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
281+ { :comma , _ , [ { :as , _ , [ { tag , _ , _ } = node , _ ] } ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
282+ { :comma , _ , [ { tag , _ , _ } = node ] } , acc when tag in ~w[ ident double_quote] a -> validate_table ( fun , node , acc )
284283 end )
285284 |> case do
286285 [ ] -> errors
@@ -290,21 +289,21 @@ defmodule SQL.Parser do
290289 defp validate ( { tag , _ , [ { t , _ , _ } ] } , _ , errors ) when tag in ~w[ offset limit] a and t in ~w[ numeric binary hexadecimal octal] a , do: errors
291290 defp validate ( { tag , _ , _ } = node , _ , errors ) when tag in ~w[ offset limit] a , do: [ node | errors ]
292291
293- defp validate_table ( tables , { _ , _ , value } = node , acc ) do
294- case Enum . find ( tables , false , fn % { table_name: { _ , _ , fun } } -> fun . ( value ) end ) do
292+ defp validate_table ( fun , { _ , _ , value } = node , acc ) do
293+ case fun . ( value ) do
295294 true -> acc
296295 false -> [ node | acc ]
297296 end
298297 end
299298
300- defp validate_columns ( columns , { tag , _ , value } = node , acc ) when tag in ~w[ ident double_quote] a do
301- case Enum . find ( columns , false , fn % { column_name: { _ , _ , fun } } -> fun . ( value ) end ) do
299+ defp validate_columns ( fun , { tag , _ , value } = node , acc ) when tag in ~w[ ident double_quote] a do
300+ case fun . ( value ) do
302301 true -> acc
303302 false -> [ node | acc ]
304303 end
305304 end
306- defp validate_columns ( columns , [ node | values ] , acc ) do
307- validate_columns ( columns , values , validate_columns ( columns , node , acc ) )
305+ defp validate_columns ( fun , [ node | values ] , acc ) do
306+ validate_columns ( fun , values , validate_columns ( fun , node , acc ) )
308307 end
309- defp validate_columns ( _columns , _ , acc ) , do: acc
308+ defp validate_columns ( _fun , _ , acc ) , do: acc
310309end
0 commit comments