SQL commands over SSH/Qshell - sql

I have spent quite a bit of time scouring the overflow forums and using other resources to try and figure this out without success. My apologies if this has been answered elsewhere. But, to my knowledge it hasn't
Here is a little background. I have some experience with SQL, Visual basic and Auto Hot Key (awesome program). Currently I am trying to learn more than the basic stuff I know about SQL (little rusty too).
For my previous and current job I work(ed) a lot with IBM's iSeries (or 'Mainframe' as some veterans like to call it.) Specifically it's version: IBM DB2 PE 9.7 FP5 SRM R1 on the DB2 i5/OS.
As you may know, iSeries related emulators have a feature that allows its users to record macros for later playback. This feature of course has its limitations. I have written some from scratch in Visual Basic that are more flexible in the operations that they can perform. However, you can only do so much with VB.
Regardless of how you look at it, iSeries is slow IMO. In order to pass/retrieve information to/from its database/server its users are limited to the speed of the program (among other things). VB macros are subject to smart pauses/timeouts as these are needed for scripts to work (like auto hot key)
iSeries does have a feature where you can query information, interact with libraries (schemas if I have that right?) and tables using the i5/OS Query manager. It also has an FTP feature (which has its uses I guess).
I have started playing around with Powershell and SSH/Qshell, I have read a lot of documenation in IBMs extensive support section on their site regarding iSeries and all things related.
So here are the questions:
Is qshell/SSH an efficient way to retrieve information from a database, or more specifically, the libraries that 'DB2 for iSeries' uses (.lib/.file extension files?)?
Wouldn't writing SQL scripts and executing them via SSH/Qshell be faster than using the iSeries emulator itself?
Is this only possible via port forwarding or tunneling?
How do I find out more about the server via SSH commands? I can navigate the servers directories pretty easily and view files that I otherwise cannot see within iSeries. Its database files are .lib/.file/.mbr file extensions that I cannot view using the 'cat' command. This would require using SQL commands I am assuming?
Do I need to log on as a root user in order to have read/write access privelages and perform anything SQL related?
As mentioned above I have played around with ssh/qshell but I am having difficulty bringing up the mysql/sql prompt to do anything (I am using openSSH 4.7p1 / a unix CLI?) which I believe changes from $ to > when you successfully do this. I have been able to do this but am unable to execute any SQL related commands so I am not sure what I am doing wrong.
Below is an example of me logging into the server over ssh via powershell and trying to execute something SQL related:
PS H:> ssh -1 myusername#blabla.something.com "mysql -u myusername -e 'show tables;'"
enter password: password
connected
Could not chdir to home directory /home/myusername: A file or directory in the path name does not exist
bsh: mysql: execute permission denied
bsh: cannot execute
Connection closed to blabla.something.com
This is an example of just logging in over ssh as normal:
ssh -1 myusername#blabla.something.com
Could not chdir to home directory /home/myusername: A file or directory in the path name does not exist
$ Mysql
mysql: execute permission denied
$ "mysql
'show databases;'"
mysql
'show databases;'" not found
Any insight as to what I am doing wrong or feedback on my questions is greatly appreciated. I know there are alternatives to what I am trying to do using PuTTY (not really an option at work), ODBC drivers (can't really download an IBM iSeries fixpack to get the drivers or repair the installation of iSeries as I can't anyways I don't have Windows admin privs)
UPDATE
First, I want to thank you all for your comments and your insight.
Warren:
Thank you, for you insight. IBM DB2 PE 9.7 FP5 SRM R1 is indeed DB2 LUW, or "COBRA". This particular emulator is an adaption of IBM's 3270 emulator. This knock off brought to you by attachmate (they added a couple bells and whistles and no longer offer support, ODBC drivers etc). Within this version, I have the option to utilize IBM DB2 Query Manager for i5/OS. I would agree that the server is partitioned (I think?) as I have been able to call different prompts like DB2/SQLJ/JAVA, just haven't been too successful with using them lol. Perhaps my attempts below will reveal a little more.
James:
Thank you for your input, I never thought to do this from powershell directly. As for the redbook, have it! I'm still reading it though. This may be a little more advanced than where I currently stand with powershell and ADO.NET. I will need to take a more in depth look at your coding example to gain a better understanding of it.
Buck:
I appreciate your point by point feedback. Not sure what your setup is, but IBM i in general (especially anything after i5) is insanely fast. The company I work for.. or at least the immediate people I work with, know very little in regards to i/vba/qsh/etc. To put it politely. So, much of what I have learned has been through reading and applying what I learn. This, actually, is only my second post. On any website, ever. I don't like to just post away because I can't figure something out in a minute. I'm stubborn and will spend hours if I have to make a script work.
As for STRSQL, the equivalent I use is STRQRY. From reading IBM's i5/OS Query Manager PDF (300 pgs -_-). I would agree that this is a very powerful tool. The only drawback is 1. you have to make a form that will format the query and 2. You have to create the Query using SQL . This is no big deal whatsoever. Unfortunately, there are hundreds of schemas, and sometimes thousands of .FILE extensions within any given LIB (among other extension types). Luckily I have narrowed this down to the primary LIB that I access most. Unfortunately, there are something like 4000+ files extensions within this library and files within some of those files (︻╦╤─ ^ _ ^). Going through all of them is a little time consuming to say the least.
There are some "macros" that perform a query in batch and then prints the data to a formatted file onto the server (which takes erm... like 30 mins for 500-600 pages). Is there any way I could view the parameters of this batch run? "Work with queries/query forms?"
The primary reason I am more so interested in using QSH>SQL to perform a query and navigate a database is due to the fact I would like to improve my SQL skillz (beginner) but I would like to be able to apply this knowledge to other environments in the future.
God, I write too much s***
My recent efforts: I am sorry. My formatting sucks
After I log in via ssh this is what I attempted:
$ db2 "select * from sysibm.sysdummy1"
db2: cannot execute
$ cd /usr/bin
$ ls
ajar
qsh
sqlj
db2
db2profc
dataq
java
javadoc
javah .....
$ db2 "select from qsys.lib
++++++CLI ERROR++++++
SQLSTATE 42704
LIB in QSYS type *file not found // there are tons of .file extensions within btw
$ cd ..
$ cd qsys.lib
$ ls
A crap load of .lib .menu .file (*file?) extensions
$ db2 "select * from 1234abcd.lib"
++++++CLI ERROR++++++
SQLSTATE 42601
NATIVE ERROR CODE: -104
Token not valid bla bla VALID TOKENS: FOR SKIP FETCH ORDER GET // success! well still fail
Questions
So my problem now is I just need to use valid tokens. Does anybody know of a good example? (im going to attempt on my own still)
For the life of me I cannot replicate the process above, to where I at least get a cli error / SQLSTATE. Everything now returns:
"db2: you should just give up lol"
I try to log everything I do, guess I missed something important ay? Somewhere between...
$ cd /usr/bin
$ ls
and
$ db2 "select * from iforget.lib"
Something happened to where I could at least execute SQL statements. Now, nothing.
db2 : t(ಠ益ಠt)
Its late. So tired
Any feedback = Appreciation

The qshell (and DB/2) equivalent to the mysql cli command is db2:
db2 "select * from sysibm.sysdummy1"
If you have the IBM Access .NET data provider installed you can query directly from PowerShell:
# Assembly name from \\HKCR\Installer\Assemblies\Global
$an = 'IBM.Data.DB2.iSeries,Version="12.0.0.0",PublicKeyToken="9CDB2EBFB1F93A26",Culture="neutral"'
# Connection string
$cs = 'Data-Source=10.0.0.50;UserID=QPGMR;Password=****'
Add-Type -AssemblyName $an
$cn = New-Object IBM.Data.DB2.iSeries.iDB2Connection($cs)
$cn.Open()
$cmd = $cn.CreateCommand()
$cmd.CommandText = "SELECT * FROM SYSIBM.SYSDUMMY1"
$da = New-Object IBM.Data.DB2.iSeries.iDB2DataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$cnt = $da.Fill($ds)
Write-Host "$cnt records selected."
$cmd.Dispose()
$cn.Close()
foreach ($dt in $ds.Tables) {
$dv = New-Object System.Data.DataView($dt)
$dv | Format-Table -AutoSize
$dv.Dispose()
}
$ds.Dispose()
For more information see the IBM Redbook Integrating DB2 Universal Database for iSeries with Microsoft ADO .NET .

1) Is qshell/SSH an efficient way to retrieve information from a
database, or more specifically, the libraries that 'DB2 for iSeries'
uses (.lib/.file extension files?)?
The synopsis was helpful; it appears you are interested in doing ad hoc queries rather than writing an end-user application. qshell is just as efficient as the IBM i command STRSQL in terms of issuing SQL statements and seeing the results immediately in an emulator window. I just queried a 2 million row table on a column without an index and got the first page of results in .23 seconds.
2) Wouldn't writing SQL scripts and executing them via SSH/Qshell be
faster than using the iSeries emulator itself?
It is difficult to understand what faster might mean. It seems you are using the emulator solely to play back macros; this is not particularly efficient. Typically, one would use the emulator to get to a command line, issue the STRSQL command and run ad hoc SQL queries from there. That is very fast in terms of getting the results to display.
3) Is this only possible via port forwarding or tunneling?
This depends entirely on how the network was configured.
4) How do I find out more about the server via SSH commands? I can
navigate the servers directories pretty easily and view files that I
otherwise cannot see within iSeries. Its database files are
.lib/.file/.mbr file extensions that I cannot view using the 'cat'
command. This would require using SQL commands I am assuming?
Whoever hired you must have given you some basic information to get you started, so you probably already know the libraries (schemas) and files (tables) which make up the production environment. So I'm assuming that you aren't asking about SQL catalogs like SYSCOLUMNS and SYSTABLES but rather things which are more specific to IBM i. The reference material for IBM i is located in the Infocenter.
5) Do I need to log on as a root user in order to have read/write
access privelages and perform anything SQL related?
No system demands root privileges in order to perform read/write access. Your employer will need to provide you with a user profile having privileges to the tables you want to access.
If you need a light weight terminal emulator, look at the tn5250 project on Sourceforge. You won't need Windows admin privileges to install or run it.

Related

Does Firebird have the ability to run system level commands?

Ive been playing around with Firebird and isql. I noticed it has the 'shell' command. However this shell drops you to a sub-process on the local system regardless if your connected to a remote DB. Is it possible to run system level commands on Firebird on the system hosting the DB? Google seems to be useless with regards to Firebird, I have read the documentation for Firebird too and dont see any mention of it.
The only way to do it is to write UDF function (in such languages like Delphi or C/C++). But even if you write or find such a function, its usefulness may be limited because Firebird can run under special user account with limited rights.
There is no way to execute shell commands in remote system via isql.

how to create a local offline sqlplus database from an sql file?

I'm in a database class and the teacher wants us to connect through ssh to an oracle database setup on a school server and it's been extremely frustrating. She wants us to turn in an sql file that will create all the necessary table, insert tuples, run certain select commands which I've found to be very hard to get an sql file with everything after i get everything right and I haven't found a way to test the sql file against the server and I don't think I have permission to drop tables anyway. Anyway my question is there a way I can take an sql file with create table and insert commands to convert it to something like an access .mba database or something local i can mess around with? and help would be greatly appreciated didn't find much help on google.
You seem to be confusing terminology a bit; SQL*Plus is a client application, and the database is a shared server resource. You want to create schema objects from an SQL file, I think. But anyway...
There's a very useful online resource for experimenting with bits of SQL in various flavours, SQL Fiddle. Technically not 'offline' of course, but I'm taking that to mean off your school's network, not necessarily completely isolated. You can create tables and run your inserts in the schema panel, and then run queries against that. Make sure you pick the right database product from the drop-down menu so you're using syntax that is valid for your class. You'll see a lot of answers here with links to demonstration fiddles.
That's great for a lot of things but if you want something a bit more robust and scalable, and entirely offline, you can install VirtualBox and get a pre-built developer VM image which gives you a ready-to-go Linux environment with a database installed and running. You can run whatever you want against that, you have SQL*Plus and SQL Developer available, and you can connect to the DB from your host machine if you want to. You can create and test your scripts against that, and in a format that will be closer to what you have to hand in than you'd use with SQL Fiddle.
This is much less work than installing the Oracle software yourself and learning how to create and manage the database, which I'm guessing is a bit more advanced than you need at the moment, based purely on the kinds of thing your question suggests you're dong at the moment. I think you'd learn a lot from the installation and build process, but I'd get comfortable with Oracle first, and maybe practice in a VM first as it's so much easier to trash it and start again when you mess something up.
If I wanted 'something local I can mess around with', I would go for a VM image. Mo posted a walkthrough of the VM setup as a comment to a previous similar answer, which you might find helpful.
"Something local I can mess around with" in terms of Oracle Database is Oracle Database 11g Express Edition. It's free and can be downloaded from oracle.com. You certainly can test sql-files run through sqlplus on Oracle Database XE.
To get the MS Access (GUI) feeling, download SQL Developer. It's free.
Best of luck!
Bjarte

OpenEdge Progress DB Export

I have an OpenEdge Progress v10.1C linux server with a bunch of data on it. We're migrating this data to an SQL server. I just need to get the data off of the server somehow, be it a bunch of CSVs of tables or an sql file or whatever - I just need the raw data.
I have no experience with this server and I can't seem to figure out how to even connect to it or anything. I just know where the data directory is and that I have a bunch of files in /usr/dlc/bin which are for management (like _progres, pro, ...)
I would really appreciate any help extracting this data!
At a command line execute $DLC/bin/showcfg -- this will reveal what you have available for licenses which will have an impact on what options you have to export the data.
If your license allows, to get simple text files you can use the "data dictionary dump". To run that start a session from a command line like this:
mpro dbName -p dict.p
If your licenses are good that will bring up the data dictionary. Navigate to Admin -> Dump Data and Definitions -> Table Contents if you get that far then go ahead and dump what you need.
If the database is large this may take a while. Maybe even a long while.
If you cannot navigate to that point then then you do not have an appropriate license. In that case if you have SQL installed and configured then the simplest thing may be to just extract the data with that. But since you are asking this question that seems unlikely -- none the less... type "ps -ef | grep sql" and see if anything shows up. If it does you should be able to connect an ODBC client.
If all else fails you can try to get someone to write you a custom extract program. That will need to be done by someone with a compiler license and they will need to provide you with r-code. That sort of thing is usually provided as a commercial service.

Creating a local SQL database file?

Please note:
I am a game programmer, so backend development isn't my forte. There are times, however, where I work with our database at my job. Please don't shoot me if my question is ridiculous.
Is there a way to create a local mySQL file and access it through PHP or C#?
I know you can make a local webpage on your machine (pretty much for testing purposes) and access multiple locally created files.
I assume that something similar would work with mySQL. (Are the login credentials also stored within the file?) I remember seeing a few online tutorials where it offered a download for both PHP and the database file, but I can't seem to find them now.
I've searched for this, but all the relevant results involved downloading mySQL and hosting a server which is a bit more than I wanted to do.
So if its possible to create a local mySQL, how do you do so?
The tools I intend on using while doing this:
PHP/JQUERY/HTML and C#
For MyISAM tables, inside the MySQL data directory there is one directory per database which contains several (usually three) files per table. For InnoDB tables, they are all contained in several files directly inside the data directory.
The location of the MySQL data directory is usually set in my.cnf using the datadir parameter.
The login credentials are stored in a special database called "mysql" which is in that data directory like any other database.
However, you have to install and run MySQL to access those files. You cannot access them with PHP or any other client API alone. If you want to do such a thing, better use SQLite.
MySQL is a database engine, u need to install that before you can use it. Unlike SQLite which stores it's database in files. Maybe that is something more of your liking. And I know there are library that supports SQLite for PHP, not sure about the rest.
SQLite you don't need to install anything.
MySQL can be used an an embedded database, but you will need to contact them in order to purchase a copy of it.

Need remote or web-based MS Access SQL tool (e.g. similar to PhpMyAdmin, but ColdFusion-based)

I've been looking all over the web for a ColdFusion-based SQL administration tool for Microsoft Access and I can't find one that's simple, free and allows running SQL statements. Any suggestions?
Thanks for the recommends, guys, I'll try SQLSurfer. (MSSSME won't work for me.)
"DISCLAIMER: Using MS Access in a (web based) production environment is not recommended."
I understand that, and part of my timeline for this website is to migrate the database to MySQL on our server.
My primary interest in this is to be able to fool around with SQL commands LOCALLY so I can modify some tables. I wouldn't use this in a production environment anyway, especially not one that already has MySQL admin (Don't worry, I have plenty of backups in case I screw something up).
DISCLAIMER: Using MS Access in a (web based) production environment is not recommended.
That said, I have to admit that there are projects, customers, etc. where you can't get around having to deal with MS Access Databases the one or other way.
There is an Open Source project on RIAForge, called SQLSurfer which is a web-based ad-hoc query tool powered by ColdFusion. It is a simple way to execute SQL statements on your database (not restricted to MS Access). http://sqlsurfer.riaforge.org/ Actually there is no download link, but you can still get the code from SVN repo. http://svn.riaforge.org/sqlsurfer/
I have been working with an earlier version for a long time and I find it useful for executing prepared SQL statements. It is a very dangerous tool, especially in production, so I'd strictly recommend to include it in a password protected administration environment and deny public access.
Can RDS satisfy your needs? works with CFEclipse / CFBuilder.
Take a look at SQL Server Management Studio Express - though I've not used it with MS Access, so can't guarantee it'll work.
Hopefully someone more experienced with the two can come along and give more details.
You can easily make one your self.
On Adobe's website you can find at least 5 of those tutorials Here's one http://www.adobe.com/devnet/flex/articles/f4cf_firstapp_part1.html which uses Apache Derby, similar to MS Access.
Of course you need to think some things through, like authentication, making some field for writting SQL statement which is going to be sent as cfquery, but it should be a nice experience to make you'r own "phpMyAdmin" ;)
For MySQL there is CFMyAdmin.com. It might connect or could be adapted to tonnect to MS Access as well. I agree with Henry though, I'd set up the DSN for your access database, the RDS conection in CFBuilder and then use the query tool.
Other alternatives might be Lita (Mac based), or a FireFox add on like Sqlite Manager. They may surprise you as to what they can open.
Also, Charlie Arehart has a long list of CF based SQL Query tools. Maybe one of them could help: http://www.carehart.org/cf411/#query
Good luck