Пример #1
0
        public void OpenIndexes(IndexInfo[] info)
        {
            IxInfo = info;

            long curIndex = -1;
            var  dt       = new G.List <DataType>();
            var  cm       = new G.List <int>();

            for (int i = 0; i <= info.Length; i += 1)
            {
                if (i > 0 && (i == info.Length || info[i].IndexId != curIndex))
                {
                    IndexFileInfo ci = new IndexFileInfo();
                    dt.Add(DataType.Bigint); // For id value
                    ci.KeyCount = dt.Count;
                    ci.Types    = dt.ToArray();
                    ci.BaseIx   = cm.ToArray();
                    ci.IndexId  = curIndex;
                    OpenIndex(curIndex, ci);
                    dt = new G.List <DataType>();
                    cm = new G.List <int>();
                }
                if (i != info.Length)
                {
                    curIndex = info[i].IndexId;
                    int colIx = info[i].ColIx;
                    dt.Add(CI.Type[colIx]);
                    cm.Add(colIx);
                }
            }
        }
Пример #2
0
    public static ReadOnlyList <T> Create <T>(params IEnumerable <T>[] sequences)
    {
        var list = new G.List <T>();

        sequences.Where(s => s != null).Iterate(s => list.AddRange(s));
        return(new ReadOnlyList <T>(list));
    }
Пример #3
0
    public WebResultSet(System.Net.HttpListenerContext ctx, System.IO.MemoryStream outStream)
    {
        Ctx       = ctx;
        OutStream = outStream;

        if (ctx.Request.HasEntityBody)
        {
            if (ctx.Request.ContentType == "application/x-www-form-urlencoded")
            {
                string input = null;
                using (System.IO.StreamReader reader = new System.IO.StreamReader(ctx.Request.InputStream))
                {
                    input = reader.ReadToEnd( );
                }
                Form = System.Web.HttpUtility.ParseQueryString(input);
            }
            else /* Assume multipart/form-data */
            {
                Files = ParseMultipart(ctx.Request);
            }
        }

        CookieNames = new G.List <string>();
        foreach (string k in ctx.Request.Cookies)
        {
            CookieNames.Add(k);
        }
    }
Пример #4
0
    FormFile[] ParseMultipart(System.Net.HttpListenerRequest rq)
    {
        /* Typical multipart body would be:
         * ------WebKitFormBoundaryVXXOTFUWdfGpOcFK
         * Content-Disposition: form-data; name="f1"; filename="test.txt"
         * Content-Type: text/plain
         *
         * Hello there
         *
         * ------WebKitFormBoundaryVXXOTFUWdfGpOcFK
         * Content-Disposition: form-data; name="submit"
         *
         * Upload
         * ------WebKitFormBoundaryVXXOTFUWdfGpOcFK--
         */

        var flist = new G.List <FormFile>();

        byte[] data = ToByteArray(rq.InputStream);
        System.Text.Encoding encoding = System.Text.Encoding.UTF8; // Not entirely clear what encoding should be used for headers.
        int pos = 0;                                               /* Index into data */

        while (true)
        {
            int headerLength = IndexOf(data, encoding.GetBytes("\r\n\r\n"), pos) - pos + 4;

            if (headerLength < 4)
            {
                break;
            }
            string headers = encoding.GetString(data, pos, headerLength);
            pos += headerLength;

            // The first header line is the delimiter
            string delimiter = headers.Substring(0, headers.IndexOf("\r\n"));

            // Extract atrtributes from header
            string contentType = Look(@"(?<=Content\-Type:)(.*?)(?=\r\n)", headers);
            string name        = Look(@"(?<= name\=\"")(.*?)(?=\"")", headers);
            string filename    = Look(@"(?<=filename\=\"")(.*?)(?=\"")", headers);

            // Get the content length
            byte[] delimiterBytes = encoding.GetBytes("\r\n" + delimiter);
            int    contentLength  = IndexOf(data, delimiterBytes, pos) - pos;

            if (contentLength < 0)
            {
                break;
            }

            // Extract the content from data
            byte[] content = new byte[contentLength];
            System.Buffer.BlockCopy(data, pos, content, 0, contentLength);
            pos += contentLength + delimiterBytes.Length;

            flist.Add(new FormFile(name, contentType, filename, content));
        }
        return(flist.ToArray());
    }
Пример #5
0
 public EXCEPTION(G.List <Exp> parms, Exec e)
 {
     if (parms.Count != 0)
     {
         e.Error("EXCEPTION takes no parameters");
     }
     Type = DataType.String;
 }
Пример #6
0
 public LASTID(G.List <Exp> parms, Exec e)
 {
     if (parms.Count != 0)
     {
         e.Error("LASTID takes no parameters");
     }
     Type = DataType.Bigint;
 }
Пример #7
0
 public LEN(G.List <Exp> args, Exec e)
 {
     if (args.Count != 1)
     {
         e.Error(this + "takes one argument");
     }
     E    = args[0];
     Type = DataType.Bigint;
 }
Пример #8
0
 public override DS GetDS()
 {
   // Operator == Token.VBar, only string-valued operator.
   var list = new G.List<Exp>();
   Left.GetConcat( list );
   Right.GetConcat( list );
   var dlist = new DS[ list.Count ];
   for ( int i = 0; i < dlist.Length; i += 1 ) dlist[ i ] = list[ i ].GetDS();
   return ( e ) => DoConcat( dlist, e );
 }
Пример #9
0
 public StdExp(G.List <Exp> arg, DataType type, DataType [] types, Exec e)
 {
     Arg   = arg.ToArray();
     Type  = type;
     Types = types;
     if (Arg.Length != Types.Length)
     {
         e.Error(this + " takes " + Types.Length + " argument(s)");
     }
 }
        public For(TableExpression te, int[] assigns, Block b)
        {
            Fetched     = 0;
            Assigns     = assigns;
            LocalValues = b.Locals;
            var rs = new SingleResultSet();

            te.FetchTo(rs, b);
            Rows = rs.Table.Rows;
        }
  public void AlterTable( string schemaName, string tableName, G.List<AlterAction> alist, Exec e )
  {
    Table t = (Table) GetTable( schemaName, tableName, e );

    var names = new G.List<string>( t.Cols.Names );
    var types = new G.List<DataType>( t.Cols.Types );
    var map = new G.List<int>();
    for ( int i = 0; i < names.Count; i += 1 ) map.Add( i );

    foreach ( AlterAction aa in alist )
    {
      int ix = names.IndexOf( aa.Name );
      if ( aa.Operation != Action.Add && ix == -1 )
        e.Error( "Column " + aa.Name + " not found" );

      switch ( aa.Operation )
      {
        case Action.Add: 
          if ( ix != -1 ) e.Error( "Column " + aa.Name + " already exists" );
          names.Add( aa.Name );
          types.Add( aa.Type );
          map.Add( 0 );
          Sql( "INSERT INTO sys.Column( Table, Name, Type ) VALUES ( " + t.TableId + "," + Util.Quote(aa.Name) + "," + (int)aa.Type + ")" );
          break;
        case Action.Drop:
          names.RemoveAt( ix );
          types.RemoveAt( ix );
          map.RemoveAt( ix );
          Sql( "DELETE FROM sys.Column WHERE Table = " + t.TableId + " AND Name = " + Util.Quote(aa.Name) ); 
          Sql( "EXEC sys.DroppedColumn(" + t.TableId + "," + ix + ")" );
          break;
        case Action.ColumnRename:
          names.RemoveAt( ix );
          names.Insert( ix, aa.NewName );
          Sql( "UPDATE sys.Column SET Name = " + Util.Quote(aa.NewName) + " WHERE Table=" + t.TableId + " AND Name = " + Util.Quote(aa.Name) );
          break;
        case Action.Modify:
          if ( DTI.Base( aa.Type ) != DTI.Base( types[ ix ] ) )
            e.Error( "Modify cannot change base type" );
          if ( DTI.Scale( aa.Type ) != DTI.Scale( types[ ix ] ) )
            e.Error( "Modify cannot change scale" );
          types.RemoveAt( ix );
          types.Insert( ix, aa.Type );
          Sql( "UPDATE sys.Column SET Type = " + (int)aa.Type + " WHERE Table=" + t.TableId + " AND Name = " + Util.Quote(aa.Name) );
          Sql( "EXEC sys.ModifiedColumn(" + t.TableId + "," + ix + ")" );
          break;
      }
    }
    var newcols = ColInfo.New( names, types );
    t.AlterData( newcols, map.ToArray() );
    Sql( "EXEC sys.RecreateModifiedIndexes()" );
    t.OpenIndexes();
    ResetCache();
  }
Пример #12
0
        int LabelUndefined = 0;                 // Number of labels awaiting definition.

        // Statement preparation ( compile phase ).

        public void Init()
        {
            Statements = null;
            Jumps      = null;
            LocalTypes = null;

            StatementList = new G.List <System.Action>();
            JumpList      = new G.List <int>();
            LocalTypeList = new G.List <DataType>();
            VarMap        = new G.Dictionary <string, int>();
            LabelMap      = new G.Dictionary <string, int>();
        }
Пример #13
0
        public void Complete()
        {
            Statements = StatementList.ToArray();
            Jumps      = JumpList.ToArray();
            LocalTypes = LocalTypeList.ToArray();

            StatementList = null;
            JumpList      = null;
            LocalTypeList = null;
            VarMap        = null;
            LabelMap      = null;
        }
 public void Add( string name, DataType type )
 {
   if ( Names == null ) 
   {
     Names = new G.List<string>();
     Types = new G.List<DataType>();
     Names.Add( "Id" );
     Types.Add( DataType.Bigint );
   }
   Names.Add( name );
   Types.Add( type );
 }
        public override G.IEnumerable <long> All(EvalEnv ee)
        {
            StoredTable t = S.Table;

            G.List <Value[]> rows = t.Rows;

            for (int i = 0; i < rows.Count; i += 1)
            {
                Value[] row = rows[i];
                yield return(row[0].L);
            }
        }
 /**
  * Get the list of vertices in the graph, except those removed.
  * @return
  */
 public override G.IList <BaseVertex> GetVertexList()
 {
     G.IList <BaseVertex> retList = new G.List <BaseVertex>();
     foreach (BaseVertex curVertex in base.GetVertexList())
     {
         if (remVertexIdSet.Contains(curVertex.GetId()))
         {
             continue;
         }
         retList.Add(curVertex);
     }
     return(retList);
 }
Пример #17
0
    /////////////////////////////////////////////////////////////////////////////

    void SaveEmail(DBNS.Value [] row)
    {
        Email em;

        em.From     = row[1].S;
        em.To       = row[2].S;
        em.Subject  = row[3].S;
        em.Body     = row[4].S;
        em.Server   = row[5].S;
        em.Port     = (int)row[6].L;
        em.Username = row[7].S;
        em.Password = row[8].S;
        if (EmailList == null)
        {
            EmailList = new G.List <Email>();
        }
        EmailList.Add(em);
    }
  public TableExpression GetTableOrView( string schemaName, string name, Exec e )
  {
    Schema schema = GetSchema( schemaName, true, e );
    TableExpression result = schema.GetCachedTable( name ); 
    if ( result != null ) return result;

    bool isView; string definition;
    long tid = ReadTableId( schema, name, out isView, out definition );
    if ( tid < 0 ) e.Error( schemaName + "." + name + " not found" );

    if ( isView )
    {
      TableExpression te = e.LoadView( definition, schemaName + "." + name );
      te.TableId = tid;
      schema.TableDict[ name ] = te;
      return te;
    }
    else
    {
      // Fetch the Column Information from the SysColumn table.
      var names = new G.List<string>(); 
      var types = new G.List<DataType>();
      names.Add( "Id" ); types.Add( DataType.Bigint ); // Add the pre-defined "id" column.

      // Use SysColumnIndex to avoid scanning the entire SysColumn table.
      var start = new LongStart( tid );
      var r = new RowCursor( SysColumn );

      foreach( IndexFileRecord ixr in SysColumnIndex.From( start.Compare, false ) )
      {
        if ( ixr.Col[0].L == tid )
        {
          r.Get( ixr.Col[1].L );
          names.Add( (string) r.V[2]._O );
          types.Add( (DataType)r.V[3].L );
        }
        else break;
      }

      Table t = new Table( this, schema, name, ColInfo.New(names,types), tid );
      t.OpenIndexes();
      return t;
    }
  }
  void ResetCache()
  {
    // Removes all schema cached objects other than base tables ( functions, procedures, views ).
    foreach( G.KeyValuePair<string,Schema> p in SchemaDict )
    {
      Schema s = p.Value;
      s.BlockDict.Clear();

      var vlist = new G.List<string>();
      foreach( G.KeyValuePair<string,TableExpression> q in s.TableDict )
      {
        TableExpression te = q.Value;
        if ( ! ( te is Table ) )
          vlist.Add( q.Key );
      }
      foreach ( string v in vlist )
        s.TableDict.Remove( v );
    }
  }
Пример #20
0
        void HandleMethodCall(OrderSpecificationMethod method, MethodCallExpression node)
        {
            var arguments = node.Arguments.ToList();

            if (arguments.Count != 2)
            {
                return;
            }

            var selector = (arguments[1] as UnaryExpression)?.Operand as LambdaExpression;

            if (selector == null)
            {
                return;
            }

            if (selector.Parameters.Count != 1)
            {
                return;
            }

            var property = selector.TryGetAccesedProperty().ValueOrDefault();

            if (property == null)
            {
                return;
            }

            var methodName = node.Method.Name;
            var type       = selector.Parameters[0].Type;


            orders.Add(new MemberItemOrder(property, method.Direction));

            if (method.IsPrimary)
            {
                orders
                    = mapi(orders.Reverse <MemberItemOrder>(), (i, e) => e.Clone(NewPrecedence: i)).ToList();
            }
        }
        // Statement execution.

        public void ExecProcedure(Block b, G.List <Exp> parms, SqlExec e)
        {
            // Allocate the local variables for the called procedure.
            var locals = new Value[b.LocalType.Count];

            // Evaluate the parameters to be passed, saving them in the newly allocated local variables.
            for (int i = 0; i < parms.Count; i += 1)
            {
                locals[i] = parms[i].Eval(this);
            }

            // Save local state.
            var save1 = b.Locals;
            var save2 = b.NextStatement;

            // Execute the procedure
            b.Locals = locals;
            b.ExecuteStatements(ResultSet);

            // Restore local state.
            b.NextStatement = save2;
            b.Locals        = save1;
        }
  public IndexInfo [] ReadIndexes( long tableId )
  {
    var ix = new G.List<IndexInfo>();
    var r = new RowCursor( SysIndexCol );
    long CurIx = 0;
    int IxNum = 0;

    // Use SysIndexColIndex to avoid scanning the entire SysIndexCol table.
    var start = new LongStart( tableId );
    foreach( IndexFileRecord ixr in SysIndexColIndex.From( start.Compare, false ) )
    {
      if ( ixr.Col[0].L == tableId )
      {
        r.Get( ixr.Col[1].L );
        var ii = new IndexInfo();
        ii.IndexId = r.V[2].L;
        if ( ii.IndexId != CurIx ) { IxNum = 0; CurIx = ii.IndexId; }
        ii.IxNum = IxNum++;
        ii.ColIx = (int)r.V[3].L; 
        ix.Add( ii );
      } else break;
    }
    return ix.ToArray();
  }
Пример #23
0
 public Sorter(ResultSet output, SortSpec[] s)
 {
     Output = output;
     Spec   = s;
     Rows   = new G.List <Value[]>();
 }
 public static ColInfo New(G.List <string> names, G.List <DataType> types)
 {
     return(new ColInfo(names.ToArray(), types.ToArray()));
 }
Пример #25
0
 public FILECONTENT(G.List <Exp> args, Exec e) : base(args, DataType.Binary,
                                                      new DataType[] { DataType.Bigint }, e)
 {
 }
Пример #26
0
 public REPLACE(G.List <Exp> args, Exec e) : base(args, DataType.String,
                                                  new DataType[] { DataType.String, DataType.String, DataType.String }, e)
 {
 }
Пример #27
0
 public SUBSTRING(G.List <Exp> args, Exec e) : base(args, DataType.String,
                                                    new DataType[] { DataType.String, DataType.Bigint, DataType.Bigint }, e)
 {
 }
Пример #28
0
 public ExpFuncCall( string schema, string fname, G.List<Exp> plist )
 {
   Schema = schema;
   FuncName = fname;
   Plist = plist.ToArray();
 }
Пример #29
0
 public ExpList( G.List<Exp> list )
 { 
   List = list.ToArray();
   Type = DataType.None;
 }
Пример #30
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]; 
 }