Example #1
0
 public NoSqlCommand(string sqlText, DbBase dbBase)
 {
     try
     {
         if (string.IsNullOrEmpty(sqlText))
         {
             return;
         }
         sourceSql = sqlText;
         ss        = SqlSyntax.Analyze(sqlText);
     }
     catch (Exception err)
     {
         Log.WriteLogToTxt(err);
     }
     if (ss.IsSelect || ss.IsUpdate || ss.IsDelete || ss.IsInsert)
     {
         MDataRow row = new MDataRow();
         if (TableSchema.FillTableSchema(ref row, ref dbBase, ss.TableName, ss.TableName))
         {
             row.Conn = dbBase.conn;
             action   = new NoSqlAction(ref row, ss.TableName, dbBase.Con.DataSource, dbBase.dalType);
         }
     }
     else
     {
         Log.WriteLogToTxt("NoSql Grammar Error Or No Support : " + sqlText);
     }
 }
Example #2
0
 public NoSqlCommand(string sqlText, DbBase dbBase)
 {
     try
     {
         sourceSql = sqlText;
         FormatSqlText(sqlText);
     }
     catch (Exception err)
     {
         Log.WriteLogToTxt(err);
     }
     if (IsSelect || IsUpdate || IsDelete || IsInsert)
     {
         MDataRow row = new MDataRow();
         if (TableSchema.FillTableSchema(ref row, ref dbBase, tableName, tableName))
         {
             row.Conn = dbBase.conn;
             action = new NoSqlAction(ref row, tableName, dbBase.Con.DataSource, dbBase.dalType);
         }
     }
     else
     {
         Log.WriteLogToTxt("NoSql Grammar Error Or No Support : " + sqlText);
     }
 }
Example #3
0
            private static void SetDefault()
            {
                DbBase db = DalCreate.CreateDal(DefaultConn);

                if (db != null)
                {
                    _DefaultDataBase = db.DataBase;
                    _DefaultDalType  = db.dalType;
                    db.Dispose();
                }
            }
Example #4
0
        //private const string SqlClient = "System.Data.SqlClient";
        //private const string OleDb = "System.Data.OleDb";
        //private const string OracleClient = "System.Data.OracleClient";
        //private const string SQLiteClient = "System.Data.SQLite";
        //private const string MySqlClient = "MySql.Data.MySqlClient";
        //private const string SybaseClient = "Sybase.Data.AseClient";
        //private const string PostgreClient = "System.Data.NpgSqlClient";
        //private const string TxtClient = "CYQ.Data.TxtClient";
        //private const string XmlClient = "CYQ.Data.XmlClient";
        //private const string XHtmlClient = "CYQ.Data.XHtmlClient";

        /// <summary>
        /// ¼òµ¥¹¤³§£¨Factory Method£©
        /// </summary>
        /// <param name="dbConn"></param>
        /// <returns></returns>
        public static DbBase CreateDal(string connNameOrString)
        {
            //ABCConn
            DbBase db = GetDbBaseBy(ConnObject.Create(connNameOrString));

            if (db.connObject.Master.ConnName != connNameOrString && connNameOrString.EndsWith("Conn"))//ÐèÒªÇл»ÅäÖá£
            {
                //Conn  A¿â
                //BConn  xxx ÕÒ²»µ½Ê±£¬ÕÒĬÈÏ¿â¡£
                DbResetResult result = db.ChangeDatabase(connNameOrString.Substring(0, connNameOrString.Length - 4));
                if (result == DbResetResult.Yes) // дÈ뻺´æ
                {
                    db.connObject.SaveToCache(connNameOrString);
                }
            }
            return(db);
        }
Example #5
0
 /// <summary>
 /// Dispose
 /// <para>释放资源</para>
 /// </summary>
 public void Dispose()
 {
     hasDisposed = true;
     if (dalHelper != null)
     {
         if (!dalHelper.IsOnExceptionEventNull)
         {
             dalHelper.OnExceptionEvent -= new DbBase.OnException(helper_OnExceptionEvent);
         }
         _debugInfo = dalHelper.debugInfo.ToString();
         dalHelper.Dispose();
         dalHelper = null;
     }
     if (_noSqlCommand != null)
     {
         _noSqlCommand.Dispose();
     }
 }
Example #6
0
 private void SetDbBase(DbBase dbBase)
 {
     dalHelper = dbBase;
     if (dalHelper.IsOnExceptionEventNull)
     {
         dalHelper.OnExceptionEvent += new DbBase.OnException(helper_OnExceptionEvent);
     }
     switch (dalHelper.dalType)
     {
     case DalType.Txt:
     case DalType.Xml:
         _noSqlCommand = new NoSqlCommand(_procName, dalHelper);
         break;
     }
     //Aop.IAop myAop = Aop.InterAop.Instance.GetFromConfig();//试图从配置文件加载自定义Aop
     //if (myAop != null)
     //{
     //    SetAop(myAop);
     //}
 }
Example #7
0
        /// <summary>
        /// 简单工厂(Factory Method)
        /// </summary>
        /// <param name="dbConn"></param>
        /// <returns></returns>
        public static DbBase CreateDal(string dbConn)
        {
            DbBase db = GetDbBaseBy(GetConnObject(dbConn));

            if (db.connObject.Master.ConfigName != dbConn && dbConn.EndsWith("Conn"))//需要切换配置。
            {
                DbResetResult result = db.ChangeDatabase(dbConn.Substring(0, dbConn.Length - 4));
                if (result == DbResetResult.Yes) // 写入缓存
                {
                    if (!connDicCache.ContainsKey(dbConn))
                    {
                        connDicCache.Set(dbConn, db.connObject);
                    }
                }
            }
            return(db);
            //ConnEntity cEntity = GetConnString(dbConn);
            //DbBase db = GetDbBaseBy(cEntity.Conn, cEntity.ProviderName);
            //db.connObject = cEntity;
            //return db;
        }
Example #8
0
        //public string TryTestConn()
        //{
        //    string err;
        //    return TryTestConn(out err);
        //}
        public string TryTestConn()
        {
            string version = string.Empty;

            //err = string.Empty;
            if (!string.IsNullOrEmpty(Conn))
            {
                DbBase helper = DalCreate.CreateDal(Conn);
                try
                {
                    helper.Con.Open();
                    version = helper.Con.ServerVersion;
                    if (string.IsNullOrEmpty(version))
                    {
                        version = helper.dalType.ToString();
                    }
                    helper.Con.Close();
                    IsOK     = true;
                    ErrorMsg = string.Empty;
                }
                catch (Exception er)
                {
                    ErrorMsg = er.Message;
                    //err = er.Message;
                    IsOK = false;
                }
                finally
                {
                    helper.Dispose();
                }
            }
            else
            {
                IsOK = false;
            }
            return(version);
        }
Example #9
0
 internal MProc(DbBase dbBase)
 {
     _procName = string.Empty;
     _conn     = dbBase.conn;
     SetDbBase(dbBase);
 }