private void TranslateCommandTree(DbCommandTree commandTree, DbCommand command) { SqlBaseGenerator sqlGenerator = null; DbQueryCommandTree select; DbInsertCommandTree insert; DbUpdateCommandTree update; DbDeleteCommandTree delete; if ((select = commandTree as DbQueryCommandTree) != null) { sqlGenerator = new SqlSelectGenerator(select); } else if ((insert = commandTree as DbInsertCommandTree) != null) { sqlGenerator = new SqlInsertGenerator(insert); } else if ((update = commandTree as DbUpdateCommandTree) != null) { sqlGenerator = new SqlUpdateGenerator(update); } else if ((delete = commandTree as DbDeleteCommandTree) != null) { sqlGenerator = new SqlDeleteGenerator(delete); } else { // TODO: get a message (unsupported DbCommandTree type) throw new ArgumentException(); } sqlGenerator.BuildCommand(command); }
// 返回账号acc的余额 public static long getRemainMoney(string acc, bool isPlayer, GMUser user) { string sql = ""; SqlSelectGenerator gen = new SqlSelectGenerator(); gen.addField("money"); if (isPlayer) { sql = gen.getResultSql(TableName.PLAYER_ACCOUNT_XIANXIA, string.Format("acc='{0}'", acc)); } else { sql = gen.getResultSql(TableName.GM_ACCOUNT, string.Format("acc='{0}'", acc)); } Dictionary <string, object> data = user.sqlDb.queryOne(sql, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); if (data == null) { return(0); } return(Convert.ToInt64(data["money"])); }
public virtual IEnumerable <TEntity> GetWhere(object filters, int pageNumber, int pageSize) { var sql = SqlSelectGenerator.GetSelect(filters, pageSize, pageNumber); using (var connection = DbConnectionFactory.CreateConnection()) { return(connection.Query <TEntity>(sql, filters)); } }
/// <summary> /// /// </summary> /// <returns></returns> public virtual async Task <IEnumerable <TEntity> > GetAllAsync() { using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); var sql = SqlSelectGenerator.GetSelectAll(); return(await connection.QueryAsync <TEntity>(sql, null)); } }
/// <summary> /// /// </summary> /// <param name="filters"></param> /// <returns></returns> public virtual IEnumerable <TEntity> GetWhere(object filters) { var sql = SqlSelectGenerator.GetSelect(filters); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); return(connection.Query <TEntity>(sql, filters)); } }
/// <summary> /// /// </summary> /// <returns></returns> public virtual IEnumerable <TEntity> GetAll() { var sql = SqlSelectGenerator.GetSelectAll(); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); return(connection.Query <TEntity>(sql)); } }
public virtual async Task <IEnumerable <TEntity> > GetWhereAsync(object filters, int pageNumber, int pageSize) { var sql = SqlSelectGenerator.GetSelect(filters, pageSize, pageNumber); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); return(await connection.QueryAsync <TEntity>(sql, filters)); } }
public virtual int GetCount(object filters) { var sql = SqlSelectGenerator.GetCount(filters); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); return(connection.Query <int>(sql, filters).Single()); } }
/// <summary> /// /// </summary> /// <param name="filters"></param> /// <returns></returns> public virtual async Task <TEntity> GetFirstAsync(object filters) { var sql = SqlSelectGenerator.GetSelect(filters); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); Task <IEnumerable <TEntity> > queryTask = connection.QueryAsync <TEntity>(sql, filters); IEnumerable <TEntity> data = await queryTask; return(data.FirstOrDefault()); } }
public virtual async Task <int> GetCountAsync(object filters) { var sql = SqlSelectGenerator.GetCount(filters); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); var result = await connection.QueryAsync <int>(sql, filters); return(result.Single()); } }
// 返回玩家账号余额 public long getRemainMoney(string acc) { SqlSelectGenerator gen = new SqlSelectGenerator(); gen.addField("money"); string sql = gen.getResultSql(TableName.PLAYER_ACCOUNT_XIANXIA, string.Format("acc='{0}'", acc)); Dictionary <string, object> data = m_sqlDb.queryOne(sql, CMySqlDbName.DB_XIANXIA); if (data == null) { return(0); } return(Convert.ToInt64(data["money"])); }
internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandTree, DbCommand command, bool createParametersForNonSelect = true) { SqlBaseGenerator sqlGenerator; DbQueryCommandTree select; DbInsertCommandTree insert; DbUpdateCommandTree update; DbDeleteCommandTree delete; DbFunctionCommandTree function; if ((select = commandTree as DbQueryCommandTree) != null) { sqlGenerator = new SqlSelectGenerator(select); } else if ((insert = commandTree as DbInsertCommandTree) != null) { sqlGenerator = new SqlInsertGenerator(insert); } else if ((update = commandTree as DbUpdateCommandTree) != null) { sqlGenerator = new SqlUpdateGenerator(update); } else if ((delete = commandTree as DbDeleteCommandTree) != null) { sqlGenerator = new SqlDeleteGenerator(delete); } else if ((function = commandTree as DbFunctionCommandTree) != null) { sqlGenerator = new SqlFunctionGenerator(function); } else { // TODO: get a message (unsupported DbCommandTree type) throw new ArgumentException(); } sqlGenerator.CreateParametersForConstants = select == null && createParametersForNonSelect; sqlGenerator.Command = (NpgsqlCommand)command; sqlGenerator.Version = serverVersion; sqlGenerator.BuildCommand(command); }