public bool isExist <T>(T dest) { var databaseName = GetDBName(dest); var isRemoveAutoIncrement = true; var tableName = NeetCommonMethod.CamelToSnake(dest.GetType().Name); var pkdic = this.ToDictionaryProperty(true, !isRemoveAutoIncrement); //SQL生成 var where = SQLCreater.CreateWhereSQLByDictionary(pkdic, databaseName, tableName); var select = SQLCreater.MasterAllGetSQL(databaseName, tableName); var sb = new StringBuilder(); sb.AppendLine(select); sb.AppendLine(where); NameValueCollection Values = new NameValueCollection(); Values["sql"] = sb.ToString(); Handler.URL = Handler.SelectURL; var jsonStr = Handler.DoPost(Values); var res = Handler.ConvertDeserialize(jsonStr); //存在する return(res.Count > 0); }
static void TestSQLSelect() { Handler.URL = connectionStringTest; var values = new NameValueCollection(); values["sql"] = SQLCreater.MasterAllGetSQL(DB, "m_creature"); string result = Handler.DoPost(values); var dic = Handler.ConvertDeserialize(result); }
public BaseQuerist(IOptions <DapperOptions> options) { var type = typeof(TEntity); var attr = type.GetCustomAttribute <TableAttribute>(); TableName = attr != null ? attr.Name : type.Name; TableSchema = attr != null ? attr.Schema : string.Empty; _creater = new SQLCreater(options); _creater.TableName = TableName; _creater.TableSchema = TableSchema; }
static void TestSQLUpdate() { Handler.URL = connectionStringInsert; var values = new NameValueCollection(); var dic = new Dictionary <string, object>(); dic.Add("id", "4"); dic.Add("name", "test4update"); dic.Add("passWord", "test"); values["sql"] = SQLCreater.CreateUpdateSQLByDictionary(dic, "PakuPakuDB", "m_player", "id=4"); string result = Handler.DoPost(values); //var res = Handler.ConvertDeserialize(result); }
static public List <T> GetFindAll <T>(T dest) { var databaseName = GetDBName(dest); var tableName = NeetCommonMethod.CamelToSnake(dest.GetType().Name); var select = SQLCreater.MasterAllGetSQL(databaseName, tableName); NameValueCollection Values = new NameValueCollection(); Values["sql"] = select; Handler.URL = Handler.SelectURL; var jsonStr = Handler.DoPost(Values); var res = Handler.ConvertDeserialize(jsonStr); var list = res.Select(x => DictionaryToClass <T>(x)).ToList(); var result = list; return(result); }
/// <summary> /// 汎用更新メソッド(追加・更新を自動判定) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dest"></param> /// <param name="databaseName"></param> public void Register <T>(T dest) { //存在チェック var isInsert = !isExist(dest); var databaseName = GetDBName(dest); var tableName = NeetCommonMethod.CamelToSnake(dest.GetType().Name); var isRemoveAutoIncrement = true; var dic = this.ToDictionaryProperty(false, !isRemoveAutoIncrement); var pkdic = this.ToDictionaryProperty(true, isRemoveAutoIncrement); var where = SQLCreater.CreateWhereSQLByDictionary(pkdic, databaseName, tableName); var sql = isInsert ? SQLCreater.CreateInsertSQLByDictionary(dic, databaseName, tableName) : SQLCreater.CreateUpdateSQLByDictionary(dic, databaseName, tableName, where) ; NameValueCollection Values = new NameValueCollection(); Values["sql"] = sql; Handler.URL = Handler.InsertAndUpdateURL; Handler.DoPost(Values); }