Calling ISQL from a shell script


  19:
  20:@echo off
  21:
  22:::Check if on-line help is required
  23:for %%v in ( %* )  do (
  24:  ( @if /I "%%v"=="-h" (goto :HELP & goto :EOF) )
  25:  ( @if /I "%%v"=="/h" (goto :HELP & goto :EOF) )
  26:  ( @if /I "%%v"=="HELP" (goto :HELP & goto :EOF) )
  27:)
  28:
  29:
  30:@goto :MAIN
  31:@goto :EOF
  32:
  33:
  34::HELP
  35:::===
  36:@echo.
  37:@echo.
  38:@echo     Run this script from a console prompt.
  39:@echo     Pass the name of the master script as the one and only parameter.
  40:@echo     This master script must have the same name as the alias used
  41:@echo     for the database that is being worked on.
  42:@echo.
  43:@echo     If the alias does not exist in alias.conf it will be added.
  44:@echo     This step requires that you have the env. var FB_DATA defined
  45:@echo     and the alias will be set to:
  46:@echo.
  47:@echo       %%ALIAS%% = %%FB_DATA%%\%%ALIAS%%.fdb
  48:@echo.
  49:@echo     Other available parameters:
  50:@echo.
  51:@echo       HELP       This help screen.
  52:@echo.
  53:@echo.
  54:@goto :EOF
  55:
  56:
  57::ERROR
  58:::====
  59:@echo.
  60:@echo   Error in execsql.bat
  61:@echo     %*
  62:@echo.
  63:popd
  64::: Attempt to execute a phony command. This will ensure
  65::: that ERRORLEVEL is set on exit.
  66:cancel_script > nul 2>&1
  67:::End of ERROR
  68:::------------
  69:endlocal
  70:@goto :EOF
  71:
  72:
  73:::============
  74::MAIN
  75:
  76::: Check we have a param on the command line
  77:@if "%1"=="" (goto :HELP & goto :EOF) else (
  78:set ALIAS=%1
  79:)
  80:
  81:@echo off
  82:
  83:::Delete old log
  84:del /q %1.txt > nul 2>&1
  85:
  86:::Check we have an alias for %1
  87::: If it doesn't exist then check for FB_DATA and
  88::: try and create it.
  89:@findstr /b /i %ALIAS% %FIREBIRD%\aliases.conf > nul
  90:@if %ERRORLEVEL% GEQ 1 (
  91:@if "%FB_DATA%"=="" (
  92:  call :ERROR Could not locate an alias for this database  & goto :EOF
  93:) else (
  94:  @echo %ALIAS% = %FB_DATA%\%ALIAS%.fdb >> %FIREBIRD%\aliases.conf
  95:  @echo. >> %FIREBIRD%\aliases.conf
  96:  @echo added %ALIAS% alias
  97:))
  98:
  99:::run creation script
 100:if EXIST %ALIAS%.sql (
 101:@echo Running %ALIAS%.sql...
 102:isql.exe -e -i %ALIAS%.sql -o %ALIAS%.txt -m -m2 > nul
 103:) else (
 104: @echo Could not find %ALIAS%.sql.
 105: @echo Exiting.
 106: goto :EOF
 107:)
 108:
 109:::print errors
 110:@echo Checking for Errors
 111:@findstr /n /i /c:"statement failed" /c:"unable" %ALIAS%.txt || (
 112:@echo No errors found.
 113:@echo Script completed successfully.
 114:)
 115:
 116:::endlocal
 117:goto :EOF
 118:
 
When all goes well we should see something like this: