TypeCobol icon indicating copy to clipboard operation
TypeCobol copied to clipboard

Execute Immediate

Open laabidiHend opened this issue 2 years ago • 2 comments

Description

The Execute immediate combines the basic functions of the PREPARE and EXECUTE statements. It can be used to prepare and execute an SQL statement that contains neither host variables nor parameter markers. This implies:

To write the ANTLR grammar To write the CUP grammar Building the Execute immediate Statement CodeElement Building the Execute immediate Node Creating the corresponding Sql Object Making corresponding CodeElement, Node and SqlObject classes visitable Write test unit

laabidiHend avatar Jul 04 '22 12:07 laabidiHend

For ANTLR

sqlVariable: hostVariable;
sqlConstant: SQL_DecimalFloatingPointLiteral | SQL_BinaryStringLiteral | SQL_GraphicStringLiteral | AlphanumericLiteral | HexadecimalAlphanumericLiteral | IntegerLiteral | DecimalLiteral | FloatingPointLiteral | datetime_constant;
sqlExpression: sqlVarible | column_name | sqlConstant ;
executeImmediateStatement : SQL_EXECUTE SQL_IMMEDIATE (sqlVariable | ( SQL_QUOTE sqlExpression SQL_QUOTE);
public class ExecuteImmediateStatement : SqlStatementElement 
{
           public SqlExpression Expression { get; }
	   public SqlVariable sqlVariable { get; }
	   public ExecuteImmediateStatement(SqlExpression Expression, SqlVariable sqlVariable) : base(CodeElementType.ExecuteImmediateStatement, StatementType.ExecuteImmediateStatement)
	   {
		 Expression=expression;
		 SqlVariable=sqlVariable;
	   }	
}

I think we should add in TokenType SQL_QUOTE to define a quote in sql.

laabidiHend avatar Jul 06 '22 13:07 laabidiHend

  • SQL_QUOTE does not make sense as we already have AlhanumericLiteral which includes the quotes or double-quotes
  • The grammar can be simplified because sqlExpression contains sqlVariable
  • 2 options:
    • executeImmediateStatement : SQL_EXECUTE SQL_IMMEDIATE sqlExpression; and we check in code that expression is either a variable or a string literal (with a TODO explaining that we need to add support for string expressions)
    • executeImmediateStatement : SQL_EXECUTE SQL_IMMEDIATE (sqlVariable | AlphanumericLiteral); which restricts the possibilities directly in grammar

fm-117 avatar Jul 07 '22 08:07 fm-117