11-21-2012 12:37 AM
I am sorry, I don't know the answer...
What I would try is:
- LaunchExecutable ( "Mysql < USE MY_DATABASE" ); instead of FmtOut (“%S”, “USE MY_DATABASE\r\n”);
or alternatively:
- FakeKeystroke ( VAL_ENTER_VKEY );
11-21-2012 09:38 AM
erdc3,
I'd suggest trying the suggestions to add the USE MY_DATABASE command to the LaunchExecutable call, or to try other methods of sending input to the console.
I'm thinking this might not be the easiest way to work with your database if you intend to do anything more complex than opening it. We do offer a CVI SQL Toolkit that provides commands for working with databases:
http://sine.ni.com/nips/cds/view/p/lang/en/nid/11128
Would it be possible to get a bit more information about what you're trying to do with the MySQL database? That might help us suggest the best approach.
In the meantime though, I'd definitely try adding the commands into the LaunchExecutable command.
11-21-2012 10:29 AM
Thanks Daniel-E for the reply. All I want to do is up load a CSV file to a data base. So all the code I would need to send to MySQL after loging in would be the following:
LOAD DATA INFILE 'c:\file.csv' INTO TABLE 'db.table'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
11-21-2012 10:31 AM
Just out of curiosity: What happens if you try
LaunchExecutable ( "Mysql < USE MY_DATABASE" );
as I suggested earlier?
11-21-2012 10:48 AM
Sorry Wolfgang, I meant to respond to your input. But when I use
LaunchExecutable ( "Mysql < USE MY_DATABASE" );
It just throws back at me its help file list.
11-21-2012 10:58 AM
I don't have a MySQL server running here, so I cannot try it, but I remember that you can execute MySQL statements in a script file.
So may be placing all your SQL commands in that script file may work: LaunchExecutable ( "mysql dbname < script.sql" ); could be that line feeds are interpreted differently if read from the script...?
11-21-2012 11:02 AM
Good call Wolfgang, but that just gives me the help list. For some reason it will only take the following command and respond to it:
LaunchExecutable ("Mysql –h localhost –u me –password=pw");
11-26-2012 07:40 AM
erdc3,
I think it might be helpful to use the LaunchExecutable command in a way that emulates the Windows command line. Here's a page from the CVI Help about the LaunchExecutable command:
http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvilaunchexecutable/
By inserting cmd.exe /c at the front of the string argument in your LaunchExecutable command, it will open cmd.exe (the Windows command line), and run the rest of the argument as an input to the command line.
So I'm looking at some of the documentation for the MySQL command line tool, specifically this page: http://dev.mysql.com/doc/refman/5.5/en/batch-commands.html
It seems like you should be able to use a command similar to the following:
LaunchExecutable("cmd.exe /c mysql -h localhost -u me -password=pw <databaseFile.sql");
where "databaseFile.sql" is the text file containing your commands. The first line of this file might need to be a USE command to tell it which database to use--so if your database is my_database, you'd need to say USE my_database as the first line of your file.
Hopefully that will work for you--let us know!
11-26-2012 02:03 PM
Thanks Daniel-E! that did the job. I can now up load the data from the Labwindows/CVI code and it does not show the logon/password needed to connect to the database.
11-27-2012 09:09 AM
That's great to hear! Good luck with the project, and let us know if you have any more questions!