当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - Passing commands in Inno Setup exec function into pgsql database

问题描述:

I'm running the following code trying to create users in my PostgreSQL database from a file which my Inno Setup script reads. Unfortunately the only commands which execute are the SET PGPPASSWORD and -U postgres elt commands which connect me to the database. The other commands which I need to run inside the database are ignored and I cannot seem to find a way to input them into the database. Is there characters I can use to input the commands into the PostgreSQL database?

ExecAsOriginalUser('cmd.exe', '/k ' +'"SET PGPASSWORD=postgres&"' +

InstallPath+ '\psql -U postgres elt -c '+ 'CREATE USER '

+ Users[UserCount - 1] + ' WITH PASSWORD ' + ''''

+ Password + '''' + '& ' + '\g', '', SW_SHOW, ewWaitUntilIdle, ResultCode);

Command Line Output:

psql: warning: extra command-line argument "-c" ignored

"": extra command-line argument "CREATE" ignored

"": warning: extra command-line argument "USER" ignored

"": extra command-line argument "postgres" ignored

"": extra command-line argument "WITH" ignored

"": extra command-line argument "PASSWORD" ignored

"": extra command-line argument "'postgres'\g" ignorepsql

(9.5.3) WARNING: Console code page (437) differs from

Windows code page

(1252) 8-bit characters might not work correctly. See psql reference page

"Notes for Windows users" for details.

Type "help" for help.

db=#

网友答案:

You probably just need to wrap the SQL to double quotes:

ExecAsOriginalUser('cmd.exe',
    '/c SET PGPASSWORD=postgres& '
    + InstallPath + '\psql -U postgres elt -c "CREATE USER ' 
    + Users[UserCount - 1] + ' WITH PASSWORD ''' + Password + '''"',
    '', SW_SHOW, ewWaitUntilIdle, ResultCode);

First verify it by running this on a command-line:

cmd.exe /c SET PGPASSWORD=postgres& C:\eltfiles\pgsql\bin\psql -U postgres elt -c "CREATE USER postgres WITH PASSWORD 'postgres'"
分享给朋友:
您可能感兴趣的文章:
随机阅读: