qail_core/transpiler/sql/
oracle.rs

1use super::super::traits::SqlGenerator;
2
3pub struct OracleGenerator;
4
5impl SqlGenerator for OracleGenerator {
6    fn quote_identifier(&self, id: &str) -> String {
7        // Oracle standardly uses double quotes for case-sensitive identifiers
8        format!("\"{}\"", id.replace('"', "\"\""))
9    }
10
11    fn placeholder(&self, index: usize) -> String {
12        // Oracle uses :1, :2, etc. (1-based index)
13        format!(":{}", index)
14    }
15
16    fn fuzzy_operator(&self) -> &str {
17        "LIKE"
18    }
19
20    fn bool_literal(&self, val: bool) -> String {
21        // Oracle has no BOOLEAN type in SQL (only PL/SQL). commonly use 1/0 or 'Y'/'N'.
22        // We'll stick to 1/0 for consistency with our other "fake boolean" dialects.
23        if val { "1".to_string() } else { "0".to_string() }
24    }
25
26    fn string_concat(&self, parts: &[&str]) -> String {
27        parts.join(" || ")
28    }
29
30    fn limit_offset(&self, limit: Option<usize>, offset: Option<usize>) -> String {
31        // Oracle 12c+ syntax
32        // OFFSET n ROWS FETCH NEXT m ROWS ONLY
33        
34        let mut sql = String::new();
35        let off = offset.unwrap_or(0);
36        
37        if limit.is_some() || offset.is_some() {
38            sql.push_str(&format!(" OFFSET {} ROWS", off));
39            
40            if let Some(lim) = limit {
41                sql.push_str(&format!(" FETCH NEXT {} ROWS ONLY", lim));
42            }
43        }
44        
45        sql
46    }
47}