]> begriffs open source - ai-review/blob - critic/sql-standard-compliance.md
frama-c
[ai-review] / critic / sql-standard-compliance.md
1 # SQL Standard Compliance Critic Framework (ISO/IEC 9075:2023)
2
3 This framework guides the Critic role when evaluating SQL code for strict adherence to the SQL:2023 standard (ISO/IEC 9075:2023). This critic focuses exclusively on language specification compliance, standard feature usage, and avoidance of vendor-specific extensions or undefined behavior.
4
5 ## SQL Standard Compliance Evaluation Areas
6
7 ### 1. Language Specification Adherence
8 **What to Look For:**
9 - Strict adherence to ISO/IEC 9075 (SQL:2023) language specification
10 - Proper use of standard SQL constructs, data types, and functions
11 - Avoidance of vendor-specific extensions unless properly guarded
12 - Correct implementation of language features as defined
13 - Avoidance of undefined or implementation-dependent behavior
14
15 **Common Problems:**
16 - Use of non-standard SQL extensions without proper abstraction
17 - Reliance on undefined or implementation-dependent behavior
18 - Incorrect assumptions about SQL feature support
19 - Violation of SQL syntax or semantic rules
20 - Missing or incorrect use of standard data types and constraints
21
22 **Evaluation Questions:**
23 - Does the code conform to the SQL:2023 standard without relying on vendor-specific features?
24 - Are all standard SQL functions and constructs used correctly according to specification?
25 - Is undefined or implementation-dependent behavior properly avoided?
26 - Are vendor-specific features documented and abstracted?
27 - Does the code execute cleanly on standard-compliant SQL engines?
28
29 ### 2. Standard Feature Usage
30 **What to Look For:**
31 - Correct usage of standard SQL data types (INTEGER, VARCHAR, DATE, etc.)
32 - Proper implementation of standard functions and operators
33 - Appropriate use of standard SQL statements (SELECT, INSERT, UPDATE, DELETE)
34 - Correct syntax for standard SQL clauses (WHERE, GROUP BY, HAVING, ORDER BY)
35 - Proper use of standard SQL expressions and predicates
36
37 **Common Problems:**
38 - Use of non-standard data types or functions
39 - Incorrect syntax for standard SQL constructs
40 - Misuse of standard SQL features
41 - Assumptions about standard feature behavior
42 - Missing standard SQL functionality
43
44 **Evaluation Questions:**
45 - Are all data types used from the SQL:2023 standard?
46 - Are standard SQL functions used correctly according to specification?
47 - Is the syntax conformant to SQL:2023 grammar?
48 - Are standard SQL expressions and predicates used properly?
49 - Does the code avoid non-standard language extensions?
50
51 ### 3. Implementation Independence
52 **What to Look For:**
53 - Code that works across different SQL-compliant database systems
54 - Avoidance of vendor-specific SQL dialects or extensions
55 - Use of feature detection or abstraction layers for optional functionality
56 - Documentation of any implementation dependencies
57 - Reliance only on standard SQL behavior
58
59 **Common Problems:**
60 - Use of proprietary SQL features without abstraction
61 - Assumptions about data type sizes or behaviors
62 - Platform-specific code without proper guards
63 - Missing feature detection for optional SQL features
64 - Lack of documentation for implementation dependencies
65
66 **Evaluation Questions:**
67 - Does the code avoid vendor-specific SQL features?
68 - Are standard data types and constructs used for portability?
69 - Is platform-specific functionality properly abstracted?
70 - Are feature detection mechanisms used for optional features?
71 - Are all implementation dependencies documented?
72
73 ## ISO/IEC Standards-Specific Criticism Process
74
75 ### Step 1: Language Compliance Analysis
76 1. **Check Language Compliance**: Does code conform to SQL:2023 standards?
77 2. **Evaluate Feature Usage**: Are standard SQL features used correctly?
78 3. **Assess Undefined Behavior**: Is undefined or implementation-dependent behavior avoided?
79 4. **Review Vendor Dependencies**: Are vendor-specific features documented and abstracted?
80
81 ### Step 2: Standard Feature Assessment
82 1. **Audit Data Types**: Are standard SQL data types used correctly?
83 2. **Check Function Usage**: Are standard SQL functions used properly?
84 3. **Evaluate Syntax**: Is the syntax conformant to SQL:2023?
85 4. **Assess Expressions**: Are standard SQL expressions used correctly?
86
87 ### Step 3: Implementation Independence Analysis
88 1. **Check for Vendor Lock-in**: Are vendor-specific features avoided or abstracted?
89 2. **Evaluate Data Types**: Are standard types used for portability?
90 3. **Assess Feature Detection**: Are optional features detected and handled?
91 4. **Review Documentation**: Are dependencies documented?
92
93 ## ISO/IEC Standards-Specific Criticism Guidelines
94
95 ### Focus on Specification Compliance
96 **Good Criticism:**
97 - "This query uses a vendor-specific extension without abstraction, violating portability requirements."
98 - "The use of the MERGE statement here does not conform to the SQL:2023 syntax."
99 - "This function relies on implementation-defined behavior for NULL handling."
100 - "The data type chosen is not part of the SQL:2023 standard."
101
102 **Poor Criticism:**
103 - "This doesn't look right."
104 - "This seems non-standard."
105 - "I don't like this approach."
106
107 ### Emphasize Standard Conformance
108 **Good Criticism:**
109 - "The use of proprietary function X violates SQL:2023 standard compliance."
110 - "This syntax is not defined in the SQL:2023 specification."
111 - "The behavior of this construct is implementation-dependent."
112 - "This feature is not part of the standard SQL language."
113
114 **Poor Criticism:**
115 - "This is non-standard."
116 - "This might not work everywhere."
117 - "This is not portable."
118
119 ## ISO/IEC Standards-Specific Problem Categories
120
121 ### Standard Compliance Problems
122 - **Non-Standard Extensions**: Use of vendor-specific features without abstraction
123 - **Syntax Violations**: Code that does not conform to SQL:2023 syntax
124 - **Implementation Dependencies**: Unwarranted assumptions about database behavior
125 - **Feature Misuse**: Incorrect usage of standard SQL features
126
127 ### Language Specification Problems
128 - **Invalid Syntax**: Code that violates SQL:2023 grammar rules
129 - **Undefined Behavior**: Code that relies on implementation-specific behavior
130 - **Missing Features**: Use of features not defined in the standard
131 - **Incorrect Semantics**: Misuse of standard SQL constructs
132
133 ### Implementation Independence Problems
134 - **Vendor Lock-in**: Use of proprietary features without abstraction
135 - **Type Assumptions**: Assuming specific data type behaviors
136 - **Platform-Specific Code**: Unguarded use of platform-specific features
137 - **Missing Feature Detection**: No checks for optional SQL features
138
139 ## ISO/IEC Standards-Specific Criticism Templates
140
141 ### For Standard Compliance Issues
142 ```
143 Standard Compliance Issue: [Specific standard violation]
144 Standard Reference: [ISO/IEC 9075 section and paragraph]
145 Problem: [How this violates the standard specification]
146 Impact: [Portability, undefined behavior, or non-conformance]
147 Evidence: [Specific code examples and standard citations]
148 Priority: [Critical/High/Medium/Low]
149 ```
150
151 ### For Language Specification Issues
152 ```
153 Language Specification Issue: [Specific language violation]
154 Standard Reference: [ISO/IEC 9075 section and paragraph]
155 Problem: [How this violates the language specification]
156 Impact: [Syntax error, undefined behavior, or non-conformance]
157 Evidence: [Specific code examples and grammar rules]
158 Priority: [Critical/High/Medium/Low]
159 ```
160
161 ### For Implementation Independence Issues
162 ```
163 Implementation Independence Issue: [Specific portability problem]
164 Problem: [What assumptions or dependencies limit portability]
165 Impact: [Platforms or implementations where this will fail]
166 Evidence: [Specific code examples and platform differences]
167 Priority: [High/Medium/Low]
168 ```
169
170 ## ISO/IEC Standards-Specific Criticism Best Practices
171
172 ### Do's
173 - **Cite Standard References**: Always reference specific sections of ISO/IEC 9075
174 - **Focus on Specification**: Evaluate against the formal SQL language specification
175 - **Consider All Implementations**: Think about conforming SQL engines, not just one vendor
176 - **Emphasize Standard Conformance**: Prioritize adherence to the SQL:2023 standard
177 - **Document Dependencies**: Clearly identify any implementation-defined behaviors
178
179 ### Don'ts
180 - **Assume Specific Implementations**: Don't assume particular database behaviors
181 - **Ignore Standard Features**: Don't overlook proper usage of standard SQL constructs
182 - **Accept Undefined Behavior**: Don't tolerate code that invokes undefined or implementation-dependent behavior
183 - **Skip Standard Compliance**: Don't ignore standard conformance requirements
184 - **Overlook Portability**: Don't accept unnecessarily non-portable code
185
186 ## ISO/IEC Standards-Specific Criticism Checklist
187
188 ### Standard Compliance Assessment
189 - [ ] Does the code conform to SQL:2023 without relying on vendor-specific features?
190 - [ ] Are all uses of standard SQL constructs correct per specification?
191 - [ ] Is undefined or implementation-dependent behavior avoided?
192 - [ ] Are vendor-specific features documented and abstracted?
193 - [ ] Does the code execute on multiple conforming SQL engines?
194
195 ### Language Specification Assessment
196 - [ ] Is the syntax conformant to SQL:2023 grammar?
197 - [ ] Are standard data types used correctly?
198 - [ ] Are standard SQL functions used properly?
199 - [ ] Are standard SQL expressions and predicates used correctly?
200 - [ ] Does the code avoid non-standard language extensions?
201
202 ### Implementation Independence Assessment
203 - [ ] Does the code avoid vendor-specific SQL features?
204 - [ ] Are standard data types and constructs used for portability?
205 - [ ] Is platform-specific functionality properly abstracted?
206 - [ ] Are feature detection mechanisms used for optional features?
207 - [ ] Are all implementation dependencies documented?
208
209 ## ISO/IEC Standards-Specific Evaluation Questions
210
211 ### For Any SQL Code
212 1. **Does this code conform to the SQL:2023 standard without vendor-specific extensions?**
213 2. **Are all potential sources of undefined or implementation-dependent behavior eliminated?**
214 3. **Is the syntax conformant to SQL:2023 grammar rules?**
215 4. **Are all standard SQL constructs used correctly?**
216 5. **Is the code portable across conforming SQL engines?**
217 6. **Are all implementation dependencies documented?**
218 7. **Does the code avoid non-standard language features?**
219 8. **Are standard data types and functions used properly?**
220 9. **Is the code free from vendor-specific assumptions?**
221 10. **Does the code execute on standard-compliant SQL engines?**
222
223 ### For SQL Statements
224 1. **Is the statement syntax conformant to SQL:2023?**
225 2. **Are all data types used from the standard?**
226 3. **Are standard SQL functions used correctly?**
227 4. **Is the behavior defined by the standard?**
228 5. **Are any vendor-specific features properly abstracted?**
229
230 ### For Database Schemas
231 1. **Are all data types from the SQL:2023 standard?**
232 2. **Are standard SQL constraints used correctly?**
233 3. **Is the schema definition conformant to the standard?**
234 4. **Are any vendor-specific features documented?**
235 5. **Is the schema portable across conforming databases?**
236
237 ## SQL:2023 Standard Principles Applied
238
239 ### "Provide a Standard Data Management Language"
240 - Write SQL code that conforms to the SQL:2023 specification
241 - Use only standard SQL features and constructs
242 - Avoid vendor-specific extensions and undefined behavior
243
244 ### "Ensure Implementation Independence"
245 - Write code that works across different conforming database systems
246 - Avoid reliance on vendor-specific behaviors
247 - Use standard types and constructs for maximum portability
248
249 ### "Maintain Language Consistency"
250 - Use standard SQL syntax and semantics consistently
251 - Follow the formal grammar and specification rules
252 - Ensure all constructs are used as defined in the standard