-1

I just need to code a short command line program to run a SELECT and convert the result to CSV, so am open to any free IDE/Compiler solution for Windows 10.

I tried MS Visual Studio and the official Mysql connector, but from the menu Tools/Connect to database, I only see options for MS & Oracle, nothing for MySql.

So, I guess I am looking for something else?


[Update] Look, guys, I do appreciate that you are trying to help, but please, no more answers with stored procedures or the like.

I must be able to connect to a MySql database and execute arbitrary commands (plus a whole lot more non-Mysql functionality) from C++.

Please also note, that I do not want to drive Mysql through the c shell(), popen() or similar function, as if from the command line. I need to use a database connector from C++.

Can we please stick with recommending an IDE which will make that easy? Thanks.

0

I think the Eclipse IDE has a MySQL connector. Here is an explanation on how to install it in Eclipse.

Eclipse also supports C/C++ software development - with the Eclipse CDT (C/C++ Development Toolkit), and is one of the most prominent free software IDEs. It's not perfect - and certainly not as polished for C/C++ use as it is for Java - but I use it extensively. You can absolutely use it to write command-line applications, specifically ones which send queries to DBMSes and write CSV output.

The only unknown is whether the MySQL connector for Eclipse can interact, or even coexist, with CDT. That you'll have to check for yourself since I don't use MySQL nor its connector with Eclipse.

I will add, though, that even without the connector component, you should still not have a problem writing your program using Eclipse as an IDE.

  • Alas, the referenced article is for Java, and not for C/C++. This should have been a comment, not an answer. – Mawg Jan 2 '17 at 18:20
  • @Mawg: See my edit (the last paragraph). If you're 100% sure the connector can't be somehow accessed when doing C/C++ development, I'll remove that part of the answer entirely. – einpoklum Jan 2 '17 at 19:37
  • Sorry, but this is a weekend project, and I have literally no free time midweek (5 hours total commute). I will get back to it on Saturday. Feel free to expand on your last sentence :-) even if it is just a URL of some code that I can copy (+1) – Mawg Jan 2 '17 at 21:15
  • 1
    Half a year has passed. – einpoklum Aug 12 '17 at 15:17
  • 1
    Your answer gives a perfectly acceptable solution for Java. Were it for C or C++, I would have accepted it. Therefore, I consider my question not to be unreasonable. I find your statement that I am "living in a fantasy world" to be bordering on offensive, so let us not continue this discussion. – Mawg Aug 13 '17 at 16:31
0
SELECT 
    orderNumber, status, orderDate, requiredDate, comments
FROM
    orders
WHERE
    status = 'Cancelled' 
INTO OUTFILE 'C:/tmp/cancelled_orders.csv' 
FIELDS ENCLOSED BY '"' 
TERMINATED BY ';' 
ESCAPED BY '"' 
LINES TERMINATED BY '\r\n';

Done, no IDE, no compiling.

Command line save above into blah.txt

The 2 p's together are intentional so you can enter the password from the command line also.

mysql -u root -ppassword databaseName

  • A very nice try! But, alas, it must be C/C++ and we will release only a single executable – Mawg Jan 4 '17 at 20:46
0

How about built-in stored procedure:

http://blog.secaserver.com/2014/10/mysql-export-table-split-csv-stored-procedure/

https://stackoverflow.com/questions/11039324/stored-procedure-that-exports-data-into-csv-files-only-exports-to-one-file

Ripped from above stack overflow:

DECLARE 
   @StartDT DATE, 
   @TableName NVARCHAR(50), 
   @FileLocation VARCHAR(255);

SET @TableName = N'ViewAccountDetail';

SELECT @StartDT = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', MIN(dos)), '19000101')
   FROM dbo.accn_demographics;

   PRINT @StartDT;
-- ^^^^^ debugging 101 - what month do we think we're starting at?

WHILE @StartDT < '20110901'
BEGIN
    SET @FileLocation = 'C:\test\' + @TableName
      + CONVERT(CHAR(10), @StartDT, 120) + '.csv';

      PRINT @FileLocation;
    --^^^^^ again, debugging 101 - what does the filename currently look like?

    --EXEC BCP_Text_File @TableName, @FileLocation    
    SET @StartDT = DATEADD(MONTH, 1, @StartDT);
END

No compiling,no IDE, and now with no external files per user request.

  • And, how, exactly, am I to invoke that from C++? – Mawg Jan 5 '17 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.