Hi All,
I have tried to create a file by this query,
mysql>select user_id from user into outfile '/home/1234.txt';
Successfully created file.But i have to add header and footer for the same file.
I could'nt create a file in mysql.I have to create file with header,data and footer.these are,
header -> framed during data insert into the file
data -> selected from the table
footer -> framed by number of rows inserted in file
Please suggest me to create file in mysql.Its very urgent.
Thanks in advance,
Deepa
Open file in append mode mysql procedureSave the header,data and footer information in file save in server
Page 1 of 1
6 Replies - 4318 Views - Last Post: 25 May 2010 - 06:32 AM
Replies To: Open file in append mode mysql procedure
#2
Re: Open file in append mode mysql procedure
Posted 19 May 2010 - 02:06 AM
Deepa,
Do you want to add table column headers ?
---SELECT "FIELD NAMES BEGIN:","docnum","custnum","docdate","FIELD NAMES END:
",T1.docnum, T2.ship_to, concat(right(T2.PGI_Date,2),mid(T2.PGI_Date,6,2),left(T2.PGI_Date,4)), SUBSTRING_INDEX(T1.File_Path,'\\',-1)
Into outfile 'C:\\Output.txt'
FIELDS TERMINATED BY '\r\n'
OPTIONALLY ENCLOSED BY ''
ESCAPED By ''
LINES TERMINATED BY '\r\n0\r\n0\r\n'
from ehimport T1, bocimport T2
WHERE T1.docnum=lpad(T2.docnum,10,'0') AND T1.Used='N'
Do you want to add header/footer using VB6 ?
----If the output of MySQL is an ASCII file, simple file handling program will let you open the file, add header and footer. For e.g.
1) Open the file in append mode (if you want to re-write the file open in input mode)
2) Get the data contents and store in a string variable
3) Get the header text string with a VbCrLf (this will put all the table data from file to next line).
4) Append the data contents to the header text string
5) Append the footer text string to the above string variable.
6) Rewrite the file either by clearing all the previous table data or by opening it in output mode(close the previous opened file first!! )
7)Close the file
Hope it helps.
Good Luck.
Do you want to add table column headers ?
---SELECT "FIELD NAMES BEGIN:","docnum","custnum","docdate","FIELD NAMES END:
",T1.docnum, T2.ship_to, concat(right(T2.PGI_Date,2),mid(T2.PGI_Date,6,2),left(T2.PGI_Date,4)), SUBSTRING_INDEX(T1.File_Path,'\\',-1)
Into outfile 'C:\\Output.txt'
FIELDS TERMINATED BY '\r\n'
OPTIONALLY ENCLOSED BY ''
ESCAPED By ''
LINES TERMINATED BY '\r\n0\r\n0\r\n'
from ehimport T1, bocimport T2
WHERE T1.docnum=lpad(T2.docnum,10,'0') AND T1.Used='N'
Do you want to add header/footer using VB6 ?
----If the output of MySQL is an ASCII file, simple file handling program will let you open the file, add header and footer. For e.g.
1) Open the file in append mode (if you want to re-write the file open in input mode)
2) Get the data contents and store in a string variable
3) Get the header text string with a VbCrLf (this will put all the table data from file to next line).
4) Append the data contents to the header text string
5) Append the footer text string to the above string variable.
6) Rewrite the file either by clearing all the previous table data or by opening it in output mode(close the previous opened file first!! )
7)Close the file
Hope it helps.
Good Luck.
#3
Re: Open file in append mode mysql procedure
Posted 19 May 2010 - 05:56 AM
Thanks for the reply,
Iam tring through the VB to save the file in "Server system".So i used that query.But i could'nt apply header to same file,where header contain data and time of file creation and version number.
- Deepa
Iam tring through the VB to save the file in "Server system".So i used that query.But i could'nt apply header to same file,where header contain data and time of file creation and version number.
- Deepa
#4
Re: Open file in append mode mysql procedure
Posted 19 May 2010 - 09:50 AM
Deepa,
Haven't you used file handling in VB before ?
Anyways, I am giving a sample code.
Modify the above code according to your needs.
Also, some efforts on behalf of you will be more appreciated.
Hope this helps. I have not tested the above code. Let me no if it solves your problem.
Good Luck.
Haven't you used file handling in VB before ?
Anyways, I am giving a sample code.
Dim OriginalData As String,HeaderText As String, FooterText As String
HeaderText="Something"
FooterText="Something"
Open "1234.txt" For Input As #1 ' Replace 1234.txt with complete file path.
OriginalData=Input$(LOF(1),#1) 'reads entire content into string variable
Close #1
'Reopen the file for writing. This will erase all the previous content !!
Open "1234.txt" For Output As #1 ' Replace 1234.txt with complete file path.
Print #1, HeaderText
Print #1, OriginalData
Print #1, FooterText
Close #1
Modify the above code according to your needs.
Also, some efforts on behalf of you will be more appreciated.
Hope this helps. I have not tested the above code. Let me no if it solves your problem.
Good Luck.
This post has been edited by bytelogik: 19 May 2010 - 09:52 AM
#5
Re: Open file in append mode mysql procedure
Posted 19 May 2010 - 10:08 PM
Hi,
I want to save the file in remote system(linux) not in local where application is running.Please can you tell me how to give the path for saving the file in server??
-Deepa
I want to save the file in remote system(linux) not in local where application is running.Please can you tell me how to give the path for saving the file in server??
-Deepa
#6
Re: Open file in append mode mysql procedure
Posted 19 May 2010 - 11:08 PM
More than likely, if you do not have the drive mapped, it will be in unc format \\servername\sharedfoldername\filename.extension, of which you can find out by using your windows explorer and going to network neighborhood to navigate to the share. Now, look up in the combo box at the top and you will see the path that you will need to copy, or you can use the common dialog control to get it for you...
Good Luck
Good Luck
#7
Re: Open file in append mode mysql procedure
Posted 25 May 2010 - 06:32 AM
Thanks a lot for your reply.It helps me to find out way what i desired.Successfully completed file transafer by "psftp" using VB.
Thanks again.Keep doing good work.
-Deepa
Thanks again.Keep doing good work.
-Deepa
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|