com.datastax.driver.core.Metadata.needsQuote()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中com.datastax.driver.core.Metadata.needsQuote()方法的一些代码示例,展示了Metadata.needsQuote()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.needsQuote()方法的具体详情如下:
包路径:com.datastax.driver.core.Metadata
类名称:Metadata
方法名:needsQuote

Metadata.needsQuote介绍

[英]We don't need to escape an identifier if it matches non-quoted CQL3 ids ([a-z][a-z0-9_]*), and if it's not a CQL reserved keyword.
[中]如果标识符与不带引号的CQL3 ID([a-z][a-z0-9_q4])匹配,并且不是CQL保留关键字,则不需要转义。

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Quotes a CQL identifier if necessary.
 *
 * <p>This is similar to {@link #quote(String)}, except that it won't quote the input string if it
 * can safely be used as-is. For example:
 *
 * <ul>
 *   <li>{@code quoteIfNecessary("foo").equals("foo")} (no need to quote).
 *   <li>{@code quoteIfNecessary("Foo").equals("\"Foo\"")} (identifier is mixed case so case
 *       sensitivity is required)
 *   <li>{@code quoteIfNecessary("foo bar").equals("\"foo bar\"")} (identifier contains special
 *       characters)
 *   <li>{@code quoteIfNecessary("table").equals("\"table\"")} (identifier is a reserved CQL
 *       keyword)
 * </ul>
 *
 * @param id the "internal" form of the identifier. That is, the identifier as it would appear in
 *     Cassandra system tables (such as {@code system_schema.tables}, {@code
 *     system_schema.columns}, etc.)
 * @return the identifier as it would appear in a CQL query string. This is also how you need to
 *     pass it to public driver methods, such as {@link #getKeyspace(String)}.
 */
public static String quoteIfNecessary(String id) {
 return needsQuote(id) ? quote(id) : id;
}

代码示例来源:origin: com.yugabyte/cassandra-driver-core

/**
 * Quotes a CQL identifier if necessary.
 * <p/>
 * This is similar to {@link #quote(String)}, except that it won't quote the input string
 * if it can safely be used as-is. For example:
 * <ul>
 * <li>{@code quoteIfNecessary("foo").equals("foo")} (no need to quote).</li>
 * <li>{@code quoteIfNecessary("Foo").equals("\"Foo\"")} (identifier is mixed case so case
 * sensitivity is required)</li>
 * <li>{@code quoteIfNecessary("foo bar").equals("\"foo bar\"")} (identifier contains
 * special characters)</li>
 * <li>{@code quoteIfNecessary("table").equals("\"table\"")} (identifier is a reserved CQL
 * keyword)</li>
 * </ul>
 *
 * @param id the "internal" form of the identifier. That is, the identifier as it would
 *           appear in Cassandra system tables (such as {@code system_schema.tables},
 *           {@code system_schema.columns}, etc.)
 * @return the identifier as it would appear in a CQL query string. This is also how you need
 * to pass it to public driver methods, such as {@link #getKeyspace(String)}.
 */
public static String quoteIfNecessary(String id) {
  return needsQuote(id)
      ? quote(id)
      : id;
}

相关文章