diff --git a/docs/welcome/features.md b/docs/welcome/features.md index ec9d00e..a00daaf 100644 --- a/docs/welcome/features.md +++ b/docs/welcome/features.md @@ -103,4 +103,16 @@ The set of SQL commands to create the object is stored in a file with the given | ALIAS | *FILE | .SQLALIAS | CREATE OR REPLACE ALIAS | | SEQUENCE | *DTAARA | .SQLSEQ | CREATE OR REPLACE SEQUENCE | -Generic SQL statements with file extension .SQL are executed using RUNSQLSTM \ No newline at end of file +Generic SQL statements with file extension .SQL are executed using RUNSQLSTM + +### Incremental SQL pseudo-source + +If you want different source to run if your object is already built, but want to maintain your code in the same file, write that SQL pseudo-source in the incremental block. Only if the object exists in your library list, will the incremental pseudo-source run. Otherwise, source outside of the block will be the one which runs. + +``` +incremental { + ALTER TABLE ADD COLUMN ... +} + +CREATE OR REPLACE TABLE ... +``` \ No newline at end of file diff --git a/src/mk/def_rules.mk b/src/mk/def_rules.mk index 730da44..c7ca56d 100644 --- a/src/mk/def_rules.mk +++ b/src/mk/def_rules.mk @@ -1058,7 +1058,8 @@ define TABLE_TO_FILE_RECIPE = $(FILE_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL TABLE $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ @@ -1075,7 +1076,7 @@ define PFSQL_TO_FILE_RECIPE = $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef # @$(TOOLSPATH)/checkObjectAlreadyExists $@ $(OBJLIB) @@ -1084,44 +1085,48 @@ define VIEW_TO_FILE_RECIPE = $(FILE_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL VIEW $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef define INDEX_TO_FILE_RECIPE = $(FILE_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL INDEX $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef define SQLUDT_TO_FILE_RECIPE = $(FILE_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL UDT $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef define SQLALIAS_TO_FILE_RECIPE = $(FILE_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL ALIAS $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*FILE) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef @@ -1140,11 +1145,12 @@ define SQLSEQ_TO_DTAARA_RECIPE = $(DTAARA_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL SEQUENCE $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*DTAARA) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef # __ __ _____ _ _ _ _ ____ _ @@ -1304,21 +1310,23 @@ endef define SQLPRC_TO_PGM_RECIPE = $(PGM_VARIABLES) @$(call echo_cmd,"=== Creating SQL PROCEDURE $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*PGM) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" "$(logFile)" "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef define SQLTRG_TO_PGM_RECIPE = $(PGM_VARIABLES) @$(call echo_cmd,"=== Creating SQL TRIGGER $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*PGM) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" "$(logFile)" "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef @@ -1466,11 +1474,12 @@ define SQLUDF_TO_SRVPGM_RECIPE = $(SRVPGM_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating SQL UDF $(OBJLIB)/$(basename $(notdir $@)) from Sql statement [$(notdir $<)]") - $(eval crtcmd := RUNSQLSTM srcstmf('$<') $(RUNSQLFLAGS)) + $(eval tempFile := $(shell mktemp)) + $(eval crtcmd := RUNSQLSTM srcstmf('$(tempFile)') $(RUNSQLFLAGS)) $(eval mbrtextcmd := CHGOBJD OBJ($(OBJLIB)/$(basename $(notdir $@))) OBJTYPE(*SRVPGM) TEXT('$(subst ','',$(TEXT))')) @$(PRESETUP) \ $(SETCURLIBTOOBJLIB) \ - $(SCRIPTSPATH)/launch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" "$(logFile)" "" "$(mbrtextcmd)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) + $(SCRIPTSPATH)/extractPseudoSQLAndLaunch "$(JOBLOGFILE)" "$(crtcmd)" "$(PRECMD)" "$(POSTCMD)" "$(notdir $@)" "$<" $(logFile) "$(mbrtextcmd)" "$(VPATH)" "$(tempFile)"> $(logFile) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef define BND_TO_SRVPGM_RECIPE = diff --git a/src/scripts/extractAndLaunch b/src/scripts/extractAndLaunch index d110e53..d3e2be1 100755 --- a/src/scripts/extractAndLaunch +++ b/src/scripts/extractAndLaunch @@ -26,7 +26,6 @@ while read -r line; do linetmp=$(echo "$line" | sed 's/\+\S*$//') cmd="${cmd} ${linetmp}" continue - fi cmd+=$line diff --git a/src/scripts/extractPseudoSQLAndLaunch b/src/scripts/extractPseudoSQLAndLaunch new file mode 100755 index 0000000..2afc3ed --- /dev/null +++ b/src/scripts/extractPseudoSQLAndLaunch @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +joblog_json=$1 +cmd=$2 +precmd=$3 +postcmd=$4 +object=$5 +source=$6 +output=$7 +text_command=$8 +VPATH=$9 +temp_file=${10} + +objectExists="false" +shouldProcess="true" + +IFS=":" +for dir in $VPATH; +do + if [[ -e "$dir/$object" ]]; then + objectExists="true" + fi +done + +while read -r line; do + if [[ $line == *"{"* ]]; then + if [[ "$objectExists" = "false" ]]; then + shouldProcess="false" + fi + continue + elif [[ $line == *"}"* ]]; then + if [[ "$objectExists" = "false" ]]; then + shouldProcess="true" + continue + else + break + fi + fi + + if [[ "$shouldProcess" = "true" ]]; then + echo $line >> $temp_file + fi +done < <(grep "" $source) + +"$SCRIPT_DIR"/launch "$joblog_json" "$cmd" "$precmd" "$postcmd" "$object" "$source" "$output" "" "$text_command"