예제 #1
0
        public static int Execute(String query, String database)
        {
            DBSession session = new DBSession();
            MySqlConnection con = null;

            try
            {
                String ip = DBConst.kDbIp;
                con = session.CreateConnection(ip, database);
                con.Open();

                MySqlCommand cmd = new MySqlCommand(query, con);

                int ret = cmd.ExecuteNonQuery();
                return ret;
            }
            catch (System.Exception ex)
            {
                logger.Warn(ex.ToString());
            }
            finally
            {
                session.Close(con);
            }
            return -1;
        }
예제 #2
0
        public static int Execute(List<String> queires)
        {
            DBSession session = new DBSession();
            MySqlConnection con = null;

            int sum = 0;
            try
            {
                con = session.CreateConnection(DBConst.kDbIp, DBConst.kMarketDataDatabase);
                con.Open();

                MySqlCommand cmd = con.CreateCommand();
                MySqlTransaction trans = con.BeginTransaction();
                cmd.Connection = con;
                cmd.Transaction = trans;

                try
                {
                    foreach (String query in queires)
                    {
                        cmd.CommandText = query;
                        sum += cmd.ExecuteNonQuery();
                    }
                    trans.Commit();
                    return sum;
                }
                catch (System.Exception tranEx)
                {
                    logger.Warn(tranEx.ToString());
                    trans.Rollback();
                    return -1;
                }
            }
            catch (System.Exception ex)
            {
                logger.Warn(ex.ToString());
            }
            finally
            {
                session.Close(con);
            }
            return -1;
        }
예제 #3
0
        public static DataRowCollection SelectFromDB(String query)
        {
            DBSession session = new DBSession();
            MySqlConnection con = null;

            try
            {
                String ip = DBConst.kDbIp;
                con = session.CreateConnection(ip, DBConst.kMarketDataDatabase);
                con.Open();

                MySqlCommand cmd = new MySqlCommand(query, con);
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd);

                DataSet ds = new DataSet("data");

                dataAdapter.Fill(ds, "data");
                DataRowCollection drc = ds.Tables["data"].Rows;

                return drc;
            }
            catch (System.Exception ex)
            {
                logger.Warn(ex.ToString());
            }
            finally
            {
                session.Close(con);
            }
            return null;
        }