|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2026 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.expression.Expression; |
| 13 | +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
| 14 | + |
| 15 | +/** |
| 16 | + * {@code PRAGMA name}, {@code PRAGMA name(arguments)} and {@code PRAGMA name = value}, used by |
| 17 | + * DuckDB and SQLite to read or set database settings. |
| 18 | + * |
| 19 | + * @see <a href="https://duckdb.org/docs/stable/configuration/pragmas">PRAGMA statements</a> |
| 20 | + */ |
| 21 | +public class PragmaStatement implements Statement { |
| 22 | + private String name; |
| 23 | + private ExpressionList<?> parameters; |
| 24 | + private Expression value; |
| 25 | + |
| 26 | + public PragmaStatement() {} |
| 27 | + |
| 28 | + public PragmaStatement(String name) { |
| 29 | + this.name = name; |
| 30 | + } |
| 31 | + |
| 32 | + public String getName() { |
| 33 | + return name; |
| 34 | + } |
| 35 | + |
| 36 | + public void setName(String name) { |
| 37 | + this.name = name; |
| 38 | + } |
| 39 | + |
| 40 | + public PragmaStatement withName(String name) { |
| 41 | + setName(name); |
| 42 | + return this; |
| 43 | + } |
| 44 | + |
| 45 | + public ExpressionList<?> getParameters() { |
| 46 | + return parameters; |
| 47 | + } |
| 48 | + |
| 49 | + public void setParameters(ExpressionList<?> parameters) { |
| 50 | + this.parameters = parameters; |
| 51 | + } |
| 52 | + |
| 53 | + public PragmaStatement withParameters(ExpressionList<?> parameters) { |
| 54 | + setParameters(parameters); |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + public Expression getValue() { |
| 59 | + return value; |
| 60 | + } |
| 61 | + |
| 62 | + public void setValue(Expression value) { |
| 63 | + this.value = value; |
| 64 | + } |
| 65 | + |
| 66 | + public PragmaStatement withValue(Expression value) { |
| 67 | + setValue(value); |
| 68 | + return this; |
| 69 | + } |
| 70 | + |
| 71 | + public StringBuilder appendTo(StringBuilder builder) { |
| 72 | + builder.append("PRAGMA ").append(name); |
| 73 | + if (parameters != null) { |
| 74 | + builder.append("(").append(parameters).append(")"); |
| 75 | + } |
| 76 | + if (value != null) { |
| 77 | + builder.append(" = ").append(value); |
| 78 | + } |
| 79 | + return builder; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String toString() { |
| 84 | + return appendTo(new StringBuilder()).toString(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 89 | + return statementVisitor.visit(this, context); |
| 90 | + } |
| 91 | +} |
0 commit comments