Archive: mysql, long paths and quotes


mysql, long paths and quotes
Hi,

first of all I have to thank whoever made NSIS, I think it's awesome!;)

Second I have some questions, my main use for NSIS is deploying a client/server application with a mysql backend.

I can't really understand why sometimes I have to use single or double quotes or no quotes so I hope someone here can enlighten me.

Here's some code from my script :

Section "";

InitPluginsDir
SetOutPath $PLUGINSDIR
File struct.sql

SetOutPath $INSTDIR

;execute mysql commands
GetFullPathName /SHORT $INSTDIRSHORT $INSTDIR
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6 ;get local time
StrCpy $TS "$0-$1-$2-$4-$5-$6"

StrCpy $FULLBACKUP "$INSTDIRSHORT\ecoges-fullbackup-$TS.sql"
StrCpy $DATABACKUP "$INSTDIRSHORT\ecoges-databackup-$TS.sql"
StrCpy $MYSQLDUMP "$INSTDIRSHORT\bin\mysqldump.exe"
StrCpy $MYSQLCLIENT "$INSTDIRSHORT\bin\mysql.exe"
StrCpy $STRUCSCRIPT "$PLUGINSDIR\struct.sql"

nsExec::Exec '"$MYSQLDUMP" -r "$FULLBACKUP" ecoges -uroot -p1234 --complete-insert'
nsExec::Exec '"$MYSQLDUMP" -r "$DATABACKUP" ecoges -uroot -p1234 --no-create-info --complete-insert'

DetailPrint "Réinitialisation de la base de données..."
nsExec::Exec 'cmd /C $MYSQLCLIENT -uroot -p1234 ecoges < $STRUCSCRIPT'

DetailPrint "Récupération des données..."
nsExec::Exec 'cmd /C $MYSQLCLIENT -uroot -p1234 ecoges < "$DATABACKUP"'

SectionEnd ; end the section


Why do I have to remove all quotes with $MYSQLCLIENT and $MYSQLDUMP can work with or without them ?

Why do I have to use double quotes when I restore $DATABACKUP but not when I create it with $MYSQLDUMP ?

My code works but I try to make it as clean as possible. I hope I'm not too hard to understand...

Thanks for your help!

You use quotes around the executable paths in case those paths contain spaces. Lets say $MYSQLCLIENT is C:\Program Files\app.exe without any quotes... cmd will try and execute C:\Program.exe first instead.

Stu


ok, but why is it failing when the mysql client is in C:\mysql\bin\mysql.exe and I use double quotes ? That's the part I don't get...

if
GetFullPathName /SHORT $INSTDIRSHORT $INSTDIR
StrCpy $MYSQLCLIENT "$INSTDIRSHORT\bin\mysql.exe"

$MYSQLCLIENT = c:\mysql\bin\mysql.exe = works fine
$MYSQLCLIENT = c:\program files\mysql\mysql server 5.0\bin\mysql.exe = works fine
"$MYSQLCIENT" = c:\mysql\bin\mysql.exe = fails


That's some cmd.exe quoting fun for you. Add "IF 1==1" (sans quotes) before the path and it should work.


like ?

StrCpy $MYSQL IF 1==1 "$INSTDIR\bin\mysql.exe"

No.

nsExec::Exec 'cmd /C IF 1==1 "$MYSQLCLIENT" -uroot -p1234 ecoges < "$DATABACKUP"'

ok thanks, I'll test that out tomorrow.

can you tell me what that code actually do if it's not too complicated ?

Thanks!


It forces cmd.exe to drop its weird quotes handling. If the first character in the command line is a quote, it'll the strip the first and the last quote thus rendering the command line completely invalid. See cmd.exe /? for more information.


I didn't know that but I will remember it for sure!

Thanks a lot for your time.