private string FormatDateTime(DateTime value) { var ingresDate = IngresDate.Create(value); if (ingresDate.IngresDateKind == IngresDateKind.DateTime) { var localValue = ingresDate.Kind == DateTimeKind.Utc ? ingresDate.ToLocalTime() : ingresDate; if (localValue.IsDate) { return(IngresDate.Format(localValue)); } } return(IngresDate.Format(ingresDate)); }
private void ChangeParameters() { var paramMap = _oldParameters.ToDictionary(x => x.ParameterName, x => x); _command.Parameters.Clear(); var paramNo = 0; var sql = new StringBuilder(); foreach (var part in ParseSql(_command.CommandText)) { if (part.Type == "Parameter") { DbParameter param; if (paramMap.TryGetValue(part.Value, out param) || paramMap.TryGetValue(part.Lexeme, out param)) { var addParam = true; var placeholder = "?"; param = (DbParameter)((ICloneable)param).Clone(); param.ParameterName = string.Format("p{0}", paramNo); if (param.Value is IngresDate || param.Value is DateTime || param.Value is TimeSpan) { var ingresDate = IngresDate.Create(param.Value); if (ingresDate.IngresDateKind == IngresDateKind.DateTime) { var localValue = ingresDate.Kind == DateTimeKind.Utc ? ingresDate.ToLocalTime() : ingresDate; if (localValue.IsDate) { placeholder = IngresDate.Format(localValue); addParam = false; } } else { placeholder = IngresDate.Format(ingresDate); addParam = false; } } else if (param.Value is int || param.Value is short || param.Value is long) { placeholder = param.Value.ToString(); addParam = false; } if (addParam) { _command.Parameters.Add(param); paramNo += 1; } sql.Append(placeholder); } else { sql.Append(part.Lexeme); } } else if (part.Type == "CatalogTable") { CatalogTables.Add(part.Value); sql.Append("session."); sql.Append(part.Value); } else { sql.Append(part.Lexeme); } } _command.CommandText = sql.ToString(); }
private string FormatTimeSpan(TimeSpan value) { return(IngresDate.Format(IngresDate.Create(value))); }