Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/welcome/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,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
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 ...
```
45 changes: 27 additions & 18 deletions src/mk/def_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1026,11 +1026,12 @@ define TABLE_TO_FILE_RECIPE =
$(FILE_VARIABLES)
$(eval d = $($@_d))
@$(call echo_cmd,"=== Creating SQL TABLE from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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)
Expand All @@ -1039,44 +1040,48 @@ define VIEW_TO_FILE_RECIPE =
$(FILE_VARIABLES)
$(eval d = $($@_d))
@$(call echo_cmd,"=== Creating SQL VIEW from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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 from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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 from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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 from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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


Expand All @@ -1095,11 +1100,12 @@ define SQLSEQ_TO_DTAARA_RECIPE =
$(DTAARA_VARIABLES)
$(eval d = $($@_d))
@$(call echo_cmd,"=== Creating SQL SEQUENCE from Sql statement [$(notdir $<)] in $(OBJLIB)")
$(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('$(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

# __ __ _____ _ _ _ _ ____ _
Expand Down Expand Up @@ -1259,21 +1265,23 @@ endef
define SQLPRC_TO_PGM_RECIPE =
$(PGM_VARIABLES)
@$(call echo_cmd,"=== Creating SQL PROCEDURE 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('$(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 in $(CURLIB)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('$(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


Expand Down Expand Up @@ -1421,11 +1429,12 @@ define SQLUDF_TO_SRVPGM_RECIPE =
$(SRVPGM_VARIABLES)
$(eval d = $($@_d))
@$(call echo_cmd,"=== Creating SQL UDF 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('$(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 =
Expand Down
1 change: 0 additions & 1 deletion src/scripts/extractAndLaunch
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ while read -r line; do
linetmp=$(echo "$line" | sed 's/\+\S*$//')
cmd="${cmd} ${linetmp}"
continue

fi

cmd+=$line
Expand Down
46 changes: 46 additions & 0 deletions src/scripts/extractPseudoSQLAndLaunch
Original file line number Diff line number Diff line change
@@ -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"