Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private VfpCommand GetCommand()
        {
            if (Parameters.Count == 0)
            {
                return(this);
            }

            var vfpCommand = new VfpCommand(this);

            _vfpCommandParameterRewritter.Rewrite(vfpCommand);

            return(vfpCommand);
        }
Exemplo n.º 5
0
            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());
            }
Exemplo n.º 6
0
            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);
            }
Exemplo n.º 7
0
            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;
                        }
                    }
                }
            }
Exemplo n.º 8
0
 public VfpDataAdapter(string selectCommandText, string selectCommandConnection)
 {
     _vfpConnection = new VfpConnection(selectCommandConnection);
     SelectCommand  = new VfpCommand(selectCommandText, _vfpConnection);
 }
Exemplo n.º 9
0
 public VfpDataAdapter(VfpCommand selectCommand)
 {
     _vfpConnection = null;
     SelectCommand  = selectCommand;
 }
Exemplo n.º 10
0
 protected internal VfpCommand(VfpCommand vfpCommand)
     : this(vfpCommand.OleDbCommand.Clone(), vfpCommand._vfpConnection)
 {
 }
Exemplo n.º 11
0
 internal VfpCommandExecutionDetails(VfpCommand command, VfpCommandMethod method)
 {
     CommandId = command.CommandId;
     Command   = command;
     Method    = method;
 }