コード例 #1
0
ファイル: ResourceManager.cs プロジェクト: jiaping/JPCMS
        public void ExcuteSQL(BaseConfigInfo bci, string updateFile)
        {
            if (updateFile != "")
            {
                string      connectionString = bci.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory);
                XmlDocument doc = new XmlDocument();
                doc.Load(updateFile);

                foreach (XmlNode node in doc.SelectNodes("/Update/Database"))
                {
                    IDbDriver dbDriver = CreateDbDriver(bci.DBType);
                    if (dbDriver == null)
                    {
                        continue;
                    }

                    //开始处理

                    int success = 0;
                    int errors  = 0;
                    using (IConnection conn = dbDriver.CreateConnection(connectionString))
                    {
                        foreach (XmlNode sub in node.SelectNodes("Sql"))
                        {
                            if (sub == null || String.IsNullOrEmpty(sub.InnerText) || String.IsNullOrEmpty(sub.InnerText.Trim()))
                            {
                                continue;
                            }
                            //读取SQL语句,逐一执行
                            SqlStatement sql = new SqlStatement();
                            sql.CommandType = System.Data.CommandType.Text;
                            sql.SqlClause   = sub.InnerText.Trim();
                            dbDriver.FormatSQL(sql);
                            try
                            {
                                conn.Update(sql);
                                success++;
                            }
                            catch (Exception ex)
                            {
                                //出现了错误,我们继续执行

                                We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_plugin_update,
                                                                     "执行SQL:" + sql.SqlClause, ex.Message);
                                errors++;
                                continue;
                            }
                        }
                    }


                    We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_plugin_update.ToString(),
                                                         "执行完毕:",
                                                         string.Format("{3}执行完毕!共执行语句{0}条,成功{1},失败{2} 。", success + errors, success, errors, updateFile));
                }
            }
        }
コード例 #2
0
ファイル: Installer.cs プロジェクト: vebin/We7CMS_2010
        public static void ExecuteSQL(BaseConfigInfo bci, string file)
        {
            if (file != "" && File.Exists(file))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(file);
                foreach (XmlNode node in doc.SelectNodes("/Update/Database"))
                {
                    IDbDriver driver = CreateDbDriver(bci.DBType);
                    if (driver == null)
                    {
                        continue;
                    }
                    int success = 0;
                    int errors  = 0;

                    using (IConnection conn = driver.CreateConnection(bci.DBConnectionString))
                    {
                        foreach (XmlNode sub in node.SelectNodes("Sql"))
                        {
                            SqlStatement sql = new SqlStatement();
                            sql.CommandType = CommandType.Text;
                            sql.SqlClause   = sub.InnerText;
                            driver.FormatSQL(sql);
                            try
                            {
                                conn.Update(sql);
                                success++;
                            }
                            catch (Exception ex)
                            {
                                We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_update,
                                                                     "执行SQL:" + sql.SqlClause + "\n\t 出现错误:", ex.Message);
                                errors++;
                                continue;
                            }
                        }
                    }
                    We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_update, "执行完毕:", string.Format("{3}执行完毕!共执行语句{0}条,成功{1}条,失败{2}条", success + errors, success, errors, file));
                }
            }
        }