コード例 #1
0
        public int ExcuteSQL(string strSQL, ParamMap param)
        {
            object         val         = 0;
            IDbTransaction transaction = null;
            IDbConnection  connection  = null;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                connection = GetConnection();
                {
                    connection = GetConnection();

                    IDbDataParameter[] parms = param.toDbParameters();

                    if (AdoHelper.DbType == DatabaseType.ACCESS)
                    {
                        strSQL = SQLBuilderHelper.builderAccessSQL(strSQL, parms);
                        val    = AdoHelper.ExecuteNonQuery(connection, transaction, CommandType.Text, strSQL);
                    }
                    else
                    {
                        val = AdoHelper.ExecuteNonQuery(connection, transaction, CommandType.Text, strSQL, parms);
                    }
                }
            }
            catch (Exception e)
            {
                DBLOG.error(strSQL, e);
            }
            return(Convert.ToInt32(val));
        }
コード例 #2
0
        //数据库状态发生改变处理事件
        void conn_StateChange(object sender, StateChangeEventArgs e)
        {
            state = e.CurrentState;

            DBLOG.warn("Session数据库>>>>新状态=" + e.CurrentState);

            if (e.CurrentState == ConnectionState.Closed)
            {
                _connect.Open();
                Thread.Sleep(1000);
            }
            else if (e.CurrentState == ConnectionState.Broken)
            {
                Thread.Sleep(1000);
                _connect.Close();
                _connect.Open();
            }
        }
コード例 #3
0
 public void Open()
 {
     if (_connect == null)
     {
         DBLOG.log(_connectionString);
         _connect = DbFactory.CreateDbConnection(_connectionString);
         (_connect as MySqlConnection).StateChange += conn_StateChange;
         _connect.Open();
     }
     else if (state == ConnectionState.Closed)
     {
         _connect.Open();
     }
     else if (state == ConnectionState.Broken)
     {
         _connect.Close();
         _connect.Open();
     }
 }
コード例 #4
0
        public List <T> Find <T>(string sql) where T : TbLogic, new()
        {
            List <T>     list = new List <T>();
            MySqlCommand cmd  = new MySqlCommand(sql, (MySqlConnection)GetConnection());

            DBLOG.log(sql);
            TableInfo       dic = getInfo(typeof(T));
            MySqlDataReader sdr = cmd.ExecuteReader();

            try
            {
                while (sdr.Read())
                {
                    T entity = new T();
                    foreach (ColomnInfo co in dic.colomns.Values)
                    {
                        String name = co.columnName;
                        if (CheckColumnName(sdr, name) == true)
                        {
                            if (sdr[name] is MySqlDateTime)
                            {
                                co.proptoty.SetValue(entity, ((MySqlDateTime)sdr[name]).GetDateTime(), null);
                            }
                            else
                            {
                                co.proptoty.SetValue(entity, sdr[name], null);
                            }
                        }
                    }
                    entity.changedKeys.Clear();//清理
                    list.Add(entity);
                }
            }
            finally
            {
                if (!sdr.IsClosed)
                {
                    sdr.Close();
                }
            }
            return(list);
        }
コード例 #5
0
        public int Count(string strSQL)
        {
            int           count      = 0;
            IDbConnection connection = null;

            try
            {
                connection = GetConnection();
                {
                    connection = GetConnection();
                    count      = Execute(strSQL);
                }
            }
            catch (Exception ex)
            {
                DBLOG.error(strSQL, ex);
            }

            return(count);
        }
コード例 #6
0
        private int Execute(MySqlCommand cmd)
        {
            DBLOG.log(cmd.CommandText);
            IDbConnection conn = this.GetConnection();

            cmd.Connection = conn as MySqlConnection;

            int re = 0;

            try
            {
                re = cmd.ExecuteNonQuery();

                /*
                 * StringBuilder str = new StringBuilder();
                 * //cmd.Parameters.RemoveAt("item");
                 * foreach (MySqlParameter o in cmd.Parameters)
                 * {
                 *  str.Append(o.ParameterName).Append("=").Append(o.Value.ToString()).Append("&");
                 * }
                 * DBLOG.log(str.ToString());*/
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错3:", mysqle);// + JSON.Encode(cmd.Parameters),mysqle);

                StringBuilder str = new StringBuilder();
                //cmd.Parameters.RemoveAt("item");
                foreach (MySqlParameter o in cmd.Parameters)
                {
                    str.Append(o.ParameterName).Append("=").Append(o.Value.ToString());
                }
                DBLOG.error(str.ToString());
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错4" + ioe.Message, ioe);
                conn.Close();
            }
            return(re);
        }
コード例 #7
0
        private int Execute(string sql)
        {
            DBLOG.log("Execute:" + sql);
            IDbConnection conn = this.GetConnection();
            int           re   = 0;
            MySqlCommand  cmd  = new MySqlCommand(sql, (MySqlConnection)conn);

            try
            {
                re = cmd.ExecuteNonQuery();
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错3:", mysqle);
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错4", ioe);
                conn.Close();
            }

            return(re);
        }
コード例 #8
0
        public int ExcuteSQL(string strSQL)
        {
            int val = 0;

            DBLOG.log("ExcuteSQL>" + strSQL);
            IDbConnection connection = null;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                connection = GetConnection();
                val        = new MySqlCommand(strSQL, connection as MySqlConnection).ExecuteNonQuery();// AdoHelper.ExecuteNonQuery(connection, null, CommandType.Text, strSQL);
            }
            catch (MySqlException mysqle)
            {
                DBLOG.error("出错ExcuteSQL:", mysqle);
            }
            catch (System.IO.IOException ioe)
            {
                DBLOG.error("出错5", ioe);
                connection.Close();
            }
            return(val);
        }
コード例 #9
0
        public int Insert <T>(List <T> entityList)
        {
            if (entityList == null || entityList.Count == 0)
            {
                return(0);
            }

            int val = 0;

            try
            {
                //获取数据库连接,如果开启了事务,从事务中获取
                foreach (T t in entityList)
                {
                    val += Insert <T>(t);
                }
            }
            catch (Exception e)
            {
                DBLOG.error("Insert=" + entityList, e);
            }

            return(val);
        }