SQLPLUS session to remember history - perl

I have just started using sqlplus for oracle and it is horrible, I was trying to look for ideas if anyone has any scripts written around sqlplus which stores history and and it works more like an editor.

You might want to consider using YASQL, http://sourceforge.net/projects/yasql/, which is an alternative client written in Perl.
It is pretty neat and covers most of what one would expect from a DB CLI client. It does not support everything sqlplus does, though.

What you want is the extremely handy rlwrap command. It will wrap almost any command and add readline-style command history and editing. It supports, colors, custom completions, and all that jazz. I'm not sure if the link I provided to rlwrap is the "official" source, and compiling it can sometimes be a pain, but your favorite Unix package source should have some version of it available.

Related

PowerShell to executable - go the extra mile or leave it?

It seems like it is not all that easy to create an executable from a PowerShell script - do you know if it was ever meant to be an option?
I have found tools like PS2EXE, but still it does not seem like it was meant to be.
I am asking, if it is worth it to go the extra mile or leave it.
Background reason: I have some less technical users that need a smoother workflow.
As #Bill_Stewart kindly noted:
PowerShell is a shell that contains a powerful scripting language.
Which is perfectly in line with Microsoft's definition :
PowerShell is a task-based command-line shell and scripting language built on .NET.
Basically, wrapping it in an executable would go beyond its purpose. The nice thing about scripting is, that it's lightweight and task based. And in this case, that you can easily run it on multiple OS-ses.
So, I wouldn't go through the effort creating an exe.
If you want to run it easily, just create a .bat or .cmd file (if using Windows). On windows, I believe, you can also create a shortcut with command arguments and a little icon.
For Linux you clould use a .sh.

Debugging perl CGI

I am using a web form I created as an interface to query a MySQL database. I have written some
perl CGI scripts to process the queries. But I am not getting the desired output, so I need to
debug the scripts. How do I do that? I mostly use Eclipse for debugging perl, but now I have the
web form parameters (checkboxes, listboxes) as input to the script. Is there any way I can pass
in the inputs from the web page and then debug the script in Eclipse? Or is there any other way
of debugging in this case? Hope I have made myself clear. Thanks.
I use this Perl module for CGI debugging. It lets you capture all data sent to a CGI script, when running from a normal browser. It then lets you "replay" the script from anywhere (command line, within a debugger) using the captured data.
CGI::Inspect looks promising, though I haven't tried it yet myself.
Using Devel::DumpTrace during a normal CGI session (with the data being logged to a file, via DUMPTRACE_FH) is a way to do in-depth debugging, without using an actual debugger.
Yes, of course you can use Apaches error log to do debugging; which a very lazy but efficient way to work.
You mention you use Eclipse so I assume you also use the EPIC plug-in for Perl development. Check out this chapter on how to configure Eclipse/EPIC for debugging CGI:
http://www.epic-ide.org/guide/ch06s02.php
I would hope Eclipse has a way to simulate CGI.
I use ActiveState's Komodo IDE, and it can simulate CGI (including input params), so I can recommend that as a good tool for this purpose. The IDE is NOT free, though, but consider this an investment if you're going to be doing this a lot. (I'm NOT affiliated with ActiveState - just a happy customer.)
It's not clear what exactly you want to debug, but a few tips:
When running under Apache, warnings go to the error.log, so you could follow your variables there.
The CGI.pm module allows you to run CGI scripts from the command-line (with parameters).
if you have a hypothetical CGI program written in perl, called webawesome.pl and you want to pass it two parameters: name and age, you can use a shell command like this:
prompt> perl -d webawesome.pl name=sifl age=21
Now you're in the perl debugger and you can step through your program, and the key/value pairs from the command line will be loaded as form parameters by CGI.pm
Setting these command line switches in Eclipse is left as an exercise to the reader, as I am an unabashed vi user, and haven't use eclipse in two or three years. I know there's dialogs to set run/debug options.
You can use Firebug or Fiddler to watch your requests made from the form, to ensure you are sending exactly what you think you are. You can also open a file open(fh,">>debug.txt") and print out the sql calls that you are making to a log file. I would also suggest learning about Data::Dumper which will print out objects prettily so you can see their structure.

How can I use emacs to run xquery code on a Marklogic database?

Instead of having to switch between editing files in emacs and doing little tests in the Marklogic query console, I'd really like to be able to open a buffer, write a little XQuery, then run it against a Marklogic server I've got running on a virtual machine. In effect, I suppose the perfect solution would result in something similar to the scratch buffer, where you write some elisp, then hit C-j to execute it.
Mostly I just move my code into libraries, and import those libraries from cq. But you could write elisp that sends your query via HTTP to the cq or QueryConsole eval.xqy module, as an HTTP POST.
You could also use a textarea emacs interface for your browser, so that you can use cq via emacs.
https://chrome.google.com/webstore/detail/ljobjlafonikaiipfkggjbhkghgicgoh
https://addons.mozilla.org/en-US/firefox/addon/its-all-text/
https://github.com/marklogic/cq
Calling eval.xqy over HTTP as suggested by #mblakele is probably easiest. But if you want tighter integration, there is the XCC library (Java/.Net; http://developer.marklogic.com/products/xcc/5.0 ), and also the slightly older libmlcc library ( http://robbertbroersma.nl/blog/a-blog.html ). Perhaps those are useful to you..

How to build a Postgres IDE in Emacs

I noticed emacs has a sql-postgres mode. It's a good start, but my needs are very different. I usually have a large SQL file that I am editing and I want to "run" it on the database. I would like to edit my code in Emacs, not PG Admin. However, I am a bit more picky on how I see the results. I would rather not see a new Emacs buffer since Emacs doesn't really do grids that well. I was thinking of popping up some program that could show me the results in a very pretty, interactive view. Maybe something like openoffice or some custom piece of code.
I think the best method is to hack together a makefile that will automatically run the sql file against postgres (which may even allow me to jump to any errors). Then, if the script is successful, possible pipe the results to some program. But which program and how can I get those results to it?
Please let me know if there is a better way. I don't want some commercial software or Windows-only freeware. I'd prefer OpenSource. Any advice?
You could use psql on the command line and set emacs to be your editor of choice. Whenever you type \e in psql, it will open your editor of choice. Grid display + emacs and there's no need to write any code.

Pipe ESS to terminal outside of Emacs?

I'm not sure if this is possible, but does anyone know if I can pipe ESS commands (i.e. evaluate region) to a R process running outside of Emacs? The Emacs terminal hangs up a bit (more often than Apple's terminal) and I'd like to just ditch it, while still using ESS commands. Currently I am doing the less efficient copy and paste technique :-)
Vince
Why not just kill the underlying R process, start a new one and continue the session in the same ESS buffer?
This doesn't answer your specific question and my experience is on Windows, but assuming it's challenging in ESS, I just mention:
There are other IDE's which have no trouble doing this (e.g. Tinn-R, StatET). In particular, for one supported on multiple operating systems, have a look at the StatET plugin for Eclipse. One very nice feature of Eclipse is that not only can you run the commands on a console outside the IDE, but you can also run multiple console sessions at the same time. This allows you to easily compare results side by side.
Needless to say, that's irrelevant if you're comfortable using ESS.