Skip to content

Commit

Permalink
Merge pull request #2956 from dotCMS/issue-1966-Oracle-SQL-trigger-va…
Browse files Browse the repository at this point in the history
…riable-size-too-small

fixes #1966 Oracle SQL trigger variable size too small
  • Loading branch information
Jason Tesser committed Jun 3, 2013
2 parents 28a6c86 + 50a47cc commit 588b5b6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sql/cms/dotcms_extra_oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ AFTER INSERT OR UPDATE ON identifier
DECLARE
rowcount varchar2(100);
assetIdentifier varchar2(100);
parentPath varchar2(100);
parentPath varchar2(255);
hostInode varchar2(100);
BEGIN
for i in 1 .. check_parent_path_pkg.newRows.count LOOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private List<String> newTriggersForOracle(){
" DECLARE\n " +
" rowcount varchar2(100);\n " +
" assetIdentifier varchar2(100);\n " +
" parentPath varchar2(100);\n " +
" parentPath varchar(255);\n " +
" hostInode varchar2(100);\n " +
" BEGIN\n " +
" for i in 1 .. check_parent_path_pkg.newRows.count LOOP\n " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.dotmarketing.startup.runonce;

import java.util.List;

import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.startup.AbstractJDBCStartupTask;

public class Task01045FixUpgradeTriggerVarLength extends AbstractJDBCStartupTask {

@Override
public boolean forceRun() {
return true;
}

@Override
public String getPostgresScript() {
return "";
}

@Override
public String getMySQLScript() {
return "";
}

@Override
public String getOracleScript() {
String parentPathCheckTrigger =
"CREATE OR REPLACE TRIGGER identifier_parent_path_check\n " +
" AFTER INSERT OR UPDATE ON identifier\n " +
" DECLARE\n " +
" rowcount varchar2(100);\n " +
" assetIdentifier varchar2(100);\n " +
" parentPath varchar2(255);\n " +
" hostInode varchar2(100);\n " +
" BEGIN\n " +
" for i in 1 .. check_parent_path_pkg.newRows.count LOOP\n " +
" select id,parent_path,host_inode into assetIdentifier,parentPath,hostInode from identifier where rowid = check_parent_path_pkg.newRows(i);\n " +
" IF(parentPath='/' OR parentPath='/System folder') THEN\n " +
" return;\n " +
" ELSE\n " +
" select count(*) into rowcount from identifier where asset_type='folder' and host_inode = hostInode and parent_path||asset_name||'/' = parentPath and id <> assetIdentifier;\n " +
" IF (rowcount = 0) THEN \n " +
" RAISE_APPLICATION_ERROR(-20000, 'Cannot insert/update for this path does not exist for the given host'); \n " +
" END IF; \n " +
" END IF;\n " +
" END LOOP;\n " +
" END;\n " +
"/\n";
return parentPathCheckTrigger;
}

@Override
public String getMSSQLScript() {
return "";
}

@Override
protected List<String> getTablesToDropConstraints() {
return null;
}

}
2 changes: 2 additions & 0 deletions src/com/dotmarketing/util/TaskLocatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.dotmarketing.startup.runonce.Task01030AddSiteSearchAuditTable;
import com.dotmarketing.startup.runonce.Task01035FixTriggerVarLength;
import com.dotmarketing.startup.runonce.Task01040CreateContainertStructures;
import com.dotmarketing.startup.runonce.Task01045FixUpgradeTriggerVarLength;

public class TaskLocatorUtil {

Expand Down Expand Up @@ -141,6 +142,7 @@ public static List<Class<?>> getStartupRunOnceTaskClasses() {
ret.add(Task01030AddSiteSearchAuditTable.class);
ret.add(Task01035FixTriggerVarLength.class);
ret.add(Task01040CreateContainertStructures.class);
ret.add(Task01045FixUpgradeTriggerVarLength.class);
return ret;
}

Expand Down

0 comments on commit 588b5b6

Please sign in to comment.