/// <summary> /// Converts the fields to IDataParameter. The name of the parameter will also include /// the name of the table. /// </summary> /// <param name="database">Database server type</param> /// <param name="tableName">Name of the database table</param> /// <param name="field">Field to be converted</param> /// <returns>The IDataParameter</returns> public IDataParameter ConvertToDataParameter(DatabaseServer database, string tableName, DatabaseField field) { IDataParameter parameter = null; DataFactory factory = new DataFactory(); factory.InitializeDataParameter(database, ref parameter); SqlGenerator generator = new SqlGenerator(); parameter.ParameterName = factory.GetParameterChar(database).ToString() + generator.GetTableName(tableName) + field.fieldName; parameter.SourceColumn = field.fieldName; if (field.fieldValue == null) { parameter.Value = DBNull.Value; } else { parameter.Value = field.fieldValue; } parameter.DbType = field.fieldType; return(parameter); }
/// <summary> /// Converts the fields of TableMetadata to IDataParameters /// </summary> /// <param name="database">Database server type</param> /// <param name="mainTable">TableMetadata from which the conversion is made</param> /// <returns>IDataParameter array </returns> public IDataParameter[] ConvertToDataParameter(DatabaseServer database, TableMetadata mainTable) { IDataParameter[] parameters = new IDataParameter[mainTable.TableFields.Length]; DataFactory factory = new DataFactory(); for (int i = 0; i < parameters.Length; i++) { factory.InitializeDataParameter(database, ref parameters[i]); } for (int i = 0; i < mainTable.TableFields.Length; i++) { parameters[i].ParameterName = mainTable.TableFields[i].fieldName; parameters[i].Value = mainTable.TableFields[i].fieldValue; parameters[i].DbType = mainTable.TableFields[i].fieldType; } return(parameters); }
/// <summary> /// Converts the fields to IDataParameter /// </summary> /// <param name="database">Database server type</param> /// <param name="fields">Fields to be converted</param> /// <returns>Array of IDataParameter</returns> public IDataParameter[] ConvertToDataParameter(DatabaseServer database, params DatabaseField[] fields) { if (fields == null || fields.Length == 0) { throw new ArgumentException("Invalid database fields"); } IDataParameter[] parameters = new IDataParameter[fields.Length]; DataFactory factory = new DataFactory(); for (int i = 0; i < fields.Length; i++) { factory.InitializeDataParameter(database, ref parameters[i]); } for (int i = 0; i < fields.Length; i++) { parameters[i].ParameterName = factory.GetParameterChar(database) + fields[i].fieldName; parameters[i].SourceColumn = fields[i].fieldName; if (fields[i].fieldValue == null) { parameters[i].Value = DBNull.Value; } else { parameters[i].Value = fields[i].fieldValue; } parameters[i].DbType = fields[i].fieldType; } return(parameters); }
/// <summary> /// Converts the specified DataField into a IDataParameter. This ensures that the /// name of the parameter is unique by comparing with a list of specified used names /// </summary> /// <param name="database">Database server</param> /// <param name="tableName">Name of the table to which the field belongs</param> /// <param name="field">DatabaseField which will be converted</param> /// <param name="listUsedParameterNames">List with used names of a parameter. When the name of the parameter is given it is checked against the values in this list. If the name if found then it is changed to be unique</param> /// <returns>The IDataParameter</returns> public IDataParameter ConvertToDataParameter(DatabaseServer database, string tableName, DatabaseField field, ref List <string> listUsedParameterNames) { IDataParameter parameter = null; SqlGenerator generator = new SqlGenerator(); DataFactory factory = new DataFactory(); factory.InitializeDataParameter(database, ref parameter); string parameterName = factory.GetParameterChar(database) + generator.GetTableName(tableName) + field.fieldName; while (listUsedParameterNames.Contains(parameterName)) { parameterName = parameterName + PARAMETER_NAME_ENDING; } parameter.ParameterName = parameterName; //add it to the external list listUsedParameterNames.Add(parameterName); if (field.fieldValue == null) { parameter.Value = DBNull.Value; } else { parameter.Value = field.fieldValue; } parameter.DbType = field.fieldType; parameter.SourceColumn = field.fieldName; return(parameter); }