//using Dapper; //using MySql.Data.MySqlClient; //using System; //using System.Collections.Generic; //using System.Data; //using System.Linq; //using System.Text; //using System.Threading.Tasks; //namespace Winsoft.GOV.XF.WebApi.WXCore.DBProvider //{ // public class DBConfig // { // public static string DefaultConnectionString { get; set; } // } // public class BaseDBProvider // { // #region instance // private static object lockObj = new object(); // private static string createWXUser = "CREATE TABLE IF NOT EXISTS `wxuser` (" + // " `id` INT GENERATED ALWAYS AS(0)," + // " `openid` VARCHAR(64) NOT NULL," + // " `mobile` VARCHAR(11) NULL," + // " `email` VARCHAR(100) NULL," + // " UNIQUE INDEX `openid_UNIQUE` (`openid` ASC)," + // " PRIMARY KEY(`id`));"; // private static string createWXBatch = "CREATE TABLE IF NOT EXISTS `wxbatch` (" + // " `id` VARCHAR(64) NOT NULL," + // " `decribe` VARCHAR(500) NULL," + // " PRIMARY KEY(`id`));"; // private static string createWXResource = "CREATE TABLE IF NOT EXISTS `wxresource` (" + // " `id` VARCHAR(64) NOT NULL," + // " `batchId` VARCHAR(64) NOT NULL," + // " `url` VARCHAR(500) NULL," + // " PRIMARY KEY(`id`));"; // protected static void CreateInstance(ref K singleInstance) where K : BaseDBProvider, new() // { // if (singleInstance == null) // { // lock (lockObj) // { // if (singleInstance == null) // { // singleInstance = new K(); // } // } // } // } // #endregion // #region connection // public BaseDBProvider() // { // } // /// // /// // /// // /// // protected IDbConnection GetDbConnection() // { // var connection = new MySqlConnection // { // ConnectionString = DBConfig.DefaultConnectionString // }; // connection.Open(); // return connection; // } // protected string BuildTotalSQL(string sql) // { // var selectCount = new StringBuilder("SELECT COUNT(1) from ("); // return // selectCount.Append(sql + ") as t") // .ToString(); // } // /// // /// // /// // /// // /// 内部索引从0开始,页码从1开始 // /// // /// if (pageIndex - 1 >= 0) // /// { // /// pageIndex = pageIndex - 1; // /// } // /// // /// // /// // /// // /// // //protected PagedResult GetPagedList(string sql, int pageIndex, int pageSize, object param) // //{ // // long total = 0; // // pageIndex -= 1; // // if (pageIndex < 0) // // { // // pageIndex = 0; // // } // // if (pageSize <= 0) // // { // // pageSize = 20; // // } // // using (IDbConnection connection = GetDbConnection()) // // { // // string totalSql = BuildTotalSQL(sql); // // total = connection.Query(totalSql, param).FirstOrDefault(); // // var list = connection.Query(String.Format(sql + " limit {0},{1}", pageIndex * pageSize, pageSize), param); // // return new PagedResult(list, pageIndex + 1, pageSize, total); // // } // //} // protected IEnumerable GetItemList(string sql, int itemIndex, int pageSize, object param) // { // if (itemIndex < 0) // { // itemIndex = 0; // } // if (pageSize <= 0) // { // pageSize = 20; // } // using (IDbConnection connection = GetDbConnection()) // { // var list = connection.Query(String.Format(sql + " limit {0},{1}", itemIndex, pageSize), param); // return list; // } // } // #endregion // } //}