Ejemplo n.º 1
0
  public override DataType TypeCheck( SqlExec e )
  {
    DataType tL = Left.TypeCheck( e );
    DataType tR = Right.TypeCheck( e );

    if ( tL == DataType.Bigint && tR == DataType.Double )
    {
      Left = new IntToDoubleExp(Left);
      tL = DataType.Double;
    }
    else if ( tR == DataType.Bigint && tL == DataType.Double )
    {
      Right = new IntToDoubleExp(Right);
      tR = DataType.Double;
    }
    else if ( Operator != Token.VBar && ( tL >= DataType.Decimal || tR >= DataType.Decimal ) )
    {
      if ( tR == DataType.Bigint ) tR = DTI.Decimal(18,0);
      else if ( tL == DataType.Bigint ) tL = DTI.Decimal(18,0);
      else if ( tR == DataType.Float ) { Right = Right.Convert( tL ); tR = tL; }
      else if ( tL == DataType.Float ) { Left = Left.Convert( tR ); tL = tR; }

      int sL = DTI.Scale(tL);
      int sR = DTI.Scale(tR);

      if ( sL < 0 || sR < 0 ) e.Error( "Type error involving decimal" );

      switch( Operator )
      {
        case Token.Divide: tL = DTI.Decimal( 18, sL - sR ); break;
        case Token.Times:  tL = DTI.Decimal( 18, sL + sR );  break;
        case Token.Percent: break; 
        default: 
          if ( sL > sR ) { Right = new ExpScale( Right, tL, sL - sR ); tR = tL; }
          else if ( sL < sR ) { Left = new ExpScale( Left, tR, sR - sL ); tL = tR; }
          break;
      }
      tR = tL;
    }    
    if ( tL == tR )
    {
      if ( Operator <= Token.NotEqual ) 
        Type = DataType.Bool;
      else 
      {
        Type = tL;
        if ( !TokenInfo.OperatorValid( Operator, tL ) ) 
          e.Error ( "Type error " + TokenInfo.Name(Operator) + " not valid for type " + DTI.Name(tL) );
      }
    }
    else if ( tL == DataType.String && Operator == Token.VBar )
    {
      Type = DataType.String;
      Right = Right.Convert( DataType.String );
    }
    else e.Error( "Binary operator datatype error");
    return Type;
  }
Ejemplo n.º 2
0
 public override DataType Bind( SqlExec e )
 {
   for ( int i = 0; i < List.Length; i += 1 ) 
   {
     Exp test = List[i].Test;
     if ( test != null && test.Bind( e )!= DataType.Bool ) e.Error( "Case test must be Bool" );
     DataType dt = List[i].E.Bind( e );
     if ( i == 0 ) Type = dt;
     else if ( dt != Type ) e.Error( "Case expressions must all have same type" );
   } 
   return Type;
 }
Ejemplo n.º 3
0
 public override DataType TypeCheck( SqlExec e )
 {
   if ( B.Params.Count != Plist.Length ) e.Error( "Param count error calling function " + FuncName );
   for ( int i = 0; i < Plist.Length; i += 1 )
     if ( Plist[i].Type != B.Params.Types[i] )
     {
       Exp conv = Plist[i].Convert( B.Params.Types[i] );
       if ( conv != null ) Plist[i] = conv;
       else e.Error( "Parameter Type Error calling function " + FuncName 
          + " required type=" + DTI.Name( B.Params.Types[i] ) 
          + " supplied type=" + DTI.Name( Plist[i].Type ) + " exp=" + Plist[i] );
     }
   return Type;
 }
Ejemplo n.º 4
0
  public override void Bind( SqlExec e )
  {
    var ci = e.CI;
    if ( ci == null ) e.Error( "Undeclared variable " + ColName );
    for ( int i=0; i < ci.Count; i += 1 ) 
      if ( ci.Name[ i ] == ColName ) 
      { 
        e.Used[ i ] = true;
        ColIx = i; 
        Type = DTI.Base( ci.Type[ i ] );
        return;
      }

    e.Error( "Column " + ColName + " not found" );
  }
Ejemplo n.º 5
0
 public override void Bind( SqlExec e )
 {
   for ( int i = 0; i < List.Length; i += 1 ) 
   {
     if ( List[ i ].Test != null )
     {
       List[ i ].Test.Bind( e );
       if ( List[ i ].Test.Type != DataType.Bool ) e.Error( "Case test must be Bool" );
     }
     List[ i ].E.Bind( e );
     DataType dt = List[ i ].E.Type;
     if ( i == 0 ) Type = dt;
     else if ( dt != Type ) e.Error( "Case expressions must all have same type" );
   } 
 }
Ejemplo n.º 6
0
 public override DataType Bind( SqlExec e )
 {
   Type = E.Bind( e );
   if ( Type != DataType.Bigint && Type != DataType.Double && Type < DataType.Decimal )
     e.Error( "Unary minus needs numeric argument" );
   return Type;
 }
Ejemplo n.º 7
0
 public override DataType Bind( SqlExec e )
 {
   Lhs.Bind( e );
   Rhs.Bind( e );
   if ( Lhs.Type != Rhs.GetElementType() ) e.Error( "IN type mismatch" );
   return Type;
 }
Ejemplo n.º 8
0
 public override void Bind( SqlExec e )
 {
   E.Bind( e );
   Type = E.Type;
   if ( Type != DataType.Bigint && Type != DataType.Double && Type < DataType.Decimal )
     e.Error( "Unary minus needs numeric argument" );
 }
 public void CheckLabelsDefined(SqlExec e)
 {
     if (JumpUndefined != 0)
     {
         e.Error("Undefined Goto Label");
     }
 }
Ejemplo n.º 10
0
 public override void Bind(SqlExec e)
 {
     E.Bind(e);
     SType = E.Type;
     if (SType != DataType.String && SType != DataType.Binary)
     {
         e.Error("LEN argument must be string or binary");
     }
 }
Ejemplo n.º 11
0
  public override void Bind( SqlExec e  )
  {
    B = e.Db.GetRoutine( Schema, FuncName, true, e );
    Type = B.ReturnType;

    e.Bind( Plist );

    if ( B.Params.Count != Plist.Length ) e.Error( "Param count error calling function " + FuncName );
    for ( int i = 0; i < Plist.Length; i += 1 )
      if ( Plist[ i ].Type != B.Params.Type[ i ] )
      {
        Exp conv = Plist[ i ].Convert( B.Params.Type[ i ] );
        if ( conv != null ) Plist[ i ] = conv;
        else e.Error( "Parameter Type Error calling function " + FuncName 
           + " required type=" + DTI.Name( B.Params.Type[ i ] ) 
           + " supplied type=" + DTI.Name( Plist[ i ].Type ) + " exp=" + Plist[ i ] );
      }
  }
Ejemplo n.º 12
0
  public override DataType Bind( SqlExec e )
  {
    var ci = e.CI;
    if ( ci == null ) e.Error( "Undeclared variable " + ColName );
    for ( int i=0; i < ci.Count; i += 1 ) 
      if ( ci.Names[i] == ColName ) 
      { 
        e.Used[ i ] = true;
        ColIx = i; 
        Type = DTI.Base( ci.Types[i] );
        return Type;
      }

    // for ( int i=0; i < ci.Length; i += 1 ) System.Console.WriteLine( ci[i].Name );
    
    e.Error( "Column " + ColName + " not found" );
    return Type;
  }
 public override DataType Bind(SqlExec e)
 {
     SType = E.Bind(e);
     if (SType != DataType.String && SType != DataType.Binary)
     {
         e.Error("LEN argument must be string or binary");
     }
     return(Type);
 }
Ejemplo n.º 14
0
 public override DataType Bind( SqlExec e  )
 {
   for ( int i = 0; i < List.Length; i += 1 ) 
   {
     DataType dt = List[i].Bind( e );
     if ( i == 0 ) ElementType = dt;
     else if ( dt != ElementType ) e.Error( "Tuple type error" ); // Maybe should apply Exp.Convert if possible.
   } 
   return Type;
 }
Ejemplo n.º 15
0
 public override void Bind( SqlExec e  )
 {
   for ( int i = 0; i < List.Length; i += 1 ) 
   {
     List[ i ].Bind( e );
     DataType dt = List[ i ].Type;
     if ( i == 0 ) Type = dt;
     else if ( dt != Type ) e.Error( "Tuple type error" ); // Maybe should apply Exp.Convert if possible.
   } 
   Dvs = Util.GetDVList( List );
 }
Ejemplo n.º 16
0
 public override void Bind(SqlExec e)
 {
     for (int i = 0; i < Types.Length; i += 1)
     {
         Arg[i].Bind(e);
         DataType t = Arg[i].Type;
         if (t != Types[i])
         {
             e.Error(this + " parameter type error, arg " + i + " expected "
                     + DTI.Name(Types[i]) + " actual " + DTI.Name(t));
         }
     }
 }
Ejemplo n.º 17
0
 public override DataType Bind( SqlExec e )
 { 
   e.Error( "Aggregate can only be a top level SELECT" );
   return DataType.None;
 }
Ejemplo n.º 18
0
 public ExpAgg( AggOp op, G.List<Exp> arg, SqlExec e ) 
 { 
   Op = op; 
   if ( arg.Count != 1 ) e.Error( Op + " takes one parameter" );
   E = arg[0]; 
 }
Ejemplo n.º 19
0
 public override void Bind( SqlExec e )
 {
   E.Bind( e );
   if ( E.Type != DataType.Bool ) e.Error( "NOT needs bool argument" );
 }
Ejemplo n.º 20
0
 public override void Bind( SqlExec e )
 {
   Lhs.Bind( e );
   Rhs.Bind( e );
   if ( Lhs.Type != Rhs.Type ) e.Error( "IN type mismatch" );
 }
Ejemplo n.º 21
0
 public override DataType Bind( SqlExec e )
 {
   if ( E.Bind( e ) != DataType.Bool )
     e.Error( "NOT needs bool argument" );
   return Type;
 }
Ejemplo n.º 22
0
 public override void Bind( SqlExec e )
 { 
   e.Error( "Aggregate can only be a top level SELECT" );
 }