MySQL:光标似乎永远不会结束

时间:2018-04-28 19:29:27

标签: mysql amazon-rds-aurora database-cursor

我正在使用Aurora / MySQL。我有一个光标,似乎没有完成/完成。

让我感到困惑的是我在网上看过的例子,我从来没有看到过他们已经完成了#34;完成了#34;或者"完成"变量为一。以下是我的剧本。

DELIMITER $$

DROP PROCEDURE IF EXISTS mass_backup $$

CREATE PROCEDURE mass_backup () 
    BEGIN
        DECLARE copy_table VARCHAR(255);
        DECLARE done BOOLEAN DEFAULT 0;
        DECLARE table_cursor CURSOR FOR
            SELECT table_name FROM information_schema.tables WHERE table_schema='app_prod_schema';
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;

        OPEN table_cursor;

        REPEAT
            FETCH table_cursor INTO copy_table;
            SELECT copy_table;
            SET @var1 = copy_table;
            SET @copySql = CONCAT('SELECT * FROM ',@var1,' INTO OUTFILE S3 ''''s3://somebucket.com-work-bucket/''', @var1 , 
                    '.csv', 'FIELDS TERMINATED BY '','' LINES TERMINATED BY ''\n''' );
            SELECT @copySql;
        UNTIL done END REPEAT;
        CLOSE table_cursor;
    END $$

DELIMITER ;

CALL mass_backup()

为什么这个光标想要永远运行?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我认为我在重复循环中使用的SELECT会弄乱“不再行”处理程序。我删除了REPEAT并进行了循环。这看起来像是一种魅力,给了我期待的陈述。

send_sample_form() {

  let d = new Date();
  d.setTime(d.getTime() + 1 * 24 * 60 * 60 * 1000);
  let expires:string = "expires=" + d.toUTCString();
  let cpath:string = '/';
  // this.cookieService.set('csrftoken', this.server_token, d, cpath, '127.0.0.1', false);
  this.cookieService.set('csrftoken', this.server_token);
  let my_headers = new HttpHeaders(
    {
      'X-CSRFToken': this.server_token
    }
  );
  this.http.post('http://127.0.0.1:8000/emptyform/',
        {'my_form': this.sample_form.value},
        {headers: this.server_token, withCredentials: true})
        .subscribe(
          (response) => {
            console.log(response);
          }
        );
}