Esempio n. 1
0
        public static string GenerateSqlSelect(Type type, int totalRows)
        {
            SetRandomSeed();
            SetFirstRowData();

            IClassInfo info = IQ.ClassInfo(type);

            string sql = "";

            for (int row = 0; row < totalRows; row++)
            {
                string rowSelect = "";
                foreach (var item in info.Fields)
                {
                    object value;
                    if (row == 0)
                    {
                        value = GetAsSqlSelect(SampleData[item.ReturnType]);
                    }
                    else
                    {
                        value = GetRandomSQLData(item.ReturnType);
                    }
                    rowSelect += (rowSelect == "" ? "" : ",") + value + " as " + item.SqlName;
                }
                rowSelect += "," + row.ToString() + " as rowOrder";
                sql       += (sql == ""?"":" union ") + "select " + rowSelect;
            }
            return(sql + " order by rowOrder");
        }
Esempio n. 2
0
        protected IClassInfo GetClassInfo(object obj)
        {
            IClassInfo classInfo = IQ.ClassInfo(obj.GetType());

            if (!classInfo.IsBound)
            {
                throw new KeyNotFoundException(String.Format("The type '{0}' is not bound.", obj.GetType()));
            }
            return(classInfo);
        }
Esempio n. 3
0
        public static IDataReader GenerateFakeDataReader(Type type, int rows)
        {
            SetRandomSeed();
            SetFirstRowData();

            IClassInfo info = IQ.ClassInfo(type);

            TestDataReader reader = new TestDataReader();

            foreach (var item in info.Fields)
            {
                reader.AddFieldToMock(item.SqlName, item.ReturnType);
            }
            reader.Generate(rows);
            return(reader);
        }
Esempio n. 4
0
        protected void RunQuery()
        {
            IDataReader DataReader;

            if (Buffered != DbBuffering.Buffered || !SqlQueryBuilderConfig.TryGetCachedData(Query, out DataReader))
            {
                DataReader = DataStorageController.RunQuery(Connection, Query, Transaction, CommandBehavior);
                DataReader = SqlQueryBuilderConfig.AddToCache(Query, DataReader);
            }

            // datareaderadapter will return a new Dictionary<string,object> when T is IDictionary<string,object>
            // we must map to an interim structure because of name-changes via SqlName

            var cInfo = IQ.ClassInfo <T>();

            var dra = new DataReaderAdapter <T>(DataReader,
                                                cInfo != null ?
                                                new Options {
                FieldNameMap = cInfo.SqlNameMap
            }:
                                                null);

            dra.OnLoad = OnLoad;
            dra.Target = Target;



            //IEnumerable<T> wrapper = GetFinalSequence(dra);

            if (Buffered == DbBuffering.Buffered)
            {
                var list = new List <T>();
                list.AddRange(dra);
                Data = list;
            }
            else
            {
                Data = dra;
            }
        }
Esempio n. 5
0
        protected ISqlQuery ParseComplexQuery(object query, IEnumerable <object> parms)
        {
            ISqlQuery outputQuery = null;

            // We always want to parse the parameters. But if the thing passed to us as "query" is not a string, then
            // just assume that all the parms are option type parameters and don't pass a query to ParameterParser
            string querySource = query is string?
                                 (string)query:
                                 "";

            ParameterParser pp = new ParameterParser(querySource, parms);

            if (Types.IsNumericType(query))
            {
                // It's a single numeric value - assume it's a primary key

                ExpectNoParameters(pp.Parameters);

                var classInfo = IQ.ClassInfo <T>();

                ISqlQueryMaker queryPK = classInfo.GetQuery();
                queryPK.Where.Add(classInfo.PrimaryKeyField.Name, query);
                outputQuery = queryPK;
            }
            else if (query is string)
            {
                bool isMappable = Types.IsMappable(typeof(T));

                // First check if its a single named field

                if (isMappable)
                {
                    var classInfo = IQ.ClassInfo <T>();


                    // Try to create a valid raw query.. if it's not valid, assume it's a where
                    if (QueryType == QueryType.Where || pp.QueryType == QueryType.Invalid)
                    {
                        ISqlQueryMaker queryPK = classInfo.GetQuery();

                        //var whereString = new WhereString(pp.Query,
                        //    pp.Parameters.Count > 0 ?
                        //        pp.Parameters.ToArray():
                        //        null);
                        queryPK.Where.Add(pp.GetWhereClause());

                        outputQuery = queryPK;
                    }
                    else
                    {
                        outputQuery = new SqlQueryDef(pp.GetQuery(QueryType), pp.Parameters);
                    }
                }
                else
                {
                    // it's mapped to a primitive type -
                    outputQuery = new SqlQueryDef(pp.GetQuery(QueryType), pp.Parameters);
                }
            }
            if (outputQuery.QueryType != QueryType)
            {
                throw new IQException("Wrong type of query passed to method: was " + outputQuery.ToString() + ", expected " + QueryType.ToString());
            }

            return(outputQuery);
        }