public string GetType(ESqlType type) { string result; if (type == ESqlType.INSERT) { result = "INSERT"; } else { if (type == ESqlType.UPDATE) { result = "UPDATE"; } else { if (type == ESqlType.DELETE) { result = "DELETE"; } else { result = "SELECT"; } } } return(result); }
public static DbType FromDBName(string type, ESqlType sqlType) { switch (type) { case "nvarchar": if (sqlType == ESqlType.MSSQL) { return(DbType.String); } throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); case "varchar": if (sqlType == ESqlType.MySQL || sqlType == ESqlType.MSSQL) { return(DbType.String); } throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); case "bit": if (sqlType == ESqlType.MSSQL) { return(DbType.Boolean); } throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); case "boolean": if (sqlType == ESqlType.MySQL) { return(DbType.Boolean); } throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); case "tinyint": if (sqlType == ESqlType.MySQL) { return(DbType.Boolean); } throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); case "int": return(DbType.Int32); case "float": return(DbType.Double); case "decimal": return(DbType.Decimal); case "datetime": return(DbType.DateTime); case "binary": return(DbType.Binary); default: throw new InvalidOperationException($"Unknown type: {type} for {sqlType}"); } }
public int Execute(ISqlMapper sqlMap, IEnumerable <string> sqlStatements, bool isBatch) { if (isBatch) { IList list = new ArrayList(); foreach (var item in sqlStatements) { list.Add(new { sql = item }); } return(this.BatchExecute(sqlMap, new DBState { Name = "BatchExecuteNoneQuery", Param = list })); } else { List <DBState> list = new List <DBState>(); foreach (string current in sqlStatements) { string text = current; string text2 = text.ToUpper().Trim(); ESqlType type = ESqlType.INSERT; if (text2.StartsWith(ESqlType.INSERT.ToString())) { type = ESqlType.INSERT; } else { if (text2.StartsWith(ESqlType.UPDATE.ToString())) { type = ESqlType.UPDATE; } else { if (text2.StartsWith(ESqlType.DELETE.ToString())) { type = ESqlType.DELETE; } } } list.Add(new DBState { Name = "ExecuteNoneQuery", Param = new { sql = current }, Type = type }); } return(this.Execute(sqlMap, list)); } }
public void DeleteValue(ESqlType eSqlType, string keys) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { sqlData.DeleteValue(keys); } }
public void SetFloat(ESqlType eSqlType, string key, float value) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { sqlData.SetValue_Float(key, value); } }
public void SetString(ESqlType eSqlType, string key, string values) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { sqlData.SetValue_String(key, values); } }
public void SetLong(ESqlType eSqlType, string key, long value) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { sqlData.SetValue_Long(key, value); } }
public string GetString(ESqlType eSqlType, string key, string defaultValue = "") { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { return(sqlData.GetValue_String(key, defaultValue)); } return(defaultValue); }
public long GetLong(ESqlType eSqlType, string key, long defaultValue = 0) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { return(sqlData.GetValue_Long(key, defaultValue)); } return(defaultValue); }
public float GetFloat(ESqlType eSqlType, string key, float defaultValue = 0) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { return(sqlData.GetValue_Float(key, defaultValue)); } return(defaultValue); }
public int GetInt(ESqlType eSqlType, string key, int defaultValue = 0) { SqlData sqlData; if (sqlDatas.TryGetValue(eSqlType, out sqlData)) { return(sqlData.GetValue_Int(key, defaultValue)); } return(defaultValue); }
public static DBCommandSet GetDBCommandSet(ESqlType type) { foreach (Type commandSetType in CommandSets) { DBCommandSet commandSet = (DBCommandSet)Activator.CreateInstance(commandSetType); if (commandSet.Type == type) { return(commandSet); } } throw new InvalidOperationException("Unknown ESqlType"); }
public int Execute(string sqlStatement) { ISqlMapper sqlMap = this.GetSqlMap(); string text = sqlStatement.ToUpper().Trim(); ESqlType eSqlType = ESqlType.INSERT; int resultRowNum = 0; if (text.StartsWith(ESqlType.INSERT.ToString())) { eSqlType = ESqlType.INSERT; } else { if (text.StartsWith(ESqlType.UPDATE.ToString())) { eSqlType = ESqlType.UPDATE; } else { if (text.StartsWith(ESqlType.DELETE.ToString())) { eSqlType = ESqlType.DELETE; } } } DBState dBState = new DBState { Name = "ExecuteNoneQuery", Param = sqlStatement, Type = eSqlType }; if (eSqlType == ESqlType.INSERT) { resultRowNum += sqlMap.Update(dBState.Name, dBState.Param); } else { if (eSqlType == ESqlType.UPDATE) { resultRowNum += sqlMap.Update(dBState.Name, dBState.Param); } else { resultRowNum += sqlMap.Delete(dBState.Name, dBState.Param); } } return(resultRowNum); }
public static string DBName(DbType type, ESqlType sqlType) { switch (type) { case DbType.String: if (sqlType == ESqlType.MSSQL) { return("nvarchar"); } if (sqlType == ESqlType.MySQL) { return("varchar"); } throw new InvalidOperationException(); case DbType.Boolean: if (sqlType == ESqlType.MSSQL) { return("bit"); } if (sqlType == ESqlType.MySQL) { return("tinyint"); } throw new InvalidOperationException(); case DbType.Int32: return("int"); case DbType.Double: return("float"); case DbType.Decimal: return("decimal"); case DbType.DateTime: return("datetime"); case DbType.Binary: return("binary"); default: throw new InvalidOperationException(); } }
public static string EntitronConnectionString(ESqlType dbType) { if (DefaultConnectionString == "DefaultConnection") { return(DefaultConnectionString); } if (DefaultDBType == ESqlType.MSSQL) { return($"{DefaultConnectionString}{(DefaultConnectionString.EndsWith(";") ? "" : ";")}App=EntityFramework;"); } if (DefaultDBType == ESqlType.MySQL) { return($"{DefaultConnectionString}{(DefaultConnectionString.EndsWith(";") ? "" : ";")}Allow User Variables=True;"); } return(DefaultConnectionString); }
public int Execute(IEnumerable <string> sqlStatements) { List <DBState> list = new List <DBState>(); foreach (string current in sqlStatements) { string text = current; string text2 = text.ToUpper().Trim(); ESqlType type = ESqlType.INSERT; if (text2.StartsWith(ESqlType.INSERT.ToString())) { type = ESqlType.INSERT; } else { if (text2.StartsWith(ESqlType.UPDATE.ToString())) { type = ESqlType.UPDATE; } else { if (text2.StartsWith(ESqlType.DELETE.ToString())) { type = ESqlType.DELETE; } } } list.Add(new DBState { Name = "ExecuteNoneQuery", Param = text, Type = type }); } return(this.Execute(list)); }
public static string FullDefinition(DbType type, ESqlType sqlType, int maxLength = -1) { switch (type) { case DbType.String: if (sqlType == ESqlType.MSSQL) { return($"nvarchar({(maxLength > 0 ? maxLength : MaxLength(type))})"); } if (sqlType == ESqlType.MySQL) { return($"varchar({(maxLength > 0 ? maxLength : MaxLength(type))})"); } throw new InvalidOperationException(); case DbType.Boolean: if (sqlType == ESqlType.MSSQL) { return("bit"); } if (sqlType == ESqlType.MySQL) { return("tinyint(1)"); } throw new InvalidOperationException(); case DbType.Int32: return("int"); case DbType.Double: if (sqlType == ESqlType.MSSQL) { return("float"); } if (sqlType == ESqlType.MySQL) { return("float(255,30)"); } throw new InvalidOperationException(); case DbType.Decimal: if (sqlType == ESqlType.MSSQL) { return("decimal(38,20)"); } if (sqlType == ESqlType.MySQL) { return("decimal(38,20)"); } throw new InvalidOperationException(); case DbType.DateTime: return("datetime"); case DbType.Binary: return("binary"); default: throw new InvalidOperationException(); } }