I'm playing around with orient db for the first time. I have it up and running and I can execute simple scripts via the console.
However, what I really want to do is to use the extra SQL Batch commands such as 'let.'
e.g. the sample script from the wiki:
begin
let account = create vertex Account set name = 'Luke'
let city = select from City where name = 'London'
let edge = create edge Lives from $account to $city
commit retry 100
return $edge
If I write a script using those commands, the console throws errors as they don't appear to be supported. The wiki suggests that's because they are only available via the Java and HTTP APIs.
Pasting the content of the script into Studio works fine, but that's a fairly unsatisfactory way to run a simple script.
Am I missing something or is there no way to run a script containing SQL Batch commands via a simple command line instruction?
You can execute it from console by using the script sql command. Remember to close it by typing end on a new line. Example:
MacBook-Pro:bin luca$ ./console.sh
OrientDB console v.2.0-SNAPSHOT (build 2539) www.orientechnologies.com
Type 'help' to display all the supported commands.
Installing extensions for GREMLIN language v.2.6.0
orientdb> connect plocal:/temp/databases/ETLDemo admin admin
Connecting to database [plocal:/temp/databases/ETLDemo] with user 'admin'...OK
orientdb {db=ETLDemo}> script sql
[Started multi-line command. Type just 'end' to finish and execute]
orientdb {db=ETLDemo}> begin
orientdb {db=ETLDemo}> let a = create vertex v
orientdb {db=ETLDemo}> commit retry 100
orientdb {db=ETLDemo}> end
Server side script executed in 0,117000 sec(s). Value returned is: V#9:199 v1
orientdb {db=ETLDemo}>
Related
I'm working on some web-based tools for our IT department, and need to launch a PowerShell script to do remote maintenance queries prior to loaning out a laptop.
I have an existing web-based registry of the laptop inventory, when one is loaned out we get the borrower to log in before they leave to ensure their profile is on the machine. At that point, I would like to query the laptop using a PowerShell script collecting information from it which would feed to the database and show on the display page.
The page itself is restricted to IT personnel, and our environments are very homogeneous -- everyone is running Windows (7 or 10) and IE (10 or 11).
I can launch a PowerShell script server-side easily enough from the VB code.
[ CommandToRun is a textbox, PStext an output span ]
Dim app = New Process()
Dim psi As ProcessStartInfo = app.StartInfo
psi.FileName = "powershell.exe"
psi.Arguments = CommandToRun.Text
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.UseShellExecute = False
PStext.InnerHtml &= "<br/>Launching app: " & psi.FileName & " " & psi.Arguments
app.Start()
app.WaitForExit(5000)
PStext.InnerHtml &= "<br/>OUTPUT<br/><pre>" & app.StandardOutput.ReadToEnd() & "</pre>"
PStext.InnerHtml &= "<br/>ERROR<br/><pre>" & app.StandardError.ReadToEnd() & "</pre>"
But it runs as the local system which does not have the authority to run remote PS commands. Lacking Administrator status, the server cannot execute anything on remote computers, therefore cannot query the laptop being loaned out.
I found a Javascript client-side solution that looks easy enough:
function tryLaunch(commandtoRun, commandParms) {
// Instantiate the Shell object and invoke its execute method.
var oShell = new ActiveXObject("Shell.Application");
// Invoke the execute method.
oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
}
But it gets a Permission denied error launching the shell.
Other sources have had the same JavaScript with "WScript.Shell" as the ActiveXObject parameter -- that fails on the construction, whereas the "Shell.Application" version fails on the ShellExecute command.
I know what I'm doing is intentionally disallowed, as its usually a pretty dangerous idea to allow web servers to launch code on clients, and portability issues kill even the most well-meaning ideas -- but like I said, this is a very controlled and homogeneous environment.
So ... my questions:
Am I missing an obviously better way to do this?
Should I focus on trying to make PS scripts run on the client? ( If so, any clues?? )
Should I focus on running the script server-side with different
access rights? ( Can I shell as the web site user? I have their
"user" object from AD )
Am I ignoring some capability of IIS to install a PS script as an
application using an Administrator account? (Seems like this should exist, which means I'm probably looking right at it and not seeing it. )
How can I get all the codes and commands which was executed previously command line SQL of the Oracle 10G Express Edition to new SQL command line?
Like from tempfiles or something else. My OS is Windows.
Here's how I do that:
open CMD
connect to the database using SQL Plus
recall previous commands by pressing the "UP" keyboard key
they are recalled line-by-line, not as a whole command, which means that if you'd like to recall something like this:
select ename
from emp
where deptno = 10
you'll need to press the UP key 3 times
note that - if you want to run the last command (no matter how many lines it spans) - enter slash / at the SQL> prompt and hit the ENTER key
even if you exit SQL Plus, no problem as long as you keep the same CMD window open; just connect again and the same functionality will still be available, in your new SQL Plus session
however, it'll be lost if you close the CMD window
The bottom line is: GUI tools are much more appropriate in this context.
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.
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 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.