Beispiel #1
0
        /// <summary>执行SQL查询,返回总记录数</summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="type">命令类型,默认SQL文本</param>
        /// <param name="ps">命令参数</param>
        /// <returns></returns>
        public virtual Int64 QueryCount(String sql, CommandType type = CommandType.Text, params DbParameter[] ps)
        {
            if (sql.Contains(" "))
            {
                var orderBy = DbBase.CheckOrderClause(ref sql);
                //sql = String.Format("Select Count(*) From {0}", CheckSimpleSQL(sql));
                //Match m = reg_QueryCount.Match(sql);
                var ms = reg_QueryCount.Matches(sql);
                if (ms != null && ms.Count > 0)
                {
                    sql = String.Format("Select Count(*) From {0}", ms[0].Groups[1].Value);
                }
                else
                {
                    sql = String.Format("Select Count(*) From {0}", DbBase.CheckSimpleSQL(sql));
                }
            }
            else
            {
                sql = String.Format("Select Count(*) From {0}", Database.FormatName(sql));
            }

            //return QueryCountInternal(sql);
            return(ExecuteScalar <Int64>(sql, type, ps));
        }
Beispiel #2
0
        protected virtual void DropDatabase()
        {
            //首先关闭数据库
            DbBase db = Database as DbBase;

            if (db != null)
            {
                db.ReleaseSession();
            }
            else
            {
                Database.CreateSession().Dispose();
            }

            OleDbConnection.ReleaseObjectPool();
            GC.Collect();

            if (File.Exists(FileName))
            {
                File.Delete(FileName);
            }
        }