コード例 #1
0
        public static void Main()
        {
            var random = new RandomNumberGenerator(123);

            using NativeList <int> list = new NativeList <int>(10);

            for (int i = 0; i < 100; i++)
            {
                list.Add(random.NextInt(1000));
            }

            // Creates a query over the elements of the list,
            // this copies all the elements of the list into the query
            using NativeQuery <int> query = list.AsQuery();

            // Gets the min and max
            // Must call NativeQuery<T>.Clone() due most of the query operations Dispose the query after being called
            int min = query.Clone().Min();
            int max = query.Clone().Max();

            // Prints: (36, 920)
            Console.WriteLine((min, max));

            using NativeQuery <int> sorted = list
                                             .AsQuery()           // Creates a query
                                             .Sorted()            // Sorts the element of the query
                                             .Where(e => e < 100) // Filters the elements by lower than 100
                                             .Reverse()           // Reverse the query
                                             .Take(5);            // Takes the first 5 elements

            // Must call ToString() to NativeQuery<T> is a ref struct
            // Prints: [94, 87, 86, 63, 57]
            Console.WriteLine(sorted.ToString());
        }
コード例 #2
0
        public static void fetchResult(this StoredProcedure aSP, Config aConfig, DBHelper aHelper)
        {
            List <DBColumn> _result    = new List <DBColumn>();
            var             paramaters = GetParamaters(aSP.Paramaters);
            var             query      = NativeStoredProcedureQuery.GetSQLQuery(aSP.Name, paramaters);

            using (SqlConnection con = new SqlConnection(aConfig.DataSource))
            {
                try
                {
                    con.Open();
                    String q = query.Query;
                    q = "SET FMTONLY ON;" + q + ";SET FMTONLY OFF;";
                    using (SqlCommand Command = new SqlCommand(query.Query, con))
                    {
                        Command.Parameters.AddRange(query.Parameters.ToArray());
                        logger.Debug(q);

                        using (SqlDataReader aReader = Command.ExecuteReader())
                        {
                            DataTable _schema = aReader.GetSchemaTable();
                            if (_schema != null)
                            {
                                foreach (DataRow row in _schema.Rows)
                                {
                                    _result.Add(new DBColumn
                                    {
                                        TABLE_NAME  = "SP" + aSP.Name,
                                        DATA_TYPE   = row["DataType"].ToString(),
                                        COLUMN_NAME = row["BaseColumnName"].ToString()
                                    });
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Debug(ex);
                    con.Close();
                    _result.Add(new DBColumn
                    {
                        TABLE_NAME  = "SP" + aSP.Name,
                        DATA_TYPE   = typeof(DataTable).ToString(),
                        COLUMN_NAME = "Result"
                    });

                    var q = NativeQuery.SimpleQueryHelper("SET FMTONLY OFF;");
                    aHelper.Execute(delegate(DbSession aDBSession)
                    {
                        aDBSession.Execute(q, new DataReaderBinder());
                    });
                }

                var r = _result.Convert(false);
                aSP.Result = r.Count() > 0 ? r.First() : null;
            }
        }
コード例 #3
0
        public List <DBStoredProcedureParamater> GetStoredProcedureParamaters()
        {
            var q = NativeQuery.SimpleQueryHelper("select r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME, r.SPECIFIC_CATALOG, p.PARAMETER_NAME, p.DATA_TYPE from  DataBank.INFORMATION_SCHEMA.ROUTINES as r inner JOIN information_schema.PARAMETERS as p ON p.SPECIFIC_NAME = r.SPECIFIC_NAME where routine_type = @p0", "PROCEDURE");

            TemplateBinder <DBStoredProcedureParamater> _binder = new TemplateBinder <DBStoredProcedureParamater>();
            List <DBStoredProcedureParamater>           _r      = new List <DBStoredProcedureParamater>();

            _binder.OnBind = delegate(DBStoredProcedureParamater aT)
            {
                _r.Add(aT);
            };
            DBHelper.Execute(delegate(DbSession aDBSession)
            {
                aDBSession.Execute(q, _binder);
            });
            return(_r);
        }
コード例 #4
0
        public IEnumerable <TableStructure> GetSchemaTables()
        {
            SqlQuery _query = NativeQuery.SimpleQueryHelper(
                "select col.TABLE_SCHEMA, col.TABLE_CATALOG, col.TABLE_NAME, col.COLUMN_NAME, col.DATA_TYPE, const.CONSTRAINT_TYPE " +
                "from INFORMATION_SCHEMA.COLUMNS as col " +
                "LEFT JOIN " +
                "(SELECT cu.TABLE_NAME, cu.COLUMN_NAME,  cu.CONSTRAINT_NAME, tc.CONSTRAINT_TYPE " +
                "From INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu INNER JOIN " +
                "INFORMATION_SCHEMA.TABLE_CONSTRAINTS as tc ON " +
                "(cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME) where tc.CONSTRAINT_TYPE = 'PRIMARY KEY') AS const " +
                "ON  " +
                "(col.TABLE_NAME = const.TABLE_NAME AND col.COLUMN_NAME = const.COLUMN_NAME) " +
                "Order by col.TABLE_NAME ASC, col.COLUMN_NAME ASC");

            var _dbColumns = ExecuteQuery(_query);

            return(_dbColumns.Convert());
        }
コード例 #5
0
/*
 *      //acquire a TableView handle with the result And set Root in an atomic fashion
 *      [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
 *      internal TableViewHandle QueryFindAll(long start, long end, long limit)
 *      {
 *          var tvHandle = TableViewHandle.RootedTableViewHandle(this);//same root as the query
 *
 *          //At this point sh is invalid due to its handle being uninitialized, but the root is set correctly
 *          //a finalize at this point will not leak anything and the handle will not do anything
 *
 *          //now, set the TableView handle...
 *          RuntimeHelpers.PrepareConstrainedRegions();//the following finally will run with no out-of-band exceptions
 *          try
 *          { }
 *          finally
 *          {
 *              tvHandle.SetHandle(NativeQuery.find_all(this, start, end , limit));
 *          }//at this point we have atomically acquired a handle and also set the root correctly so it can be unbound correctly
 *          return tvHandle;
 *      }
 *
 *      //acquire a TableView handle with the result And set Root in an atomic fashion
 *      [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
 *      internal TableViewHandle QueryFindAll()
 *      {
 *          var tvHandle = TableViewHandle.RootedTableViewHandle(this);//same root as the query
 *
 *          //At this point sh is invalid due to its handle being uninitialized, but the root is set correctly
 *          //a finalize at this point will not leak anything and the handle will not do anything
 *
 *          //now, set the TableView handle...
 *          RuntimeHelpers.PrepareConstrainedRegions();//the following finally will run with no out-of-band exceptions
 *          try
 *          { }
 *          finally
 *          {
 *              tvHandle.SetHandle(NativeQuery.find_all_np(this));
 *          }//at this point we have atomically acquired a handle and also set the root correctly so it can be unbound correctly
 *          return tvHandle;
 *      }
 */
        protected override void Unbind()
        {
            NativeQuery.destroy(handle);
        }
コード例 #6
0
 public static bool Match(NativeQuery query, object o)
 {
     return(query.Match(o));
 }
コード例 #7
0
 public static string GetClass(NativeQuery query)
 {
     return(OdbClassUtil.GetFullName(query.GetObjectType()));
 }