Example #1
0
 internal void RaiseValueChanged(StoreType st)
 {
     if (OnValueChanged != null)
     {
         OnValueChanged(st);
     }
 }
Example #2
0
 /// <summary>
 /// Generates a value suitable to be concat in a SQL query with mysql concat function.
 /// Doesn't take into account the actual value, just the type.
 /// </summary>
 /// <returns></returns>
 internal string WrapSqlValue()
 {
     if (StoreType.IsString(Type) || StoreType.IsDateTime(Type))
     {
         return(string.Format(" if( {0} is null, 'NULL', concat( '''', {0}, '''' ))", Name));
     }
     else
     {
         return(string.Format(" if( {0} is null, 'NULL', {0} )", Name));
     }
 }
Example #3
0
 internal StoreType(StoreType st)
 {
     this.ArgType   = st.ArgType;
     this.VarKind   = st.VarKind;
     this.Type      = st.Type;
     this.Value     = st.Value;
     this.Name      = st.Name;
     this.Length    = st.Length;
     this.Precision = st.Precision;
     this.Unsigned  = st.Unsigned;
 }
Example #4
0
 public static string WrapValue(string Type, object Value)
 {
     if (Value == null || Value == DBNull.Value)
     {
         return("NULL");
     }
     else if (StoreType.IsString(Type) || StoreType.IsDateTime(Type))
     {
         return(string.Format("'{0}'", Value));
     }
     else if (Debugger.Cmp(Type, "bit") == 0)
     {
         return((Convert.ToInt32(Value) == 1) ? "1" : "0");
     }
     else
     {
         return(Value.ToString());
     }
 }
 /// <summary>
 /// Parses a data type and update the StoreType with the info gathered.
 /// </summary>
 /// <param name="st"></param>
 /// <param name="node"></param>
 internal void ParseDataType(StoreType st, CommonTree node)
 {
   if (Cmp(node.Text, "data_type") != 0)
   {
     throw new InvalidDataException("Argument node");
   }
   bool isEnum = false;
   CommonTree dtNode = node;
   for (int i = 0; i < dtNode.ChildCount; i++)
   {
     switch (i)
     {
       case 0:
         {
           st.Type = dtNode.GetChild(i).Text;
           if (Debugger.Cmp(st.Type, "set") == 0 || Debugger.Cmp(st.Type, "enum") == 0)
             isEnum = true;
         }
         break;
       case 1:
         {
           int v;
           if (Int32.TryParse(dtNode.GetChild(i).Text, out v))
           {
             st.Length = v;
           }
           else if (Debugger.Cmp(dtNode.GetChild(i).Text, "(") == 0)
           {
             if (isEnum)
             {
               CommonTree parent = (CommonTree)dtNode.GetChild(i);
               st.Values = new List<string>();
               for (int j = 0; j < parent.ChildCount; j++)
               {
                 st.Values.Add(parent.GetChild(j).Text);
               }
             }
             else
             {
               st.Length = Int32.Parse(dtNode.GetChild(i).GetChild(0).Text);
               st.Precision = Int32.Parse(dtNode.GetChild(i).GetChild(1).Text);
             }
           }
           if (Debugger.Cmp(dtNode.GetChild(i).Text, "unsigned") == 0)
             st.Unsigned = true;
         }
         break;
       default:
         // unsigned & zerofill are not tested, since they are the same and unsigned flag is true by default.
         if (Cmp(dtNode.GetChild(i).Text, "signed") == 0)
         {
           st.Unsigned = false;
         }
         // For now, just ignore collate & character
         // ...
         break;
     }
   }
 }
 internal KeyValuePair<string, StoreType> ParseArg(CommonTree node)
 {
   StoreType st = new StoreType();
   int i = 0;
   st.Name = node.GetChild(i).Text;
   st.VarKind = VarKindEnum.Argument;
   i++;
   if (Cmp(node.GetChild(i).Text, "data_type") == 0)
   {
     ParseDataType(st, (CommonTree)node.GetChild(i));
     i++;
   }
   if (i < node.ChildCount)
   {
     string s = node.GetChild(i).Text;
     if ((Cmp("in", s) == 0) || (Cmp("out", s) == 0) || (Cmp("inout", s) == 0))
     {
       st.ArgType = (ArgTypeEnum)Enum.Parse(typeof(ArgTypeEnum), s, true);
     }
   }
   return new KeyValuePair<string, StoreType>(st.Name, st);
 }
 /// <summary>
 /// Returns a description of the variable (or variables) declared within a single DECLARE statement.
 /// </summary>
 /// <param name="Tree"></param>
 /// <returns>Array with one or more variables.</returns>
 internal StoreType[] ParseDeclare( CommonTree Tree )
 {
   StoreType st = new StoreType();
   StoreType[] stVars = null;
   int idx = 0, i, idxDataType;
   while( ( idx < Tree.ChildCount ) && ( Cmp( Tree.GetChild( idx ).Text, "data_type") != 0) )
     idx++;
   if (idx >= Tree.ChildCount)
     throw new InvalidDataException("Argument node");
   stVars = new StoreType[ idx ];
   idxDataType = idx;
   ParseDataType(st, (CommonTree)Tree.GetChild(idx));
   while ((idx < Tree.ChildCount) && (Cmp(Tree.GetChild(idx).Text, "default") != 0))
     idx++;
   if (idx < Tree.ChildCount)
   {
     st.Value = Tree.GetChild(idx).GetChild(0).Text;
   }
   else
   {
     st.Value = DBNull.Value;
   }
   i = 0;
   while ((i < Tree.ChildCount) && (i < idxDataType))
   {
     stVars[ i ] = new StoreType();
     stVars[ i ].Name = Tree.GetChild(i).Text;
     stVars[ i ].Type = st.Type;
     stVars[ i ].Length = st.Length;
     stVars[ i ].Values = st.Values;
     stVars[ i ].Precision = st.Precision;
     stVars[ i ].Unsigned = st.Unsigned;
     stVars[ i ].Value = st.Value;
     i++;
   }
   return stVars;
 }
 /// <summary>
 /// Registers in the current scope all the session variables, so they can be properly emulated.
 /// </summary>
 /// <param name="cts"></param>
 /// <param name="vars"></param>
 private void ParseSessions(CommonTokenStream cts, Dictionary<string, StoreType> vars)
 {
   for( int i = 0; i < cts.Count; i++ )
   {
     IToken tok = cts.Get(i);
     if ((tok.Type == MySQL51Parser.AT1) && ((i + 1) < cts.Count) &&
       (cts.Get(i + 1).Type == MySQL51Parser.ID))
     {
       if ((i > 0) && (cts.Get(i - 1).Type == MySQL51Parser.ID)) continue;
       string id = string.Format( "@{0}", cts.Get( i + 1 ).Text );
       StoreType st;
       if( !vars.TryGetValue( id, out st ) )
       {
         st = new StoreType() { Name = id, Type = "varchar", Value = DBNull.Value, VarKind = VarKindEnum.Session };
         vars.Add(id, st );
       }
     }
   }
 }
 private StoreType GetStoreType(MySqlDataReader r, string prefix)
 {
   StoreType st;
   st = new StoreType();
   st.Name = string.Format( "{0}.{1}",prefix, r.GetString(0) );
   st.Type = r.GetString(1);
   if (StoreType.IsString(st.Type))
     st.Length = r.GetInt32(4);
   else if ( StoreType.IsNumeric( st.Type ) )
     st.Length = r.GetInt32(2);
   st.Values = null;   // TODO: For now, no supporting enum types
   st.Precision = StoreType.IsNumeric(st.Type) ? r.GetInt32(3) : 0;
   st.Unsigned = false;
   st.Value = DBNull.Value;
   return st;
 }
Example #10
0
 internal string WrapValue()
 {
     return(StoreType.WrapValue(Type, Value));
 }
Example #11
0
 internal StoreType(StoreType st)
 {
   this.ArgType = st.ArgType;
   this.VarKind = st.VarKind;
   this.Type = st.Type;
   this.Value = st.Value;
   this.Name = st.Name;
   this.Length = st.Length;
   this.Precision = st.Precision;
   this.Unsigned = st.Unsigned;
 }
Example #12
0
 internal void RaiseValueChanged(StoreType st)
 {
   if (OnValueChanged != null)
     OnValueChanged(st);
 }