I have this dbobject.file which in turn calls several dml,ddl and prcs.
I am trying to execute this file using ant but it requires only the sql statements,throws error for set define and spool.It is working using sqlplus but I want to run using ant,so calling this dbobject file should execute the dmls and ddls.
set define off
spool dbobjects.log
prompt calling D:\Pst1\Intel\tag\txt1.dml
#"D:\Pst1\Intel\tag\txt1.dml"
prompt calling D:\Pst\Intel\tag\txt2.dml
#"D:\Pst\Intel\tag\txt2.dml"
set define on
Thanks in advance.
From the sound of your question it sounds like you're trying to figure out how to convert an Oracle sqlplus script into a SQL Ant task.
Both spool and set aren't SQL commands, they don't affect the server, instead they change how sqlplus operates locally. So in the context of Ant they wouldn't mean anything. If you're printing results in your script you can use the output= attribute to do something roughly similar.
If you were converting your sqlplus script to Ant I'd expect it to look something like this:
<sql driver="org.database.jdbcDriver" url="jdbc:database-url" userid="sa" password="pass"
src="txt1.dml"
output="dbobjects.log" />
<sql driver="org.database.jdbcDriver" url="jdbc:database-url" userid="sa" password="pass"
src="txt2.dml"
output="dbobjects.log"
append="true" />
This would execute txt1.dml and txt2.dml as a set of SQL files against your database and would save any result sets generated into dbobjects.log.
This may not work in all cases especially if you're relying on anything sqlplus provides like report formatting or nested imports. In that case you'd need to rewrite your source files to only contain SQL.
Related
I need to execute a script (Informix code) in a .sql file for migration purposes. The thing is, I want to load it from a function to be able to use the exception, therefore being able to do a rollback in case of an error.
So, this is the code (still experimenting):
DROP FUNCTION IF EXISTS "informix".SCRIPT_MIGRATION();
CREATE FUNCTION "informix".SCRIPT_MIGRATION()
RETURNS BOOLEAN as RESULT;
DEFINE lv_execute lvarchar(32739);
DEFINE li_errnum, li_eisam INT;
DEFINE lv_errtxt CHAR(200);
ON EXCEPTION SET li_errnum, li_eisam, lv_errtxt
ROLLBACK;
CALL regista_log('script_migration', get_session_user(), li_errnum, lv_errtxt);
RETURN 'f';
END EXCEPTION;
CALL set_isolation_level();
BEGIN;
LET lv_execute = 'LOAD FROM ''C:\Users\Admin\Desktop\ConstaWeb_Stuff\test.sql'' DELIMITER ''+'' INSERT INTO SCRIPT_MIGRATION_TEMP_TABLE;';
DROP TABLE IF EXISTS SCRIPT_MIGRATION_TEMP_TABLE;
CREATE TABLE SCRIPT_MIGRATION_TEMP_TABLE(
STRING_TO_EXECUTE LVARCHAR(31739)
);
EXECUTE IMMEDIATE lv_execute;
COMMIT;
RETURN 't';
END FUNCTION;
CALL SCRIPT_MIGRATION();
That's because we apparently can't execute the load command inside functions. So I'm trying to execute it. But I'm not getting it right, apparently...
The objective here is to execute the script (not a shell command script! it's an Informix script, like creates, loads, unloads, drops...) on a file. I'm open to other ways of doing this.
I'm relatively new to Informix so I'm sure there is still a lot I don't know about it.
As already noted, the LOAD command is not a command recognized by the Informix server. Client products emulate an SQL statement by recognizing the syntax and reading the file and executing appropriate SQL statements. Changing the way you (try to) execute it in a function executing in the server will not help.
Using a shell script instead may help.
If you're migrating an existing Informix database to a new location (machine, version of Informix), then using DB-export and DB-Import may be a good way to go.
The DB-Access command is the 'standard' way to execute scripts from a shell script. You'd need to ensure you set the DBACCNOIGN environment variable to 1. That will then stop if there's an error during the LOAD and rollback the transaction. There's also the DB-Load command, but it will be harder to rollback DDL statements since it does not handle those.
Alternatively, you might find my SQLCMD* program useful — though it too isn't perfect. However, unlike DB-Access, it allows you to control which statements can generate errors that are ignored and which are not (continue [on|off|push|pop]; before and after as appropriate).
With careful packaging, you can use it to create your migration, assuming the DB-Export and DB-Import won't do the job for you automatically.
* You may have to subscribe to the IIUG to get at this. The registration is not onerous, and neither is the email load.
Is there any way in Netezza Stored Procedure to put output into a file? By output I mean statements from Notice statement in Netezza. Also we can't use any shell or other script because the SP is being invoked via a tool which cannot execute shell scripts but only make DB calls.
There are multiple ways to write these values to a file -
1) Write UDX which can put your statements to disk
2) Every raise notice statement gets log in "/nz/kit/log/pg.log" file, so you need to write a bash which runs with cron or similar tool and extract required information for you.
I have an Ant buildfile (build.xml) which is called by some application. I would like to know exactly what kind of properties are used to invoke Ant. Therefore I would like to modify the build.xml file to display all properties specified in the call, e.g.:
ant aTarget -Dxslt.parser=SAXON -Dbasedir=aFolder
would display list as below
- target: aTarget
- xslt.parser = SAXON
- basedir=aFolder
Please note that I do not know exactly what is being using to invoke Ant. Therefore, I need to use some sort of a loop get all properties, options.
The simplest thing that comes to mind is to place a line like:
<echo message="Ant invocation is '${sun.java.command}'" />
In the buildfile outside of any target. It'll look something like:
% ant aTarget -Dx=y
[echo] ant invocation is: 'org.apache.tools.ant.launch.Launcher -cp . aTarget -Dx=y'
It shows you what was passed to the Ant Launcher, which might will likely be a little more than what was passed to the ant wrapper script, but should do.
I would avoid trying to parse the line, as you say, you don't know what might be there, and it could quickly get complicated.
Take a look at the <echoproperties> task:
<property name="in.file.prop" value="value2"/>
<echoproperties/>
in.file.prop and its value will be printed. However, over 60 other properties will be printed as well including properties built into Ant.
You can save the results of <echoproperties> to a file and then filter that file with something like a <linecontains> filter.
Is it possible to send one property file and a separate value as two different parameters to an Ant script ?
E.g. build.xml propertyfile=propfile -Dname1=value1
RTFM ;-) means see Ant manual running Apache Ant, f.e.
ant -f whatever.xml -propertyfile=/var/usr/foobar.properties -Dfoo=bar
multiple -Dkey=value or -propertyfile=path/to/propertyfile are possible
I am reading a file in ant and loading the properties through loadproperties. I am interested in using the value of a specific property, whose name is not known. I know that it follows a pattern because that is how I load the property.
I can echoproperties and see that it is being loaded.
But I dont know how to access its value, given that its name is actually a pattern rather that hardcoded.
How can I access this property's value to do some processing.
I hope this is clear. Please ask if I need to clarify some more.
Take a look at ant-contrib package. Its propertycopy task will do what you need. If you need to resolve an arbitrary number of properties following an established pattern, you would use ant-contrib's propertycopy in conjunction with ant-contribs "for" task.
http://ant-contrib.sourceforge.net/tasks/tasks/index.html
You should use Ant's script task.
I suggest using the beanshell script since it is pure java.
For example, to print all properties for your project, use the following:
<target name="echoprops">
<script language="beanshell">
System.out.println("All Properties: " + project.getProperties().keySet());
</script>
</target>
It should be easy to modify the above script to get the property you want.
To use this task, you will need to run the following in $ANT_HOME first:
ant -f fetch.xml script -Ddest=user
That will download all required optional jars to ~/.ant/lib .