當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.escapeQuote方法代碼示例

本文整理匯總了Java中com.mysql.jdbc.StringUtils.escapeQuote方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.escapeQuote方法的具體用法?Java StringUtils.escapeQuote怎麽用?Java StringUtils.escapeQuote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mysql.jdbc.StringUtils的用法示例。


在下文中一共展示了StringUtils.escapeQuote方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateTableDataDirectory

import com.mysql.jdbc.StringUtils; //導入方法依賴的package包/類
/**
 * CREATE TABLE syntax changed in 5.6GA
 * 
 * InnoDB: Allow the location of file-per-table tablespaces to be chosen
 * CREATE TABLE ... DATA DIRECTORY = 'absolute/path/to/directory/'
 * 
 * Notes:
 * - DATA DIRECTORY option can't be used with temporary tables.
 * - DATA DIRECTORY and INDEX DIRECTORY can't be used together for InnoDB.
 * - Using these options result in an 'option ignored' warning for servers below MySQL 5.7.7. This syntax isn't allowed for MySQL 5.7.7 and higher.
 * 
 * @throws SQLException
 */
public void testCreateTableDataDirectory() throws SQLException {

    if (versionMeetsMinimum(5, 6, 6)) {
        try {
            String tmpdir = null;
            String separator = File.separatorChar == '\\' ? File.separator + File.separator : File.separator;
            this.rs = this.stmt.executeQuery("SHOW VARIABLES WHERE Variable_name='tmpdir' or Variable_name='innodb_file_per_table'");
            while (this.rs.next()) {
                if ("tmpdir".equals(this.rs.getString(1))) {
                    tmpdir = this.rs.getString(2);
                    if (tmpdir.endsWith(File.separator)) {
                        tmpdir = tmpdir.substring(0, tmpdir.length() - 1);
                    }
                    if (File.separatorChar == '\\') {
                        tmpdir = StringUtils.escapeQuote(tmpdir, File.separator);
                    }
                } else if ("innodb_file_per_table".equals(this.rs.getString(1))) {
                    if (!this.rs.getString(2).equals("ON")) {
                        fail("You need to set innodb_file_per_table to ON before running this test!");
                    }
                }
            }

            dropTable("testCreateTableDataDirectorya");
            dropTable("testCreateTableDataDirectoryb");
            dropTable("testCreateTableDataDirectoryc");
            dropTable("testCreateTableDataDirectoryd");

            createTable("testCreateTableDataDirectorya", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            createTable("testCreateTableDataDirectoryb", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
            this.stmt.executeUpdate("CREATE TEMPORARY TABLE testCreateTableDataDirectoryc (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir
                    + (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));
            createTable("testCreateTableDataDirectoryd", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator
                    + "' INDEX DIRECTORY = '" + tmpdir + (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));

            this.stmt.executeUpdate("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");

            this.pstmt = this.conn
                    .prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement(
                    "CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement(
                    "CREATE TEMPORARY TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '"
                    + tmpdir + "' INDEX DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

        } finally {
            // we need to drop them even if retainArtifacts=true, otherwise temp files could be deleted by OS and DB became corrupted
            dropTable("testCreateTableDataDirectorya");
            dropTable("testCreateTableDataDirectoryb");
            dropTable("testCreateTableDataDirectoryc");
            dropTable("testCreateTableDataDirectoryd");
        }

    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:80,代碼來源:SyntaxRegressionTest.java


注:本文中的com.mysql.jdbc.StringUtils.escapeQuote方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。