private void _TestQuery
        (
            string text,
            string expected
        )
        {
            string actual = IrbisSearchQuery.PrepareQuery(text);

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        /// <inheritdoc cref="AbstractCommand.CreateQuery"/>
        public override ClientQuery CreateQuery()
        {
            ClientQuery result = base.CreateQuery();

            result.CommandCode = CommandCode.Search;

            string database = Database ?? Connection.Database;

            if (string.IsNullOrEmpty(database))
            {
                Log.Error
                (
                    "SearchCommand::CreateQuery: "
                    + "database not set"
                );

                throw new IrbisException("database not set");
            }

            result.Add(database);

            string preparedQuery = IrbisSearchQuery.PrepareQuery
                                   (
                SearchExpression
                                   );

            result.AddUtf8(preparedQuery);

            result.Add(NumberOfRecords);
            result.Add(FirstRecord);

            string preparedFormat = IrbisFormat.PrepareFormat
                                    (
                FormatSpecification
                                    );

            result.Add
            (
                new TextWithEncoding
                (
                    UtfFormat
                            ? "!" + preparedFormat
                            : preparedFormat,
                    UtfFormat
                            ? IrbisEncoding.Utf8
                            : IrbisEncoding.Ansi
                )
            );

            if (!string.IsNullOrEmpty(SequentialSpecification))
            {
                result.Add(MinMfn);
                result.Add(MaxMfn);

                string preparedSequential = IrbisFormat.PrepareFormat
                                            (
                    SequentialSpecification
                                            );
                if (!ReferenceEquals(preparedSequential, null) && preparedSequential.Length != 0)
                {
                    if (!preparedSequential.StartsWith("!if"))
                    {
                        preparedSequential = "!if "
                                             + preparedSequential
                                             + " then '1' else '0'";
                    }

                    Encoding encoding = preparedSequential.StartsWith("!")
                        ? IrbisEncoding.Utf8
                        : IrbisEncoding.Ansi;

                    result.Add
                    (
                        new TextWithEncoding
                        (
                            preparedSequential,
                            encoding
                        )
                    );
                }
            }

            return(result);
        }
Example #3
0
        /// <inheritdoc cref="AbstractCommand.CreateQuery"/>
        public override ClientQuery CreateQuery()
        {
            ClientQuery result = base.CreateQuery();

            result.CommandCode = CommandCode.GlobalCorrection;

            string database = Database ?? Connection.Database;

            if (string.IsNullOrEmpty(database))
            {
                Log.Error
                (
                    "GblCommand::CreateQuery: "
                    + "database not specified"
                );

                throw new IrbisException("database not specified");
            }
            result.AddAnsi(database);

            result.Add(Actualize);

            if (!string.IsNullOrEmpty(FileName))
            {
                // @filename without extension
                result.AddAnsi(FileName);
            }
            else
            {
                string statements = GblUtility.EncodeStatements
                                    (
                    Statements.ThrowIfNull("Statements")
                                    );
                result.AddUtf8(statements);
            }

            string preparedSearch = IrbisSearchQuery.PrepareQuery
                                    (
                SearchExpression
                                    );

            result.AddUtf8(preparedSearch);

            result.Add(FirstRecord);
            result.Add(NumberOfRecords);

            result.Add(string.Empty);

            if (ReferenceEquals(MfnList, null))
            {
                // Seems doesn't work with 2015.1
                //result.Add(0);
                //result.Add(MinMfn);
                //result.Add(MaxMfn);

                int count = MaxMfn - MinMfn + 1;
                result.Add(count);
                for (int mfn = MinMfn; mfn < MaxMfn; mfn++)
                {
                    result.Add(mfn);
                }
            }
            else
            {
                if (MfnList.Length == 0)
                {
                    Log.Error
                    (
                        "GblCommand::CreateQuery: "
                        + "MfnList.Length="
                        + MfnList.Length
                    );

                    throw new IrbisException("MfnList.Length == 0");
                }
                result.Add(MfnList.Length);
                foreach (var mfn in MfnList)
                {
                    result.Add(mfn);
                }
            }

            if (!FormalControl)
            {
                result.Add("*");
            }

            if (!AutoIn)
            {
                result.Add("&");
            }

            return(result);
        }