/// <summary> /// Gets the SQL value ready for insert for this row and column. /// </summary> /// <param name="col">The column to retrieve the value.</param> /// <param name="row">The current row.</param> /// <returns>The escaped value.</returns> public virtual string GetSqlColumnValue(IColumn col, DataRow row) { Throw.If(col, "col").IsNull(); Throw.If(row, "row").IsNull(); if (col.IsNullable && row[col.Name] == DBNull.Value) { return("NULL"); } else if (DataTypeUtil.IsNumeric(col)) { return(row[col.Name].ToString()); } else if (DataTypeUtil.IsBoolean(col)) { if ((bool)row[col.Name]) { return("1"); } else { return("0"); } } else { return(string.Format("'{0}'", row[col.Name].ToString().Replace("'", "''"))); } }
public virtual string GetXmlColumnValue(IColumn col, DataRow row) { Throw.If(col, "col").IsNull(); Throw.If(row, "row").IsNull(); if (col.IsNullable && row[col.Name] == DBNull.Value) { return(null); } else if (DataTypeUtil.IsNumeric(col)) { return(row[col.Name].ToString()); } else if (DataTypeUtil.IsDateTime(col)) { DateTime dt = (DateTime)row[col.Name]; return(dt.ToString("o")); // ISO 8601 } else if (DataTypeUtil.IsBoolean(col)) { if ((bool)row[col.Name]) { return("1"); } else { return("0"); } } else { // wrap in CDATA section? return(string.Format("{0}", row[col.Name])); } }