ããã¿ã¤ãã«ãæãã¤ããªãã¦ããããªããã
çµç·¯
ã¡ãã£ã¨ãä»äºã§ãããªã·ã§ã«*1ãä½ããã¨ã«ãªãã¾ãã¦ã
#!/bin/sh sqlplus test/test@orcl << EOF select * from aaaa where id = ${id} and name = ${name} ; EOF
ä½ãé¨å㯠<< EOF ãã EOF ã®éã®SQLãªãã§ããããã®ã¾ã¾ã·ã§ã«ã®ä¸ã«æ¸ãã¦ããSQLãå®è¡ãããªããä½ããªãã§ããããã¨ããããã§ãã¡ãã£ã¨éãã§ã¿ã¾ããã
ãããããã¨
- å¤æ°é¨åã¯å ¨ã¦ãªãã©ã«ã«ãã¦ãSQLãå®è¡ããªããåä½ã§ä½ããã
- SQLãã§ãããã·ã§ã«ã«çµã¿è¾¼ã¿ãã
- ã·ã§ã«ã«çµã¿è¾¼ãã ããå¤æ°é¨åã¯å¾©æ´»ãããã
ã¡ããã£ã¨ãã£ã¦ã¿ã
ããã ãPowerShellã§éãã§ã¿ããï¼ãã¡ãããæ¥åæéã«ï¼
ã¨ããããã§ã以ä¸ã®ãããªãã¡ã¤ã«ãåä¸ãã£ã¬ã¯ããªå
ã«ç¨æãã¾ãã
ãã³ãã¬ã¼ãï¼test.tplï¼
ã·ã§ã«ã®ã²ãªå½¢ã§ãã
#INSERT
#!/bin/sh sqlplus test/test@orcl << EOF #INSERT<test_01.sql> EOF
SQLãã¡ã¤ã«ï¼test_01.sqlï¼
ã¡ã¤ã³ã®ãã¸ãã¯é¨åã
ã/*
select * from hoge where id = /*<REPLACE ${id} */ 999 /*>*/ and name = /*<REPLACE ${name} */ 'nakaji' /*>*/ ;
PowerShellã¹ã¯ãªããï¼test.ps1ï¼
以ä¸ã®å
容ã§ã¹ã¯ãªãããä½æãã¾ãããã¨ã©ã¼å¦çã¯ããã§ãã
å¼æ°ã«ãã³ãã¬ã¼ããã¡ã¤ã«ãæå®ãã¦å®è¡ããã¨ãæ¨æºåºåã«çµæãåºåãããã®ã§ãªãã¤ã¬ã¯ããããªããã¦ãã¡ã¤ã«ã«ä¿åãã¾ãã
Param([String]$templateName) function InsertFile([String]$directory, [String]$fileName) { $insertFileName = Join-Path $directory $fileName if (-not(Test-Path $insertFileName)) { Write-Error ("ãã¡ã¤ã«ãåå¨ãã¾ããï¼" + $insertFileName) return; } Get-Content $insertFileName } Get-Content $templateName | %{ # ã#<INSERT hoge>ãã®é¨åããhogeãã®ãã¡ã¤ã«ã®å 容ã«å·®ãæ¿ãã if ($_ -match "^#INSERT<(.+)>.*") { #Split-Path $templateName -Parent | InsertFile($_, $matches[1]) $directory = Split-Path $templateName -Parent $buf = InsertFile $directory $matches[1] $buf } else { $_ } } | %{ # ã/*<REPLACE hoge */ piyo /*>*/ã ã ãhogeãã«ç½®æ $_ -replace '/\*<REPLACE\s+(.+)\s+\*/\s.+\s/\*>\*/', '$1' }
å®è¡
PS D:\> .\test.ps1 .\test.tpl #!/bin/sh sqlplus test/test@orcl << EOF select * from aaaa where id = ${id} and name = ${name} ; EOF
ãã£ããããã§ã¡ãã£ã¨æ¥½ãã§ããï¼ã¨æã£ããããã®åã«ãã®ãä»äºã¯çµãã£ã¦ã¾ããã¨ããorz
*1:å®éã¯ããã¡ãã£ã¨è¤éãªãã ãï¼æ¬å½ã ãï¼