how to execute orientdb script using windows command line.
For Example i have been trying
<< console.bat script.osql >>
but i need a command to execute it from windows command line with username and password . I know usually there is a way in mysql to execute .sql file from command line. IS there any similar way in orientdb ?
I'm a newbe to orientdb.appriciate any kind of help
Thanx.
I presume the script.osql file contains a bunch of SQL scripts and you are trying to execute a batch script?
If so you can include the login info in the same file as yet another SQL script and get the job done.
Following is a sample script (say script.osql),
connect remote:localhost/Test2 admin admin;
CREATE CLASS B;
CREATE PROPERTY B.name STRING;
CREATE CLASS A;
CREATE PROPERTY A.name STRING;
ALTER PROPERTY A.name MANDATORY true;
CREATE PROPERTY A.bList LINKSET B;
and you can execute the above batch script using the console.bat. Command similar to below;
console.bat script.osql
Hope this helps.
Related
I am facing a problem in DB2. In my Oracle environment it was very easy for me to include multiple scripts in one master script, which were executed sequentially. e.g.:
Master.sql:
connect ....
#script1.sql
#script2.sql
Now I have to build up same logic in DB2 LUW. Is there a simple way to include multiple scripts in one master script? I would like to have one single db2 call from shell, which executes the master script and within all subscripts.
Regards
Jan
There is notrhing to stop you from creating a single file with multiple sql batches. In the Windows world, it would look like this:
Note: First you initialize the db2 command prompt.
db2cmd -c -w -i %1.bat
With as many of these as you want in the .bat file:
db2 -txf c:\Example\db2html.sql
In Linux, the db2clp is included in the shell once you load the db2profile ('. /home/db2inst1/sqllib/db2profile). In windows, you need to call db2cmd in order to use db2clp.
With a interactive db2clp, you cannot call db2 scripts via #scriptX, however, you can call them from the shell like
db2 -tvf script
However, if you use the CLP*Plus you can do almost everything you do in SQL*Plus. For more information: https://www.ibm.com/developerworks/community/blogs/IMSupport/entry/tech_tip_db2_s_new_clp_plus_utility?lang=en
I have a script in a file (mysqlscript.sql) that is basically a bunch of inserts/updates/deletes separated by GO statements
insert into ....
GO
update .....
GO
How do I run this script?
You can try to use $system.SQL.ImportDir()
And of course, you can read your file and execute each sql-query in your programm.
The tool Caché Monitor use GO as statement separator and connects to InterSystems Caché. With this tool you can execute your script.
I have a bunch of SQL scripts (with shell script wrappers) to unload data like so
EXPORT TO /tmp/out.csv OF DEL MODIFIED BY NOCHARDEL COLDEL, DATESISO
MESSAGES /tmp/out.msg SELECT WIDGETID
...
I want to add an error handler to the script the way Oracle does it:
WHENEVER SQLERROR EXIT FAILURE;
SPOOL /tmp/out.csv;
SELECT WIDGETID...
SPOOL OFF;
According to DB2's documentation, this can be done in stored procedures, C, Perl, REXX, and nothing else...
How can this be done in SQL scripts?
I am running DB2/LINUXX8664 9.7.2.
you could use the DB2 command line command processor and get its return code. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0010411.html
or you could use the SYSPROC.ADMIN_CMD procedure and use its return codes. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0023573.html
you could put the stored proc calls in a script file and run something like db2 -tvf runexport.txt or put the db2 commands in a linux script file and use linux scripting foo to handle the db2 return codes.
I want to load and execute a sql file from another sql file, but do not the syntax. Is this possible? In detail, I have a file install_tables.sql which should load a file tables_definition.sql.
If you run your script using psql you can embedd the \i command in your main script:
\i tables_defininition.sql
In linux I can do something like this:
mysql -u user -p=pass somedb <(echo "create database foo;")
How can I do that with windows batch scripts?
Basically, I want to make a batch file that runs a sql script without having to keep the script in a separate file.
Thanks
One way is to echo the SQL commands into a file, run the mysql command with option to include the SQL file, and then remove the file (if you really don't want it.)
You can do
echo create database foo;|mysql ...
just fine, but for multiple lines you really want to make a temporary file you just pass to MySQL to read.