Example #1
0
File: DB.cs Project: wra222/testgit
        public SQLContext MergeToOneNonQuery()
        {
            lock (_content)
            {
                SQLContext ret = new SQLContext();
                foreach (int key in _content.Keys)
                {
                    SQLContext item = _content[key];
                    string sentence = item.Sentence;

                    if (item.Params != null && item.Params.Count > 0)
                    {
                        foreach (string paramKey in item.Params.Keys)
                        {
                            SqlParameter paramItem = item.Params[paramKey];
                            SqlParameter newItem = new SqlParameter("@" + key.ToString() + "_" + paramItem.ParameterName.Substring(1), paramItem.SqlDbType);
                            newItem.Value = paramItem.Value;
                            ret.Params.Add(key.ToString() + "_" + paramKey, newItem);
                            sentence = sentence.Replace(paramItem.ParameterName, newItem.ParameterName);
                        }
                    }
                    ret.Sentence = ret.Sentence + sentence + ";";
                }
                return ret;
            }
        }
Example #2
0
File: DB.cs Project: wra222/testgit
 public void AddOne(int index, SQLContext item)
 {
     lock (_content)
     {
         if (!_content.ContainsKey(index))
             _content.Add(index, item);
     }
 }
Example #3
0
File: DB.cs Project: wra222/testgit
        public SQLContext MergeToOneQuery(string andOrOr)
        {
            lock (_content)
            {
                SQLContext ret = new SQLContext();
                if (_content.Keys != null && _content.Keys.Count > 0)
                {
                    int i = 0;
                    foreach (int key in _content.Keys)
                    {
                        SQLContext item = _content[key];
                        if (i == 0)
                        {
                            ret.Indexes = item.Indexes;

                            if (_content.Keys.Count == 1)
                            {
                                ret.Sentence = item.Sentence;
                            }
                            else
                            {
                                string[] fieldAndCond = item.Sentence.Split(new string[] { "WHERE" }, StringSplitOptions.None);
                                if (fieldAndCond != null)
                                {
                                    if (fieldAndCond.Length > 1)
                                        ret.Sentence = fieldAndCond[0] + " WHERE (" + fieldAndCond[1] + ") ";
                                    else
                                        ret.Sentence = fieldAndCond[0] + " WHERE (1=1) ";
                                }
                            }
                        }
                        else
                        {
                            string[] fieldAndCond = item.Sentence.Split(new string[] { "WHERE" }, StringSplitOptions.None);
                            if (fieldAndCond != null && fieldAndCond.Length > 1)
                            {
                                ret.Sentence = ret.Sentence + " " + andOrOr + " (" + fieldAndCond[1] + ") ";
                            }
                        }
                        if (item.Params != null && item.Params.Count > 0)
                        {
                            foreach (string key_i in item.Params.Keys)
                            {
                                if (!ret.Params.ContainsKey(key_i))
                                    ret.Params.Add(key_i, item.Params[key_i]);
                            }
                        }
                        i++;
                    }
                }
                return ret;
            }
        }
Example #4
0
File: DB.cs Project: wra222/testgit
 internal static bool InsertIntoCache(int methodId, SQLContext sqlCtx)
 {
     lock (_cacheSyncObj)
     {
         if (!_cache.ContainsKey(methodId))
         {
             _cache.Add(methodId, sqlCtx);
             return true;
         }
         else
             return false;
     }
 }
Example #5
0
File: DB.cs Project: wra222/testgit
 private static bool GetFromCache(int methodId, ref SQLContext sqlCtx)
 {
     lock (_cacheSyncObj)
     {
         if (_cache.ContainsKey(methodId))
         {
             sqlCtx = _cache[methodId];
             return true;
         }
         else
         {
             sqlCtx = new SQLContext();
             _cache.Add(methodId, sqlCtx);
             return false;
         }
     }
 }
Example #6
0
File: DB.cs Project: wra222/testgit
 private static bool PeerTheSQL_Inner(int methodId, out SQLContext sqlCntxt, bool isJoinSQL, out TableAndFields[] tblAndFldses)
 {
     sqlCntxt = null;
     tblAndFldses = null;
     bool res1 = false;
     lock (_cacheSyncObj)
     {
         if (_cache.ContainsKey(methodId))
         {
             sqlCntxt = new SQLContext(_cache[methodId]);// 2010-03-01 Liu Dong(eB1-4)         Modify ITC-1122-0080 
             res1 = true;
         }
         else
         {
             res1 = false;
         }
     }
     if (isJoinSQL)
     {
         bool res2 = false;
         lock (_cacheForTaFSyncObj)
         {
             if (_cacheForTaF.ContainsKey(methodId))
             {
                 IList<TableAndFields> lst = new List<TableAndFields>();
                 foreach (TableAndFields item in _cacheForTaF[methodId])
                 {
                     lst.Add(new TableAndFields(item));
                 }
                 tblAndFldses = lst.ToArray();
                 res2 = true;
             }
             else
             {
                 res2 = false;
             }
         }
         return res1 && res2;
     }
     else
         return res1;
 }
Example #7
0
File: DB.cs Project: wra222/testgit
 internal static bool PeerTheSQL(int methodId, out SQLContext sqlCntxt, out TableAndFields[] tblAndFldses)
 {
     return PeerTheSQL_Inner(methodId, out sqlCntxt, true, out tblAndFldses);
 }
Example #8
0
File: DB.cs Project: wra222/testgit
 internal static bool PeerTheSQL(int methodId, out SQLContext sqlCntxt)
 {
     TableAndFields[] tmp = null;
     return PeerTheSQL_Inner(methodId, out sqlCntxt, false, out tmp);
 }
Example #9
0
File: DB.cs Project: wra222/testgit
 public static SQLContext ToOld(SQLContextNew item)
 {
     SQLContext ret = new SQLContext();
     ret.Sentence = item.Sentence;
     item.FillIndexes(ret.Indexes);
     item.FillParams(ret.Params);
     return ret;
 }
Example #10
0
File: DB.cs Project: wra222/testgit
        public SQLContext(SQLContext orig)
        {
            this.Sentence = orig.Sentence;

            foreach (KeyValuePair<string, SqlParameter> item in orig.Params)
            {
                this.Params.Add(item.Key, (SqlParameter)((ICloneable)item.Value).Clone());
            }
            foreach (KeyValuePair<string, int> item in orig.Indexes)
            {
                this.Indexes.Add(item.Key, item.Value);
            }
        }