/// <summary> /// Prepare DML /// </summary> /// <param name="ids">SQL语句ID编号</param> /// <param name="objs">输入对象</param> /// <returns></returns> public string execPrepare(string id, Object obj) { try { resultSql = ""; if (id == null) { throw new Exception("参数不全"); } if (obj == null) { throw new Exception("参数不全"); } daoStruct = parseDao.ObtainConfig(id); if (daoStruct.DbType.Length <= 0 || daoStruct.ConStr.Length <= 0 || daoStruct.SqlStr.Length <= 0) { throw new Exception("配置参数不全"); } string sql = daoStruct.SqlStr; resultSql = sql; if (daoStruct.IsLog) { WriteLogin.writeDBLog(daoStruct.Desc, sql); } List <DTOClass> dtolist = setDto(obj); if (sql.Length <= 0) { throw new Exception("构造SQL语句出错"); } IDataSource dataSource = null; switch (daoStruct.DbType) { case "oracle": dataSource = new OracleDataSource(daoStruct); break; case "mysql": dataSource = new MySqlDataSource(daoStruct); break; case "sql": dataSource = new SqlDataSource(daoStruct); break; case "access": dataSource = new AccessDataSource(daoStruct); break; case "sqllite": dataSource = new SqlLiteDataSource(daoStruct); break; } dataSource.PrepareExcute(sql, dtolist); } catch (Exception ex) { throw new Exception(ex.Message, ex); } return(""); }
/// <summary> /// 单DML语句操作 /// </summary> /// <param name="id">SQL语句ID编号</param> /// <param name="obj">输入输出对象</param> /// <returns></returns> public string execDml(string id, Object obj) { resultSql = ""; if (id == "") { throw new Exception("参数不全"); } if (obj == null) { throw new Exception("参数不全"); } daoStruct = parseDao.ObtainConfig(id); if (daoStruct.DbType.Length <= 0 || daoStruct.ConStr.Length <= 0 || daoStruct.SqlStr.Length <= 0) { throw new Exception("配置参数不全"); } string sql = ""; sql = setSql(obj, daoStruct.SqlStr); resultSql = sql; //记录SQL if (daoStruct.IsLog) { WriteLogin.writeDBLog(daoStruct.Desc, resultSql); } if (sql.Length <= 0) { throw new Exception("构造SQL语句出错"); } IDataSource dataSource = null; switch (daoStruct.DbType) { case "oracle": dataSource = new OracleDataSource(daoStruct); break; case "mysql": dataSource = new MySqlDataSource(daoStruct); break; case "sql": dataSource = new SqlDataSource(daoStruct); break; case "access": dataSource = new AccessDataSource(daoStruct); break; case "sqllite": dataSource = new SqlLiteDataSource(daoStruct); break; } if (dataSource != null) { dataSource.SingleExecute(sql); } return(""); }
/// <summary> /// Prepare DML /// </summary> /// <param name="ids">SQL语句ID编号</param> /// <param name="objs">输入对象</param> /// <returns></returns> public string execPrepare(List <string> ids, List <Object> objs) { try { resultSql = ""; List <string> idlist = new List <string>(); idlist = ids; List <Object> objectlist = new List <Object>(); objectlist = objs; if (idlist.Count <= 0) { throw new Exception("缺少参数"); } if (idlist.Count != objectlist.Count) { throw new Exception("参数数量不一致"); } List <string> sqls = new List <string>(); List <List <DTOClass> > dtolists = new List <List <DTOClass> >(); for (int i = 0; i < idlist.Count; i++) { daoStruct = parseDao.ObtainConfig(idlist[i]); if (daoStruct.DbType.Length <= 0 || daoStruct.ConStr.Length <= 0 || daoStruct.SqlStr.Length <= 0) { throw new Exception("配置参数不全"); } string sql = daoStruct.SqlStr; List <DTOClass> dtolist = setDto(objectlist[i]); if (sql.Length <= 0) { throw new Exception("构造SQL语句出错"); } sqls.Add(sql); dtolists.Add(dtolist); if (resultSql != "") { resultSql += "\r\n"; } resultSql += sql; } if (daoStruct.IsLog) { WriteLogin.writeDBLog(daoStruct.Desc, resultSql); } IDataSource dataSource = null; switch (daoStruct.DbType) { case "oracle": dataSource = new OracleDataSource(daoStruct); break; case "mysql": dataSource = new MySqlDataSource(daoStruct); break; case "sql": dataSource = new SqlDataSource(daoStruct); break; case "access": dataSource = new AccessDataSource(daoStruct); break; case "sqllite": dataSource = new SqlLiteDataSource(daoStruct); break; } dataSource.PrepareExcute(sqls, dtolists); } catch (Exception ex) { throw new Exception(ex.Message, ex); } return(""); }
/// <summary> /// 多DML语句操作 /// </summary> /// <param name="ids">SQL语句ID编号列表</param> /// <param name="objs">输入输出对象列表</param> /// <returns></returns> public string execTranctionDml(List <string> ids, List <Object> objs) { resultSql = ""; List <string> idlist = new List <string>(); idlist = ids; List <Object> objectlist = new List <Object>(); objectlist = objs; if (idlist.Count <= 0) { throw new Exception("缺少参数"); } if (idlist.Count != objectlist.Count) { throw new Exception("参数数量不一致"); } List <string> sqls = new List <string>(); for (int i = 0; i < idlist.Count; i++) { daoStruct = parseDao.ObtainConfig(idlist[i]); if (daoStruct.DbType.Length <= 0 || daoStruct.ConStr.Length <= 0 || daoStruct.SqlStr.Length <= 0) { throw new Exception("配置参数不全"); } string sql = ""; sql = setSql(objectlist[i], daoStruct.SqlStr); if (sql.Length <= 0) { throw new Exception("构造SQL语句出错"); } sqls.Add(sql); if (resultSql != "") { resultSql += "\r\n"; } resultSql += sql; } if (daoStruct.IsLog) { WriteLogin.writeDBLog(daoStruct.Desc, resultSql); } IDataSource dataSource = null; switch (daoStruct.DbType) { case "oracle": dataSource = new OracleDataSource(daoStruct); break; case "mysql": dataSource = new MySqlDataSource(daoStruct); break; case "sql": dataSource = new SqlDataSource(daoStruct); break; case "access": dataSource = new AccessDataSource(daoStruct); break; case "sqllite": dataSource = new SqlLiteDataSource(daoStruct); break; } dataSource.TranctionExcute(sqls); //记录SQL return(""); }