| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.util; |
| 7 |
|
| 8 |
/** |
| 9 |
* An object that has an SQL representation. |
| 10 |
*/ |
| 11 |
public interface HasSQL { |
| 12 |
|
| 13 |
/** |
| 14 |
* Quote identifiers only when it is strictly required (different case or |
| 15 |
* identifier is also a keyword). |
| 16 |
*/ |
| 17 |
int QUOTE_ONLY_WHEN_REQUIRED = 1; |
| 18 |
|
| 19 |
/** |
| 20 |
* Replace long LOB values with some generated values. |
| 21 |
*/ |
| 22 |
int REPLACE_LOBS_FOR_TRACE = 2; |
| 23 |
|
| 24 |
/** |
| 25 |
* Don't add casts around literals. |
| 26 |
*/ |
| 27 |
int NO_CASTS = 4; |
| 28 |
|
| 29 |
/** |
| 30 |
* Add execution plan information. |
| 31 |
*/ |
| 32 |
int ADD_PLAN_INFORMATION = 8; |
| 33 |
|
| 34 |
/** |
| 35 |
* Default flags. |
| 36 |
*/ |
| 37 |
int DEFAULT_SQL_FLAGS = 0; |
| 38 |
|
| 39 |
/** |
| 40 |
* Combined flags for trace. |
| 41 |
*/ |
| 42 |
int TRACE_SQL_FLAGS = QUOTE_ONLY_WHEN_REQUIRED | REPLACE_LOBS_FOR_TRACE; |
| 43 |
|
| 44 |
/** |
| 45 |
* Get a medium size SQL expression for debugging or tracing. |
| 46 |
* |
| 47 |
* @return the SQL expression |
| 48 |
*/ |
| 49 |
default String getTraceSQL() { |
| 50 |
return getSQL(TRACE_SQL_FLAGS); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get the SQL statement of this expression. This may not always be the |
| 55 |
* original SQL statement, specially after optimization. |
| 56 |
* |
| 57 |
* @param sqlFlags |
| 58 |
* formatting flags |
| 59 |
* @return the SQL statement |
| 60 |
*/ |
| 61 |
default String getSQL(int sqlFlags) { |
| 62 |
return getSQL(new StringBuilder(), sqlFlags).toString(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Appends the SQL statement of this object to the specified builder. |
| 67 |
* |
| 68 |
* @param builder |
| 69 |
* string builder |
| 70 |
* @param sqlFlags |
| 71 |
* formatting flags |
| 72 |
* @return the specified string builder |
| 73 |
*/ |
| 74 |
StringBuilder getSQL(StringBuilder builder, int sqlFlags); |
| 75 |
|
| 76 |
} |