Supported features
==================

Multiassign
-----------
* ANSI SQL 
    SET (variable list) = (expression list)

* DB2, MySQL
    SET variable1 = expression1, variable2 = expression2, ...

Cursor processing
-----------------
* ANSI SQL (via continue not found handler)

BEGIN
  DECLARE x integer;
  DECLARE done boolena DEFAULT false;
  DECLARE c CURSOR FOR SELECT * FROM tab;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;
  OPEN c;
  FETCH c INTO x;
  WHILE NOT done DO
    PRINT x;
    FETCH c INTO x;
  END WHILE;
END;

* DB2 (via magic SQLCODE or SQLSTATE variables)

BEGIN
  DECLARE x integer;
  DECLARE SQLCODE integer;
  DECLARE x CURSOR FOR SELECT * FROM tab;
  OPEN c;
  FETCH c INTO x;
  WHILE SQLCODE = 0 DO
    PRINT x;
    FETCH c INTO x;
  END WHILE;
END;

FOR statement
-------------
BEGIN
  FOR SELECT * FROM tab DO
    PRINT a, b, c;
  END FOR;
END;

BEGIN
  FOR fn SELECT * FROM tab DO
    PRINT fn.a, fn.b, fn.c;
  END FOR;
END;

Empty statement
---------------
BEGIN
END;

FOR SELECT * FROM tab DO
END FOR;

Signals
-------
SIGNAL SQLSTATE '22000';

SIGNAL SQLSTATE '55001' SET message_text = 'Custom message';

RESIGNAL

* There is PostgreSQL extension - a expressions can be used in signal info list.

Conditions
----------
BEGIN
  DECLARE custom_condition CONDITION FOR SQLSTATE '02001';
  DECLARE CONTINUE HANDLER FOR custom_condition PRINT 'Detected condition';
  SIGNAL custom_condition;
END;

Note: Default SQLSTATE for conditions is 45000 (like DB2)

Diagnostics statement
---------------------
       GET STACKED DIAGNOSTICS
          message = MESSAGE_TEXT,
          detail = DETAIL_TEXT,
          hint = HINT_TEXT,
          _sqlstate = RETURNED_SQLSTATE,
          _sqlcode = RETURNED_SQLCODE,
          _condition_name = CONDITION_IDENTIFIER;

Known limits
============
* UNDO handlers should be used only inside ATOMIC compound statements.

* ERRORS and signals with ERROR level should be handled by UNDO handlers only.

* You cannot use a cursors from outer compound statement inside UNDO handlers.
  Cursors are closed when UNDO handler is executed.
