private static T ExecuteWithTracing <T>(VfpCommand vfpCommand, VfpCommandMethod method, Func <T> executeFunc) { var executionEventArgs = new VfpCommandExecutionDetails(vfpCommand, method); executionEventArgs.Status = VfpCommandExecutionStatus.Executing; vfpCommand.Connection.RaiseExecuting(executionEventArgs); var sw = new Stopwatch(); try { try { sw.Start(); var result = executeFunc(); sw.Stop(); executionEventArgs.Result = result; executionEventArgs.Duration = sw.Elapsed; executionEventArgs.Status = VfpCommandExecutionStatus.Finished; vfpCommand.Connection.RaiseFinished(executionEventArgs); return(result); } catch (OleDbException oleDbException) { throw new VfpException(oleDbException.Message, oleDbException); } } catch (Exception ex) { executionEventArgs.Result = ex; executionEventArgs.Status = VfpCommandExecutionStatus.Failed; vfpCommand.Connection.RaiseFailed(executionEventArgs); throw; } }
internal static T Execute <T>(VfpCommand vfpCommand, VfpCommandMethod method, Func <T> executeFunc) { if (VfpClientTracing.Tracer.HasSourceLevel(SourceLevels.Information)) { return(ExecuteWithTracing(vfpCommand, method, executeFunc)); } return(ExecuteWithoutTracing(executeFunc)); }
protected override int Fill(DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords) { var result = VfpCommand.Execute(SelectCommand, VfpCommandMethod.DataAdapterFill, () => base.Fill(dataTables, new VfpDataReader((DbDataReader)dataReader), startRecord, maxRecords)); foreach (var dataTable in dataTables) { TrimEndAllStringColumn(dataTable); } return(result); }
private VfpCommand GetCommand() { if (Parameters.Count == 0) { return(this); } var vfpCommand = new VfpCommand(this); _vfpCommandParameterRewritter.Rewrite(vfpCommand); return(vfpCommand); }
public static string Build(VfpCommand command) { if (IsExecScript(command)) { return(command.Parameters[0].Value.ToString()); } var output = new StringBuilder(); WriteParameters(command, output); WriteCommandText(command, output); var vfpCode = output.ToString(); vfpCode = vfpCode.Trim(Environment.NewLine.ToCharArray()); return(vfpCode.Trim()); }
private static void WriteCommandText(VfpCommand command, StringBuilder output) { var text = command.CommandText; for (var index = command.Parameters.Count - 1; index >= 0; index--) { var parameter = command.Parameters[index]; text = text.Replace("@" + parameter.ParameterName, GetParameterName(parameter.ParameterName)); } text = text.Trim(Environment.NewLine.ToCharArray()) .Replace("\n", string.Empty); text = AddSemiColons(text); text = ReplaceQuestionMarks(command.Parameters, text); output.Append(Environment.NewLine); output.Append(Environment.NewLine); output.Append(text); }
private static void WriteParameters(VfpCommand command, StringBuilder output) { foreach (VfpParameter parameter in command.Parameters) { output.Append(Environment.NewLine); var parameterName = GetParameterName(parameter.ParameterName); if (parameter.Value == null || parameter.Value == DBNull.Value) { output.Append(string.Format("{0} = NULL", parameterName)); } else { switch (parameter.VfpType) { case VfpType.Logical: output.Append(string.Format("{0} = {1}", parameterName, ((bool)parameter.Value) ? ".t." : ".f.")); break; case VfpType.Character: case VfpType.Varchar: case VfpType.Memo: var parameterValue = parameter.Value.ToString(); if (parameterValue.Length > VfpMapping.MaximumCharacterFieldSize || parameterValue.IndexOf(Environment.NewLine) >= 0) { output.AppendLine(string.Format(@" TEXT TO {0} NOSHOW {1} ENDTEXT" , parameterName, parameterValue)); } else { output.Append(string.Format("{0} = '{1}'", parameterName, parameterValue.Replace("'", "' + chr(39) + '"))); } break; case VfpType.Date: output.Append(string.Format("{0} = CTOD('{1}')", parameterName, ((DateTime)parameter.Value).ToShortDateString())); break; case VfpType.DateTime: output.Append(string.Format("{0} = CTOT('{1}')", parameterName, parameter.Value)); break; default: if (typeof(byte[]) == parameter.Value.GetType()) { var fileName = Path.GetTempFileName(); File.WriteAllBytes(fileName, (byte[])parameter.Value); output.Append(string.Format("{0} = FILETOSTR('{1}')", parameterName, fileName)); } else { output.Append(string.Format("{0} = {1}", parameterName, parameter.Value)); } break; } } } }
public VfpDataAdapter(string selectCommandText, string selectCommandConnection) { _vfpConnection = new VfpConnection(selectCommandConnection); SelectCommand = new VfpCommand(selectCommandText, _vfpConnection); }
public VfpDataAdapter(VfpCommand selectCommand) { _vfpConnection = null; SelectCommand = selectCommand; }
protected internal VfpCommand(VfpCommand vfpCommand) : this(vfpCommand.OleDbCommand.Clone(), vfpCommand._vfpConnection) { }
internal VfpCommandExecutionDetails(VfpCommand command, VfpCommandMethod method) { CommandId = command.CommandId; Command = command; Method = method; }