Search in sources :

Example 11 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class OracleSqlScriptSmallTest method parseProcedure.

@Test
public void parseProcedure() throws Exception {
    String source = "CREATE OR REPLACE PROCEDURE set_right_value_for_sequence(seq_name in VARCHAR2, table_name in VARCHAR2, column_id in VARCHAR2)\n" + "IS\n" + "    seq_val NUMBER(6);\n" + "    row_count NUMBER(6);\n" + "BEGIN\n" + "    EXECUTE IMMEDIATE\n" + "    'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'alter sequence  ' || seq_name || ' increment by -' || seq_val || ' minvalue 0';\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'select case when max(' || column_id || ') is null then 1 else max(' || column_id || ') end from ' || table_name INTO row_count;\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'alter sequence ' || seq_name || ' increment by ' || row_count || ' minvalue 0';\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'select ' || seq_name || '.nextval from dual' INTO seq_val;\n" + "\n" + "    EXECUTE IMMEDIATE\n" + "    'alter sequence ' || seq_name || ' increment by 1 minvalue 1';\n" + "END;\n" + "/\n" + "\n" + "EXECUTE set_right_value_for_sequence('SEQ_ATR', 'TOTCATTRIB', 'ATTRIB_ID');";
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(2, sqlStatements.size());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) Test(org.junit.Test)

Example 12 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class OracleSqlScriptSmallTest method parseMergeInsert.

@Test
public void parseMergeInsert() throws Exception {
    String source = "INSERT INTO ss.CODETBL(FIELDNAME,FIELDVALUE,IDS)\n" + "SELECT FIELDNAME,FIELDVALUE,IDS FROM\n" + "(\n" + "SELECT 'ACCT_TYPE_CD' FIELDNAME, '$' FIELDVALUE,'SAMP' IDS FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'L','SAMP' FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'C','SAMP' FROM DUAL \n" + ")\n" + "D\n" + "WHERE NOT EXISTS\n" + "(\n" + "SELECT 1 FROM SS.CODETBL \n" + "WHERE D.FIELDNAME = FIELDNAME \n" + "AND D.FIELDVALUE = FIELDVALUE\n" + "AND D.IDS = IDS\n" + ");";
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(1, sqlStatements.size());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) Test(org.junit.Test)

Example 13 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class OracleSqlScriptSmallTest method parsePackages.

@Test
public void parsePackages() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/package/V1__Package.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(2, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(33, sqlStatements.get(1).getLineNumber());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 14 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class MySQLSqlScriptSmallTest method multiLineCommentDirective.

@Test
public void multiLineCommentDirective() throws Exception {
    String source = "/*!50001 CREATE ALGORITHM=UNDEFINED */\n" + "/*!50013 DEFINER=`user`@`%` SQL SECURITY DEFINER */\n" + "/*!50001 VIEW `viewname` AS select `t`.`id` AS `someId`,`t`.`name` AS `someName` from `someTable` `t` where `t`.`state` = 0 */;\n";
    SqlScript sqlScript = new SqlScript(source, new MySQLDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(1, sqlStatements.size());
    assertEquals(1, sqlStatements.get(0).getLineNumber());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) Test(org.junit.Test)

Example 15 with SqlStatement

use of org.flywaydb.core.internal.dbsupport.SqlStatement in project flyway by flyway.

the class EnterpriseDBSqlScriptSmallTest method parseMergeInsert.

@Test
public void parseMergeInsert() throws Exception {
    String source = "INSERT INTO ss.CODETBL(FIELDNAME,FIELDVALUE,IDS)\n" + "SELECT FIELDNAME,FIELDVALUE,IDS FROM\n" + "(\n" + "SELECT 'ACCT_TYPE_CD' FIELDNAME, '$' FIELDVALUE,'SAMP' IDS FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'L','SAMP' FROM DUAL UNION ALL\n" + "SELECT 'ACCT_TYPE_CD', 'C','SAMP' FROM DUAL \n" + ")\n" + "D\n" + "WHERE NOT EXISTS\n" + "(\n" + "SELECT 1 FROM SS.CODETBL \n" + "WHERE D.FIELDNAME = FIELDNAME \n" + "AND D.FIELDVALUE = FIELDVALUE\n" + "AND D.IDS = IDS\n" + ");";
    SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(1, sqlStatements.size());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) Test(org.junit.Test)

Aggregations

SqlStatement (org.flywaydb.core.internal.dbsupport.SqlStatement)21 SqlScript (org.flywaydb.core.internal.dbsupport.SqlScript)19 Test (org.junit.Test)19 ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)11 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 FlywayWithDryRun (org.flywaydb.core.FlywayWithDryRun)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationVersion (org.flywaydb.core.api.MigrationVersion)1 Level (org.flywaydb.core.internal.util.logging.console.ConsoleLog.Level)1