on ‎2012 Aug 16 9:57 AM
Hi,
I was wondering if there is a way to use "OS" environment variable in an sql file.
Im trying to to something like this ->
START LOGGING '%temp%\\sql.log'; UPDATE...; CREATE... ; ALTER... ; STOP LOGGING; INPUT INTO DBA.DB_UPDATE_LOG (TEXT) FROM '%temp%\\sql.log'; COMMIT;
Works fine, if i use a path without the %temp% variable. I want to avoid "access denied" errors while writing the log file.
Regards Stefan
Request clarification before answering.
AFAIK, there's no builtinfunction to get the value of an environment variable in SQL Anywhere. And the feature you're asking for deals with a particular ISQL command, which would be executed outside the database server - so this might be a reasonable product enhancement suggestion.
For a general access to environment variables in SQL code, here is a code snippet to do this via an OS SET command re-directed to a file, which is then read via xp_read_file into a local variable. Note that in order to write to a file, you will also have access to a particular directory.
CAVEAT: Error handling has been omitted...
begin declare strTempDir varchar(255); call xp_cmdshell('SET TEMP > C:\\\\TempPath.txt', 'no_output'); set strTempDir = xp_read_file('C:\\\\TempPath.txt'); set strTempDir = trim(substr(strTempDir, locate(strTempDir, '=')+1)); select strTempDir; end;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.