public void SelectWithKeys(params object[] values) { TkDebug.AssertEnumerableArgumentNull(values, "values", this); TkDebug.Assert(KeyCount == values.Length, string.Format(ObjectUtil.SysCulture, "参数values的个数和表的主键字段个数不匹配,主键的个数为{0},而values的个数为{1}", KeyCount, values.Length), this); IParamBuilder[] builders = new IParamBuilder[KeyCount]; for (int i = 0; i < KeyCount; ++i) { builders[i] = SqlParamBuilder.CreateEqualSql(Context, fKeyFieldArray[i], values[i]); } Select(ParamBuilder.CreateParamBuilder(builders)); }
public static void SetPrimaryKey(DataTable table, params DataColumn[] keys) { TkDebug.AssertArgumentNull(table, "table", null); TkDebug.AssertEnumerableArgumentNull <DataColumn>(keys, "keys", null); try { table.PrimaryKey = keys; } catch (DataException ex) { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "无法给表{0}设置主键,请检查表中的主键字段{1}是否存在重复数据", table.TableName, GetKeyFields(keys)), ex, null); } }
/// <summary> /// 创建数据表 /// </summary> /// <param name="tableName">表名</param> /// <param name="fieldNames">字段序列</param> /// <returns>数据表</returns> public static DataTable CreateDataTable(string tableName, IEnumerable <IFieldInfo> fieldNames) { TkDebug.AssertArgumentNullOrEmpty(tableName, "tableName", null); TkDebug.AssertEnumerableArgumentNull(fieldNames, "fieldNames", null); DataTable table = new DataTable(tableName) { Locale = ObjectUtil.SysCulture }; foreach (IFieldInfo fieldName in fieldNames) { table.Columns.Add(new DataColumn(fieldName.NickName, MetaDataUtil.ConvertDataTypeToType(fieldName.DataType))); } return(table); }
/// <summary> /// 对DataRow进行赋值,注意,输入的values必须是从起始开始到结束相应的Row的ColName序列 /// </summary> /// <param name="row">需要赋值的DataRow</param> /// <param name="values">相应的值</param> /// <example>例如: /// <code> /// DataSetUtil.SetRowValues(row, new object[] {"01", "先生"}); /// </code> /// </example> public static void SetRowValues(DataRow row, params object[] values) { TkDebug.AssertArgumentNull(row, "row", null); TkDebug.AssertEnumerableArgumentNull(values, "values", null); row.BeginEdit(); try { for (int i = 0; i < values.Length; ++i) { row[i] = values[i]; } } finally { row.EndEdit(); } }
public IParamBuilder CreateParamBuilder(string filterSql, string[] fields, params object[] values) { TkDebug.AssertEnumerableArgumentNullOrEmpty(fields, "fields", this); TkDebug.AssertEnumerableArgumentNull(values, "values", this); TkDebug.Assert(fields.Length == values.Length, string.Format(ObjectUtil.SysCulture, "参数fields和values的个数不匹配,fields的个数为{0},而values的个数为{1}", fields.Length, values.Length), this); List <IParamBuilder> list = new List <IParamBuilder>(fields.Length + 1); for (int i = 0; i < fields.Length; i++) { IParamBuilder builder = SqlParamBuilder.CreateEqualSql(Context, GetFieldInfo(fields[i]), values[i]); list.Add(builder); } if (!string.IsNullOrEmpty(filterSql)) { list.Add(ParamBuilder.CreateSql(filterSql)); } return(ParamBuilder.CreateParamBuilder(list)); }
string ISqlProvider.GetFunction(string funcName, params object[] funcParams) { TkDebug.AssertArgumentNullOrEmpty(funcName, "funcName", this); switch (funcName.ToUpper(ObjectUtil.SysCulture)) { case "SUBSTRING": TkDebug.AssertEnumerableArgumentNull(funcParams, "funcParams", this); TkDebug.AssertArgument(funcParams.Length == 3, "funcParams", string.Format(ObjectUtil.SysCulture, "SUBSTRING的参数个数要求是3个,现在是{0}个", funcParams.Length), this); return(string.Format(ObjectUtil.SysCulture, "SUBSTR({0}, {1}, {2})", funcParams)); case "SYSDATE": return("SYSDATE"); case "LENGTH": return(string.Format(ObjectUtil.SysCulture, "LENGTH({0})", funcParams)); default: return(string.Empty); } }