Class: Gitlab::Database::QueryAnalyzers::PreventSetOperatorMismatch::Targets
- Inherits:
-
Object
- Object
- Gitlab::Database::QueryAnalyzers::PreventSetOperatorMismatch::Targets
- Defined in:
- lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/targets.rb
Class Method Summary collapse
-
.a_star?(target) ⇒ Boolean
True when ‘SELECT *`.
-
.null?(target) ⇒ Boolean
Null targets are used to produce “polymorphic” query result sets that can be aggregated through a UNION without having to worry about mismatched columns.
-
.reference_names(target, select_stmt) ⇒ Object
Return the reference names used by the given target.
Class Method Details
.a_star?(target) ⇒ Boolean
True when ‘SELECT *`
32 33 34 |
# File 'lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/targets.rb', line 32 def a_star?(target) Node.locate_descendant(target, :a_star) end |
.null?(target) ⇒ Boolean
Null targets are used to produce “polymorphic” query result sets that can be aggregated through a UNION without having to worry about mismatched columns.
A null target would be something like: SELECT NULL::namespaces FROM namespaces
41 42 43 |
# File 'lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/targets.rb', line 41 def null?(target) target&.val&.type_cast&.arg&.a_const&.isnull end |
.reference_names(target, select_stmt) ⇒ Object
Return the reference names used by the given target.
For example: ‘SELECT users.id` would return [’users’] ‘SELECT * FROM users, namespaces` would return [’users’, ‘namespaces’]
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/database/query_analyzers/prevent_set_operator_mismatch/targets.rb', line 16 def reference_names(target, select_stmt) # Parse all targets to determine what is referenced. fields = fields(target) case fields.count when 0 literal_ref_names(target, select_stmt) when 1 unqualified_ref_names(fields, select_stmt) else # The target is qualified such as SELECT reference.id field_ref = fields[fields.count - 2] [field_ref.string.sval] end end |