-
September 4th, 2018, 05:31 AM
#1
[RESOLVED] Export MySQL table from C++ Using OUTFILE command
Hi,
i like to export Mysql table as a csv file. The below command working good in MySQL command prompt and file stored in D drive.
Code:
SELECT * FROM LOG INTO OUTFILE 'D:\\logreport.csv' FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY "\r\n";
I like to use this command via C++.
Code:
CString sQuery = "SELECT * FROM log INTO OUTFILE 'D:\\logreport.csv' FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY "\r\n"";
Getting missing closing quote Error. So tried like below,
Code:
sQuery = "SELECT * FROM log INTO OUTFILE 'D:\\logreport.csv'";
DB.ExecuteSQL(QueryStr);
DB.ExecuteSQL(FlushStr);
This query also not working. showing empty error message.
Regards,
SaraswathiSrinath
-
September 4th, 2018, 06:02 AM
#2
Re: Export MySQL table from C++ Using OUTFILE command
Try
Code:
CString sQuery = "SELECT * FROM log INTO OUTFILE 'D:\\logreport.csv' FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\"";
ie escape the " so the compiler treats it as an embedded " and not a terminating " of the previous ".
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 4th, 2018, 06:31 AM
#3
Re: Export MySQL table from C++ Using OUTFILE command
Originally Posted by 2kaud
Try
Code:
CString sQuery = "SELECT * FROM log INTO OUTFILE 'D:\\logreport.csv' FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\"";
ie escape the " so the compiler treats it as an embedded " and not a terminating " of the previous ".
Thank you. Working Good.
Originally Posted by saraswathisrinath
Code:
sQuery = "SELECT * FROM log INTO OUTFILE 'D:\\logreport.csv'";
DB.ExecuteSQL(QueryStr);
DB.ExecuteSQL(FlushStr);
This query also not working. showing empty error message.
Sorry. Problem find out in the above case. careless mistake from my side. QueryStr passed ExecuteSQL , but stored quesry in sQuery
Thank you once again.
Regards,
SaraswathiSrinath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|