예제 #1
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        ///////////////////////
        public bool Execute(string sSQL)
        {
            bool needDb = false;

            try
            {
                if (sql_cmd == null)
                {
                    sql_cmd = sql_con.CreateCommand();
                }
                sql_cmd.CommandText = sSQL;
                try
                {
                    sql_cmd.ExecuteNonQuery();
                }
                catch (System.Data.Common.DbException dbx)
                {
                    needDb = DBMain.DBExceptionHandler(dbx, sSQL);
                }
            }
            catch (Exception caught)
            {
                try
                {
                    DBMain.AltLog(LogLevels.Warning, 70101, "Execute '" + caught.Message + "' " + sSQL);

                    return(false);
                }
                catch { }
            }
            return(true);
        }
예제 #2
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        public string Scalar(string sSQL)
        {
            string sData = "";

            try
            {
                sql_con.Open();
                sql_cmd             = sql_con.CreateCommand();
                sql_cmd.CommandText = sSQL;
                var o = sql_cmd.ExecuteScalar();
                if (o != null)
                {
                    sData = o.ToString();
                }
            }
            catch (System.Data.Common.DbException dbx)
            {
                DBMain.DBExceptionHandler(dbx, sSQL);
            }
            catch (Exception caught)
            {
                try
                {
                    DBMain.AltLog(LogLevels.Warning, 70104, "Scalar  '" + caught.Message + "' " + sSQL);
                    sql_con.Close();
                    return(null);
                }
                catch { }
            }
            sql_con.Close();
            return(sData);
        }
예제 #3
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        // assumes DB is there, but might need to build it before we get here
        public bool Execute(string sSQL)
        {
            bool needDb = false;

            try
            {
                sql_con.Open();
                sql_cmd             = sql_con.CreateCommand();
                sql_cmd.CommandText = sSQL;
                try
                {
                    int i = sql_cmd.ExecuteNonQuery();
                }
                catch (System.Data.Common.DbException dbx)
                {
                    needDb = DBMain.DBExceptionHandler(dbx, sSQL);
                }
            }
            catch (Exception caught)
            {
                try
                {
                    DBMain.AltLog(LogLevels.Warning, 70101, "Execute '" + caught.Message + "' " + sSQL);
                    sql_con.Close();
                    return(false);
                }
                catch { }
            }
            if (sql_con != null)
            {
                sql_con.Close();
            }
            if (needDb)
            {
                DBMain.Creation(sql_cmd);  // create an new empty DB, pass the failed query string, retry it once after initial DB creation
            }
            return(true);
        }
예제 #4
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        public long ExecuteTransactionID(ArrayList sqlList)
        {
            //Execute Sequence of Sql Statements
            //Check Sql Type to determine if we have return value to replace in next statement
            DbTransaction Trans  = null;
            string        sRtn   = "";
            Int32         result = -1; // what to return here?

            try
            {
                sql_con.Open();
                Trans = sql_con.BeginTransaction();

                sql_cmd             = sql_con.CreateCommand();
                sql_cmd.Transaction = Trans;
                bool needDb = false; bool scalar = false;
                for (int i = 0; i < sqlList.Count; i++)
                {
                    if (!sqlList[i].ToString().Equals(""))
                    {
                        sql_cmd.CommandText = sqlList[i].ToString();
                        //DBMain.AltLog(LogLevels.Info, 70115, "sql => " + sql_cmd.CommandText);
                        try
                        {
                            if (sqlList[i].ToString().ToUpper().StartsWith("SELECT"))
                            {
                                //Expect back a string
                                scalar = true;
                                sRtn   = sql_cmd.ExecuteScalar().ToString();
                                if (sRtn.Equals(""))
                                {
                                    Trans.Rollback();
                                    sql_con.Close();
                                    return(-1);
                                }
                            }
                            else
                            {
                                scalar = false;
                                if (sql_cmd.CommandText.Contains("<Rtn>"))
                                {
                                    //substitute in sRtn Value
                                    sql_cmd.CommandText = sql_cmd.CommandText.Replace("<Rtn>", sRtn);
                                }
                                //Expect back # rows modified
                                if (sql_cmd.ExecuteNonQuery() < 0)
                                {
                                    Trans.Rollback();
                                    sql_con.Close();
                                    return(-1);
                                }
                            }
                        }
                        catch (System.Data.Common.DbException dbx)
                        {
                            Trans.Rollback();
                            needDb = DBMain.DBExceptionHandler(dbx, sql_cmd.CommandText);
                            sql_con.Close();
                            return(-1);
                        }
                        if (needDb)
                        {
                            DBMain.Creation(sql_cmd, scalar);  // create a new empty DB, pass the failed query string, retry it once after initial DB creation
                        }
                    }
                }
                Trans.Commit();
                sql_con.Close();

                Int32.TryParse(sRtn, out result);
                return(result);
            }
            catch (Exception caught)
            {
                if (sql_cmd != null)
                {
                    DBMain.AltLog(LogLevels.Warning, 70107, "ExecuteTransactionID  '" + caught.Message + "' " + sql_cmd);
                }
                if (Trans != null)
                {
                    Trans.Rollback();
                }
                if (sql_con != null)
                {
                    sql_con.Close();
                }
                return(-1);
            }
        }
예제 #5
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        public bool ExecuteTransaction(ArrayList sqlList)
        {
            //Execute Sequence of Sql Statements
            //Check Sql Type to determine if we have return value to replace in next statement

            DbTransaction Trans = null;
            string        sRtn  = "";

            try
            {
                Trans = sql_con.BeginTransaction();
                if (sql_cmd == null)
                {
                    sql_cmd = sql_con.CreateCommand();
                }

                sql_cmd.Transaction = Trans;
                bool needDb = false;
                for (int i = 0; i < sqlList.Count; i++)
                {
                    sql_cmd.CommandText = sqlList[i].ToString();
                    try
                    {
                        if (sqlList[i].ToString().ToUpper().StartsWith("SELECT"))
                        {
                            //Expect back a string
                            sRtn = sql_cmd.ExecuteScalar().ToString();
                            if (sRtn.Equals(""))
                            {
                                Trans.Rollback();

                                return(false);
                            }
                        }
                        else
                        {
                            if (sql_cmd.CommandText.Contains("<Rtn>"))
                            {
                                //substitute in sRtn Value
                                sql_cmd.CommandText = sql_cmd.CommandText.Replace("<Rtn>", sRtn);
                            }

                            //Expect back # rows modified
                            if (sql_cmd.ExecuteNonQuery() < 0)
                            {
                                Trans.Rollback();

                                return(false);
                            }
                        }
                    }
                    catch (System.Data.Common.DbException dbx)
                    {
                        needDb = DBMain.DBExceptionHandler(dbx, sql_cmd.CommandText);
                    }
                }
                Trans.Commit();

                return(true);
            }
            catch (Exception caught)
            {
                if (sql_cmd != null)
                {
                    DBMain.AltLog(LogLevels.Warning, 70107, "ExecuteTransaction  '" + caught.Message + "' " + sql_cmd);
                }
                if (Trans != null)
                {
                    Trans.Rollback();
                }
                return(false);
            }
        }
예제 #6
0
파일: DB.cs 프로젝트: tempbottle/INCC6
        public int Execute(ArrayList sqlList)
        {
            //Execute Sequence of Sql Statements
            //Check Sql Type to determine if we have return value to replace in next statement

            string sRtn   = "";
            Int32  result = -1; // what to return here?

            try
            {
                if (sql_cmd == null)
                {
                    sql_cmd = sql_con.CreateCommand();
                }

                bool needDb = false;
                for (int i = 0; i < sqlList.Count; i++)
                {
                    if (!sqlList[i].ToString().Equals(""))
                    {
                        sql_cmd.CommandText = sqlList[i].ToString();
                        try
                        {
                            if (sqlList[i].ToString().ToUpper().StartsWith("SELECT"))
                            {
                                //Expect back a string
                                sRtn = sql_cmd.ExecuteScalar().ToString();
                                if (sRtn.Equals(""))
                                {
                                    return(-1);
                                }
                            }
                            else
                            {
                                if (sql_cmd.CommandText.Contains("<Rtn>"))
                                {
                                    //substitute in sRtn Value
                                    sql_cmd.CommandText = sql_cmd.CommandText.Replace("<Rtn>", sRtn);
                                }
                                //Expect back # rows modified
                                if (sql_cmd.ExecuteNonQuery() < 0)
                                {
                                    return(-1);
                                }
                            }
                        }
                        catch (System.Data.Common.DbException dbx)
                        {
                            needDb = DBMain.DBExceptionHandler(dbx, sql_cmd.CommandText);
                        }
                    }
                }

                Int32.TryParse(sRtn, out result);
                return(result);
            }
            catch (Exception caught)
            {
                if (sql_cmd != null)
                {
                    DBMain.AltLog(LogLevels.Warning, 70107, "Execute list  '" + caught.Message + "' " + sql_cmd);
                }
                return(-1);
            }
        }