dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Export MySQL table from C++ Using OUTFILE command

  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    299

    [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

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,411

    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++17 Compiler: Microsoft VS2017 (15.8.4)

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    299

    Re: Export MySQL table from C++ Using OUTFILE command

    Quote Originally Posted by 2kaud View Post
    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.


    Quote Originally Posted by saraswathisrinath View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)