Exemplo n.º 1
0
        protected override CodeStatementCollection Build(Dictionary <int, List <Dictionary <PARAMETER, string> > > parameters
                                                         , List <SqlFormat> sQLs
                                                         , string connection
                                                         , bool isNotCondition
                                                         , List <string> ReferencedAssemblies
                                                         , Type type
                                                         , string query)
        {
            ReferencedAssemblies.Add("LazySQL.dll");
            ReferencedAssemblies.Add("LazySQL.SQLite.dll");
            ReferencedAssemblies.Add("System.Data.SQLite.dll");

            CodeStatementCollection codeStatementCollection = new CodeStatementCollection();

            #region 添加所需零件

            StringBuilderBlueprint stringBuilderBlueprint = new StringBuilderBlueprint();

            SQLLiteTemplateBlueprint sQLiteTemplateBlueprint = new SQLLiteTemplateBlueprint();

            #endregion

            codeStatementCollection.Add(stringBuilderBlueprint.Create());

            codeStatementCollection.Add(sQLiteTemplateBlueprint.Create());

            TryCatchFinallyBlueprint tryCatchFinallyBlueprint = new TryCatchFinallyBlueprint();

            codeStatementCollection.Add(tryCatchFinallyBlueprint.Create(() =>
            {
                CodeStatementCollection tryCodeStatementCollection = new CodeStatementCollection();

                ListBlueprint listBlueprint = new ListBlueprint();

                tryCodeStatementCollection.Add(listBlueprint.Create <SQLiteParameter>());

                Building(isNotCondition
                         , parameters
                         , tryCodeStatementCollection
                         , new SQLiteParamterQuery(listBlueprint)
                         , type
                         , sQLs
                         , stringBuilderBlueprint
                         , query
                         , connection
                         , sQLiteTemplateBlueprint
                         , listBlueprint);

                return(tryCodeStatementCollection);
            }));

            return(codeStatementCollection);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 代码构成模板
        /// </summary>
        /// <param name="isNotCondition"></param>
        /// <param name="parameters"></param>
        /// <param name="tryCodeStatementCollection"></param>
        /// <param name="paramterQuery"></param>
        /// <param name="type"></param>
        /// <param name="sqls"></param>
        /// <param name="stringBuilderBlueprint"></param>
        protected void Building(
            bool isNotCondition
            , Dictionary <int, List <Dictionary <PARAMETER, string> > > parameters
            , CodeStatementCollection tryCodeStatementCollection
            , IParamterQuery paramterQuery
            , Type type
            , List <SqlFormat> sqls
            , StringBuilderBlueprint stringBuilderBlueprint
            , string query
            , string connection
            , ITemplateBlueprint templateBlueprint
            , ListBlueprint listBlueprint)
        {
            Dictionary <string, string> SavePar = new Dictionary <string, string>();

            //按顺序添加SQL语句以及条件语句
            for (int sQLsCount = 0; sQLsCount < sqls.Count; sQLsCount++)
            {
                tryCodeStatementCollection.Add(stringBuilderBlueprint.Append(sqls[sQLsCount].SQLText));
                if (!isNotCondition)
                {
                    int CondiIndex = sqls[sQLsCount].CondiIndex;
                    if (CondiIndex != -1)
                    {
                        CreateCondition(SavePar, CondiIndex, parameters, tryCodeStatementCollection, paramterQuery, sqls, sQLsCount, stringBuilderBlueprint, sqls[sQLsCount].oNDITION_TYPE);
                    }
                }
            }

            //返回值
            ReturnBlueprint returnBlueprint = new ReturnBlueprint();

            switch (query)
            {
            case "select":
                SelectReturn(connection
                             , tryCodeStatementCollection
                             , templateBlueprint
                             , returnBlueprint
                             , stringBuilderBlueprint
                             , listBlueprint);
                break;

            default:
                DefaultReturn(connection
                              , tryCodeStatementCollection
                              , templateBlueprint
                              , returnBlueprint
                              , stringBuilderBlueprint
                              , listBlueprint);
                break;
            }
        }
Exemplo n.º 3
0
        protected void SimpleExecuteDataTableCircleBuild <T>(T par, ListBlueprint listBlueprint, CodeStatementCollection codeStatementCollection) where T : IBlueprint, IParmsBlueprint
        {
            codeStatementCollection.Add(stringBuilderBlueprint.Append($"@{fieldName}"));
            codeStatementCollection.Add(stringBuilderBlueprint.AppendField("i"));
            codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"i != ({fieldName}List.Count - 1)", () =>
            {
                CodeStatementCollection codeStatementCollectionTmpIF = new CodeStatementCollection();
                codeStatementCollectionTmpIF.Add(stringBuilderBlueprint.Append(","));
                return(codeStatementCollectionTmpIF);
            }));

            codeStatementCollection.Add(par.Create($"\"@{fieldName}\" + i", $"{fieldName}List[i]"));
            codeStatementCollection.Add(listBlueprint.Add(par.Field));
        }
Exemplo n.º 4
0
 protected override void SelectReturn(string connection, CodeStatementCollection codeStatementCollection, ITemplateBlueprint templateBlueprint, ReturnBlueprint returnBlueprint, StringBuilderBlueprint stringBuilderBlueprint, ListBlueprint listBlueprint)
 {
     codeStatementCollection.Add(returnBlueprint.ReturnExpress(templateBlueprint.ExecuteDataTable(connection
                                                                                                  , stringBuilderBlueprint.Field
                                                                                                  , listBlueprint.Field)));
 }
Exemplo n.º 5
0
 public SqlLiteParamterQuery(ListBlueprint listBlueprint)
 {
     this.listBlueprint = listBlueprint;
 }
Exemplo n.º 6
0
        public CodeStatementCollection Create(StringBuilderBlueprint sqlStrBlueprint
                                              , Dictionary <PARAMETER, string> paramter
                                              , CONDITION_TYPE cONDITION_TYPE)
        {
            stringBuilderBlueprint = sqlStrBlueprint;

            #region 属性赋值及其格式化处理

            CodeStatementCollection codeStatementCollection = new CodeStatementCollection();
            bool needSplit = false;

            string name;
            if (paramter.ContainsKey(PARAMETER.NAME))
            {
                name = paramter[PARAMETER.NAME];
            }
            else
            {
                throw new Exception("不存在Name属性");
            }
            string fieldName = name.Replace(".", string.Empty);

            string target;
            if (paramter.ContainsKey(PARAMETER.TARGET))
            {
                target = paramter[PARAMETER.TARGET];
            }
            else
            {
                target = name;
            }

            string symbol;
            if (paramter.ContainsKey(PARAMETER.SYMBOL))
            {
                symbol = paramter[PARAMETER.SYMBOL];
                foreach (var c in ConditionSplit)
                {
                    if (symbol.Equals(c, StringComparison.InvariantCultureIgnoreCase))
                    {
                        needSplit = true;
                    }
                }
            }
            else
            {
                symbol = "=";
            }

            string        template  = string.Empty;
            List <string> templates = new List <string>();
            if (paramter.ContainsKey(PARAMETER.TEMPLATE))
            {
                template = paramter[PARAMETER.TEMPLATE];

                if (template.IndexOf("*") == -1)
                {
                    throw new Exception("在模板中,没有作为标记的'*'符号");
                }

                if (needSplit)
                {
                    templates = new List <string>(template.Split('*'));
                }
            }
            else
            {
                if (needSplit)
                {
                    throw new Exception("你使用了in,not in这类多参数的传值没有写模板");
                }
            }

            #endregion

            //FieldName赋值,方便给子类使用
            this.fieldName = fieldName;

            switch (cONDITION_TYPE)
            {
            case CONDITION_TYPE.SET:
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{fieldName} = @{fieldName}ParSET,"));
                    SetTrue(codeStatementCollectionIF);
                    return(codeStatementCollectionIF);
                }));
                break;

            case CONDITION_TYPE.VALUE:
                codeStatementCollection.Add(sqlStrBlueprint.Append($"@{fieldName}VALUE"));
                codeStatementCollection.Add(sqlStrBlueprint.Append(" , "));
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    ValueTrue(codeStatementCollectionIF);
                    return(codeStatementCollectionIF);
                },
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionElse = new CodeStatementCollection();
                    ValueFalse(codeStatementCollectionElse);
                    return(codeStatementCollectionElse);
                }));
                break;

            case CONDITION_TYPE.WHERE:
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    codeStatementCollectionIF.Add(stringBuilderBlueprint.Append(" AND "));
                    if (!needSplit)
                    {
                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{target} {symbol} {(string.IsNullOrWhiteSpace(template) ? $"@{fieldName}" : template)}"));
                        ExecuteDataTableNormalBuild(codeStatementCollectionIF);
                    }
                    else
                    {
                        ListBlueprint listBlueprint = new ListBlueprint($"{fieldName}List");
                        codeStatementCollectionIF.Add(listBlueprint.Create <string>($"{fieldName}.Split(',')"));
                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{target} {symbol} {templates[0]}"));

                        codeStatementCollectionIF.Add(ToolManager.Instance.CircleTool.CreateCircle("int i = 0", $"i < {fieldName}List.Count", "i++", () =>
                        {
                            CodeStatementCollection codeStatementCollectionFor = new CodeStatementCollection();
                            ExecuteDataTableCircleBuild(codeStatementCollectionFor);
                            return(codeStatementCollectionFor);
                        }));

                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append(templates[1]));
                    }
                    return(codeStatementCollectionIF);
                }));
                break;
            }

            return(codeStatementCollection);
        }
Exemplo n.º 7
0
 protected void SimpleValueFalse <T>(T par, ListBlueprint listBlueprint, CodeStatementCollection codeStatementCollection) where T : IBlueprint, IParmsBlueprint
 {
     codeStatementCollection.Add(par.Create($"\"@{fieldName}VALUE\"", "\"\""));
     codeStatementCollection.Add(listBlueprint.Add(par.Field));
 }
Exemplo n.º 8
0
 protected void SimpleSetTrue <T>(T par, ListBlueprint listBlueprint, CodeStatementCollection codeStatementCollection) where T : IBlueprint, IParmsBlueprint
 {
     codeStatementCollection.Add(par.Create($"\"@{fieldName}ParSET\"", $"{fieldName}"));
     codeStatementCollection.Add(listBlueprint.Add(par.Field));
 }
Exemplo n.º 9
0
 protected void SimpleExecuteDataTableNormalBuild <T>(T par, ListBlueprint listBlueprint, CodeStatementCollection codeStatementCollection) where T : IBlueprint, IParmsBlueprint
 {
     codeStatementCollection.Add(par.Create($"\"@{fieldName}\"", $"{fieldName}"));
     codeStatementCollection.Add(listBlueprint.Add(par.Field));
 }
Exemplo n.º 10
0
 public MsSqlParamterQuery(ListBlueprint listBlueprint)
 {
     this.listBlueprint = listBlueprint;
 }
Exemplo n.º 11
0
 protected abstract void DefaultReturn(string connection
                                       , CodeStatementCollection codeStatementCollection
                                       , ITemplateBlueprint templateBlueprint
                                       , ReturnBlueprint returnBlueprint
                                       , StringBuilderBlueprint stringBuilderBlueprint
                                       , ListBlueprint listBlueprint);