1

次の選択を実行する手順があります。

select distinct concat( 'php /home/rudyerd-systems/frontend/ClientStatementGenerator.php ', left(user(), locate('@',user())-1), space(1), ca.client_id, space(1), date_format( @pTradingPeriodMonth, '%y%m' ), space(1), date_format( @pTradingPeriodMonth, '%y%m' ),
                    ' > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html' )
from   ca_client_account ca,
       ca_tranche tr
where  @pTradingPeriodMonth    between tr.dt_value and ifnull( tr.dt_withdrawal, @pTradingPeriodMonth ) and
       ca.client_account_id   = tr.client_account_id
order  by ca.client_id;

次の結果が生成されます。

| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet ATP 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet BLB 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet CAR 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet CDR 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet CSP 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet DGC 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet FDR 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet FVN 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet JLM 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet JRA 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet JRP 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet MJO 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet MPW 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet NTC 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet RJA 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet RMM 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet SJC 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html                                                                                                          |
| php /home/rudyerd-systems/frontend/ClientStatementGenerator.php scorbet UDB 1205 1205 > /home/rudyerd-systems.sco/frontend/bash/new_statement_test.html 

各変数を含む HTML ページが作成されるように、手順の結果を直接 Linux コマンド ラインに出力したいと考えています。この手順は、HTML ファイルを作成するフォルダー内の bash スクリプトから実行されます。

完全を期すために、これは完全な手順です。

-- ---------------------------------------------------------------------------------
-- pUIGetCliStmtGenList
--
-- This procedure returns the Clients who statements need to be generated for
--
-- ---------------------------------------------------------------------------------

drop procedure if exists pUiGetCliStmtGenList;
delimiter //

create procedure pUiGetCliStmtGenList(
  IN  pTradingPeriodMonth      DATE,
  IN  pUsername                VARCHAR,
  IN  pPassword                VARCHAR,
  OUT pResult                  INT
)
MODIFIES SQL DATA
COMMENT 'Gathers the list of people a statement needs to be created for'
begin
 --
  declare vClient_id           VARCHAR(3);
  declare vAmtTradedSystemCcy  DECIMAL(13,2);
  declare vCount               INT;
  --
  declare EXIT handler for SQLWARNING, SQLEXCEPTION call pRdHandleError( 10000, 'pUiGetCliStmtGenList', vHint );
  --  ***********************************************************************************************************
  set vHint = pTradingPeriodMonth;
  set pResult = 0;

  SELECT DISTINCT CONCAT( 'php /home/rudyerd-systems/frontend/ClientStatementGenerator.php ', left(user(), locate('@',user())-1), space(1), ca.client_id, space(1), date_format( @pTradingPeriod, '%y%m' ), space(1), date_format( @pTradingPeriod, '%y%m' ),
                    ' > /home/rudyerd-systems.sco/frontend/bash/'ca.client_id''@pTradingPeriod'statement.html' )
  FROM   ca_client_account ca,
         ca_tranche tr
  INTO     
  WHERE  @pTradingPeriodMonth    between tr.dt_value and ifnull( tr.dt_withdrawal, @pTradingPeriodMonth ) and
         ca.client_account_id   = tr.client_account_id
  ORDER BY ca.client_id;
  --
  -- If there are no clients
    if vCount <> 0 then
     call pRdHandleError( 1002, 'pUiGetCliStmtGenFlag', vHint );
    end if; 
  --
  --   
  ELSE
  -- Output to Linux Command Line and Generate the HTML pages

  -- Then Convert the pages to pdf
  -- 
  set pResult = 1;
  --
end;
//

delimiter ;
4

2 に答える 2

1

出力ショーが実行可能なスクリプトであることが意図されており、フィールド値の 1 つを出力ファイル名に変更>する>>か追加して、それらが一意になるようにすると仮定すると、これが目的になる可能があります。

mysql -B -u username -p dbname < script.sql | sed 's/|//' | sh

存在する場合、sedコマンドはパイプ文字を削除します。全体をパイプすると、指定された引数で実行さshれる各行が実行phpされ、出力が指定されたファイルにリダイレクトされます。mysqlニーズに合わせて引数を変更する必要がある場合があります。

于 2012-06-05T13:03:47.010 に答える
0

ファイルを作成できるようにサーバーにアクセスできる場合は、次のように出力を CSV ファイルにエクスポートできます。

SELECT field1,field2 FROM table1
INTO OUTFILE '/home/output.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

必要に応じて、パーサーを作成したり、別のスクリプト言語/ツールを使用してエントリを変更したりできます...

于 2012-06-05T11:19:58.010 に答える