Skip to content
⌘ NSIS Forum Archive

mysql query and return value reaction

4 posts

Mosestycoon#

mysql query and return value reaction

Dear Friends:

I started creating a plug-in to my application. It should install a webapplication into the local webspace. Like most webapplications this is based on PHP and MySQL.

The webapplication should use its own database user, so I need to get the credentials for the root user (user with global rights on the database) and use this informations to create the new database and a new user with password.

To solve this problem, I created a CustomPage where all these values must be filled by the user. I get all values back and pipe them into the following lines:

  nsExec::Exec '$INSTDIR\DB\MySQL4\bin\mysql -u $R0 -proot -e "CREATE DATABASE $R2"' 
with $R0 = root username
and $R2 = name of the database

As you can see in this line, -proot symbolises the parameter -p (switch for password entry) and a symbolic password root. And her I have my first problem:

If a user has no password set for his root user, neither the password nor the switch -p must be set. The CustomPage (custom.ini) is already prepared to serve a variable $R1 which could be placed as -p$R1, but mysql would react with an error if you trigger it with -p and provide no password. So I think the -p must be copied into $R0. How can I achieve this?

And another question. If the user enters a wrong password mysql will return an error. Can this error be used (or captured) to return e.g. a MessageBox and switch back to the CustomPage again...?

I hope somebody has a solution for me.

Chris
Mosestycoon#edited
Ok meantime I solved problem one, to differ between an existing and a non-existent password with the following code:
  ;  -----  ask for MySQL root credentials
  ;         field 2=root user
  ReadINIStr $R0 "$PLUGINSDIR\\mysql.ini" "Field 2" "State"
  ;         field 3=password for root user
  ReadINIStr $R1 "$PLUGINSDIR\\mysql.ini" "Field 3" "State"
  ;  -----  ask for creating a new MySQL User
  ;         field 11=database
  ReadINIStr $R2 "$PLUGINSDIR\\mysql.ini" "Field 11" "State"
  ;  -----  field 12=new database user
  ReadINIStr $R3 "$PLUGINSDIR\\mysql.ini" "Field 12" "State"
  ;  -----  field 13=password for new database user
  ReadINIStr $R4 "$PLUGINSDIR\\mysql.ini" "Field 13" "State" 
  ;  -----  use the informations above to create the database 
  StrCmp $R1 "" EmptyPwd notEmptyPwd
  EmptyPwd:
  
  ;  -----  if no password is given
  ;
  nsExec::ExecToLog '$INSTDIR\\DB\\MySQL4\\bin\\mysql -u $R0 -e "CREATE DATABASE $R2"'
  nsExec::ExecToLog '$INSTDIR\\DB\\MySQL4\\bin\\mysql -u $R0 -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, ALTER, CREATE TEMPORARY TABLES ON $R2.* TO $\\'$R3$\\'@$\\'localhost$\\' IDENTIFIED BY $\\'$R4$\\'"'
  
  goto PwdDone
  notEmptyPwd:
  ;  -----  if the passwd field is filled...
  ;
  nsExec::ExecToLog '$INSTDIR\\DB\\MySQL4\\bin\\mysql -u $R0 -p$R1 -e "CREATE DATABASE $R2"'
  nsExec::ExecToLog '$INSTDIR\\DB\\MySQL4\\bin\\mysql -u $R0 -p$R1 -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, ALTER, CREATE TEMPORARY TABLES ON $R2.* TO $\\'$R3$\\'@$\\'localhost$\\' IDENTIFIED BY $\\'$R4$\\'"'
  
  PwdDone: 
But there is still the problem, that the installer will finish even if the mysql database returns an error.

Any idea to solve this?
Chris
Takhir#
What about mysql stdout parsing?
nsExec:
if (log & 2) pushstring(szUnusedBuf);
if (log & 1 && *szUnusedBuf) LogMessage(szUnusedBuf);
pushstring(szRet);

And BTW it is possible to prepare and use stdin string for DOS processes http://forums.winamp.com/showthread....ght=dos+plugin
Mosestycoon#
Thx for your reply Takhir -

How do I use this? After the part I posted, there has to be this "see what mysql gives back" part. but I am a non-programmer living from snippets and manuals to achieve my goals ;-)

Thx
Chris