Exemplo n.º 1
0
        public List <String> Execute(string commandParameter)
        {
            if (_connection == null)
            {
                throw new ApplicationException("Error Getting Connection");
            }

            FndPLSQLSelectCommand command = new FndPLSQLSelectCommand(_connection, _selectStatement);

            command.BindVariables.Add(
                new FndBindVariable(
                    FndBindVariableDirection.In,
                    "NAME",
                    new FndTextAttribute(string.Concat(commandParameter, "%")))
                );

            FndDataTable returnTable = command.ExecuteReader("CUSTOMER_INFO");

            var returnNames = new List <String>();

            foreach (FndDataRow item in returnTable.Rows)
            {
                returnNames.Add(item["NAME"].ToString());
            }

            return(returnNames);
        }
        /// <summary>
        /// Write query results to json string or file
        /// </summary>
        /// <param name="command"></param>
        /// <param name="output"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        internal static async Task <string> ToJsonAsync(this FndPLSQLSelectCommand command, OutputProperties output, CancellationToken cancellationToken)
        {
            var culture = string.IsNullOrWhiteSpace(output.CultureInfo) ? CultureInfo.InvariantCulture : new CultureInfo(output.CultureInfo);

            // utf-8 as default encoding
            Encoding encoding = string.IsNullOrWhiteSpace(output.OutputFile?.Encoding) ? Encoding.UTF8 : Encoding.GetEncoding(output.OutputFile.Encoding);

            // create json result
            using (var fileWriter = output.OutputToFile ? new StreamWriter(output.OutputFile.Path, false, encoding) : null)
                using (var writer = output.OutputToFile ? new JsonTextWriter(fileWriter) : new JTokenWriter() as JsonWriter)
                {
                    writer.Formatting = Formatting.Indented;
                    writer.Culture    = culture;

                    // start array
                    await writer.WriteStartArrayAsync(cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();
                    FndDataTable reader = command.ExecuteReader();
                    for (var j = 0; j < reader.Rows.Count; j++)
                    {
                        // start row object
                        await writer.WriteStartObjectAsync(cancellationToken);

                        foreach (FndDataColumn a in reader.Columns)
                        {
                            var resultValue = Convert.ToString(reader.Rows[j][a.Name]);

                            // add row element name
                            await writer.WritePropertyNameAsync(a.Name, cancellationToken);

                            // add row element value
                            await writer.WriteValueAsync(resultValue, cancellationToken);

                            cancellationToken.ThrowIfCancellationRequested();
                        }

                        cancellationToken.ThrowIfCancellationRequested();

                        // end row object
                        await writer.WriteEndObjectAsync(cancellationToken);
                    }

                    // end array
                    await writer.WriteEndArrayAsync(cancellationToken);

                    if (output.OutputToFile && output.OutputFile != null)
                    {
                        return(output.OutputFile.Path);
                    }

                    return(((JTokenWriter)writer).Token.ToString());
                }
        }
Exemplo n.º 3
0
        public List<String> Execute(string commandParameter)
        {
            if (_connection == null)
                throw new ApplicationException("Error Getting Connection");

            FndPLSQLSelectCommand command = new FndPLSQLSelectCommand(_connection, _selectStatement);
            command.BindVariables.Add(
                new FndBindVariable(
                    FndBindVariableDirection.In,
                    "NAME",
                    new FndTextAttribute(string.Concat(commandParameter, "%")))
                    );

            FndDataTable returnTable = command.ExecuteReader("CUSTOMER_INFO");

            var returnNames = new List<String>();
            foreach(FndDataRow item in returnTable.Rows)
            {
                returnNames.Add(item["NAME"].ToString());
            }

               return returnNames;
        }