http://pgtap.org/integration.html#perl mentions how to run the tests, but I cannot find an example of a Perl test case.
Do I have to get a DBI connection manually, run my commands on it, and check the results?
Does it even make sense to use Perl vs SQL code?
Am I missing something?
pgTap is for parsing SQL output - output from running an SQL script via psql from the command line. An SQL script that contains pgTap SQL calls mixed in with the SQL statements that you wish to test.
As such, DBI doesn't enter into it.
Related
Been looking around, can't find an answer to my problem.
I am using a SQLCMD script, within T-SQl. So i start the script from SQL Server Management Studio and select the SQLCMD mode.
I use the variable SQLCMDHEADERS -1, like ":setvar SQLCMDHEADERS -1"
Next i run a lot of queries for output, to be stored into a file.
The header is still being printed however. Weird thing. Within in SQL Server 2012 this is working like how it should..
Anyone has a clue?
i am trying to execute following unix command but its not getting executed
$array_of_tables= `dbsmp $srv_name`;
print "$array_of_tables\n";
please help me to find out list of tables in a data base through perl scripting.
Also i am trying to copy a file from a path to different path by using following command:-
copy(`cd /osp/slee/service/$srv_name/bin/exec/script.txt`,`cd /osp/local/home/linus/amit/scripts`);
but getting an error:-
Usage: copy(FROM, TO [, BUFFERSIZE])
please provide some solution
Thanks
Use doublequotes instead of back ticks.
copy("/osp/slee/service/$srv_name/bin/exec/script.txt","/osp/local/home/linus/amit/scripts");
and remove the cd
In Perl, the preferable way to capture the output of a system (shell) command is the qx() operator. See http://perldoc.perl.org/perlop.html#Quote-Like-Operators.
$array_of_tables = qx(dbsmp $srv_name);
print("$array_of_tables\n");
Actually, backticks should also work, so the problem must lie with your dbsmp command. I'm not sure what that command is; you'll have to provide more information about the utility and what error you're seeing.
For comparison, I can retrieve the list of tables in my local postgres database as a pipe-separated table using this shell command:
> psql -tAXq main postgres <<<\\d;
And this can be run from Perl as follows:
> perl -e 'print(qx(psql -tAXq main postgres <<<\\\\d;));'
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 simple perl script that uses DBD::Oracle to run a query and print the results. It works fine from the command line, but I also have a PHP script that runs it and reads the output. When the PHP script is accessed through apache it fails to connect, with the error "OCIEnvInit".
I've tried creating a shell script that re-sets all the environment variables available in the shell but that didn't help, and I also tried setting the debugging output for DBI but got nothing. What could cause this error when the script does work?
Are you sure that ORACLE_HOME and other relevant environment variables (e.g., LD_LIBRARY_PATH) that are set in your shell when you run the script from the command line are also set to the same values in the apache/PHP process?
Is there an equivalent in PostgreSQL of the Oracle SQLPLUS "set echo on" so that I can get batch input
statements echoed in the output?
I have a very large file with input statements in it that has a few errors when I run it.
I am having difficulty finding the statement that produced the error because psql is only reporting
the error - not the statement that generated the error.
You need to pass the -a (or --echo-all) argument to psql. It's described at https://www.postgresql.org/docs/current/static/app-psql.html under OPTIONS.
PostgreSQL also logs errors in its server logs, along with the statement that caused it. That might be useful to bear in mind for debugging errors with tools other than psql that don't report errors very well.