Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting data to textfile

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
Is there a command that outputs my data to a text file: i.e. I'm in Interbase Interactive SQL and I run a "select * from resident" and I want to output the result to a file (e.g. resident.txt) - all very easy in Sybase where you simply add "output to c:\resident.txt format text" - but can't finf similar in interbase.

Thanks for any help.

Also - is there a way to upload data from text files back into tables (like the sql loader function in oracle)

thanks - Interbase Newbie

Dan Auber
 
Hi -

You will probably need to use the ISQL.EXE tool that ships with Interbase. Its a command line utility for interacting with Interbase Databases.

Here is an exampke of its use I came across..

...

...IF you're working in Windows ( or DOS... scary! ) here's
a batch file that can create a script:
Include everything between the dashed lines name it
it CREATE_SQL.BAT
------------------------------------------------------
@echo off
rem start bat
if %1.==. goto HELPBAT
if %2.==. goto HELPBAT
echo CONNECT 'C:\PROJECTS\test.GDB' >curr_script.sql
echo USER 'SYSDBA' PASSWORD 'masterkey'; >>curr_script.sql
echo. >>curr_script.sql
echo OUTPUT "%1"; >>curr_script.sql
if %2.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%2"; >>curr_script.sql
if %3.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%3"; >>curr_script.sql
if %4.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%4"; >>curr_script.sql
if %5.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%5"; >>curr_script.sql
if %6.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%6"; >>curr_script.sql
if %7.==. goto ARGSDONE
echo SELECT Select * from table1 where field like "%7"; >>curr_script.sql
:ARGSDONE
echo. >>curr_script.sql
echo COMMIT; >>curr_script.sql
GOTO ENDBAT
:HELPBAT
Echo.
echo Create SQL batch file
echo.
echo creates an interbase script based on command line parameters.
echo.
echo USAGE:
echo create_sql ouputfile field1 [ field2 .. field7 ]
echo

:ENDBAT
-----------------------------------------------------


simply run:

create_sql ouputfile.txt curly larry moe


to create the script:
----------------------------------------------------
CONNECT 'C:\PROJECTS\test.GDB'
USER 'SYSDBA' PASSWORD 'masterkey';

OUTPUT "outputfile.txt";
SELECT Select * from table1 where field like "curly";
SELECT Select * from table1 where field like "larry";
SELECT Select * from table1 where field like "moe";

COMMIT;
----------------------------------------------------

and run it:
isql -i curr_script.sql

note: curr_script.sql gets overwritten on every pass.
IMPORTANT: It looks like word-wrapping may damage the batch file... let me know, and I'll try to email it to you..

IF you are not using Windows, it probably wouldn't be too hard to do this in PHP or something like that.


Not checked out this script myself, but looks fairly comprehensive as you can pass parameters to the script and define output file from command line. Author was someone calling himself vogonPoet (credit where credit due and all.)


Opp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top