Archive: SQL statement


SQL statement
  I need to execute a .SQL file and have it edit the database SAM in mysql.

Here is my .nsi code to try to execute them:

;Output File Name

OutFile "sfox.exe"

>;The Default Installation Directory
InstallDir "C:\Documents and Settings\Hess Smith\Desktop\SAM"

>!include "MUI.nsh"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

>Section ""
>SetOutPath $INSTDIR
>;Put all of the .SQL files into a temp directory
File "C:\Documents and Settings\Hess Smith\Desktop\SFR\installer\sam2\installer files\sql\tables.sql"

>;SQL Execute 1
nsExec::ExecToStack 'cmd /C "C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe" -uroot -pstrege -hlocalhost -P3306 < "$INSTDIR\tables.sql"'

>;SQL Execute 1
Exec '"C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe" -uroot -pstrege -hlocalhost -P3306 < "$INSTDIR\tables.sql"'
>SectionEnd
>
Here is my tables.sql file that it downloads and executes.


# Generation Time: Dec 07, 2002 at 10:54 PM

# Server version: 3.23.52
# PHP Version: 4.2.3
# Database : `SAMDB`
# --------------------------------------------------------

#
# Table structure for table `category`
#
>use sam;
>CREATE TABLE category (
ID mediumint(9) NOT NULL auto_increment,
name varchar(100) NOT NULL default '',
parentID mediumint(9) NOT NULL default '0',
levelindex tinyint(4) NOT NULL default '0',
itemindex mediumint(9) NOT NULL default '0',
PRIMARY KEY (ID),
UNIQUE KEY name (name)
)TYPE=MyISAM;
It pops up a command prompt and it appears that it is doing something, but it is moving so fast i can't read it. Then it exits. But it isnt affecting the database.

Does anybody have any ideas?? :igor:

Use nsExec::ExecToLog and you'll get the output of your command-line program in the installation log window.

-Stu


what do u mean by that?


Instead of using nsExec::ExecToStack, use nsExec::ExecToLog!!!

-Stu


Use "pause" in your Batch File
  Write "pause" in your Batch File at the End to prevent auto-closing of the DOS Window.


i haven't created a batch file. Is that the problem? How would I go about doing this?


That can be a problem sometimes. Some command-line programs only work in a DOS environment (i.e. do not work under nsExec)

Rather than creating a batch, just do:

ReadEnvStr $R0 COMSPEC
nsExec::Exec "'$R0' /c '...'"

-Stu


ReadEnvStr $R0 COMSPEC

nsExec
::Exec "'$R0' /c '...'"
I'm sorry, but where would I go about using that code? Im guessing that the path to my .sql file goes in place of the '...'. But what is all of the other stuff?

Give this a try


Output File Name

OutFile "sfox.exe"

>;The Default Installation Directory
InstallDir "C:Documents and SettingsHess SmithDesktopSAM"

>!include "MUI.nsh"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

>Section ""
>SetOutPath $INSTDIR
>;Put all of the .SQL files into a temp directory
File "C:Documents and SettingsHess SmithDesktopSFRinstallersam2installer filessql\tables.sql"

>;SQL Execute 1
>;nsExec::ExecToStack 'cmd /C "C:Program FilesMySQLMySQL Server 4.1binmysql.exe" -uroot -pstrege -hlocalhost -P3306 < "$INSTDIR\tables.sql"'
>;Instead of the line you have above, try this:
;
ComSpec: Stores the path and file name of the Windows 2000 command interpreter, Cmd.exe. The command interpreter is analogous to MS-DOS Command.com
>;Get value in a variable:
>ReadEnvStr $R0 COMSPEC

>;Use cmd /K instead of /C to leave the window open to view its output
>;C:>cmd /?
;/C Carries out the command specified by string and then terminates
>;/K Carries out the command specified by string but remains
nsExec::ExecToLog ''$R0' /K "C:Program FilesMySQLMySQL Server 4.1binmysql.exe" -uroot -pstrege -hlocalhost -P3306 < "$INSTDIR\tables.sql"'

>;SQL Execute 1
Exec '"C:Program FilesMySQLMySQL Server 4.1binmysql.exe" -uroot -pstrege -hlocalhost -P3306 < "$INSTDIR\tables.sql"'
>SectionEnd
>