Ejemplo n.º 1
0
        public void EscapedNamesLeadingToACollisionAreHandledCorrectly()
        {
            var resultSet = new FlexResultSet();
            var result    = new FlexResult();

            result.schema = new List <SQLColumn>()
            {
                new SQLColumn()
                {
                    ColumnName = "test_1", DataType = "varchar"
                },
                new SQLColumn()
                {
                    ColumnName = "test?1", DataType = "varchar"
                }
            };
            result.data = new List <object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");

            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
{
    public string test_1 { get; set; }
    public string test_1_2 { get; set; }
}
";

            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 2
0
        public void EmptyColumnList_NotRenderableAsCreateTable()
        {
            var sut = new FlexResult();

            sut.schema = new List <SQLColumn>();
            Assert.AreEqual(false, FieldScripting.ResultIsRenderableAsCreateTable(sut));
        }
Ejemplo n.º 3
0
        public void AnonymousColumnsAreHandledCorrectly()
        {
            var resultSet = new FlexResultSet();
            var result    = new FlexResult();

            result.schema = new List <SQLColumn>()
            {
                new SQLColumn()
                {
                    ColumnName = "", DataType = "varchar"
                },
                new SQLColumn()
                {
                    ColumnName = "", DataType = "int"
                }
            };
            result.data = new List <object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");

            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
{
    public string anonymousProperty { get; set; }
    public int anonymousProperty_2 { get; set; }
}
";

            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 4
0
        public void handle_duplicate_column_names()
        {
            var resultSet = new FlexResultSet();
            var result    = new FlexResult();

            result.schema = new List <SQLColumn>()
            {
                new SQLColumn()
                {
                    ColumnName = "testa", DataType = "int"
                },
                new SQLColumn()
                {
                    ColumnName = "testa", DataType = "varchar"
                }
            };
            result.data = new List <object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");

            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
{
    public int testa { get; set; }
    public string testa_2 { get; set; }
}
";

            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 5
0
        public void ResultSet_WithNoReturnedSchema_ResultsInNoReturnedSchemaComment()
        {
            FlexResultSet fsr = new FlexResultSet();

            var result = new FlexResult();

            fsr.results.Add(result);

            Assert.AreEqual("--No schema for result from query.", FieldScripting.ScriptResultDataAsInsert(result, "#result0", FlexResultSet.SQL2008MaxRowsInValuesClause).ToString());
        }
Ejemplo n.º 6
0
        public void ResultSet_WithNoReturnedSchema_ResultsInNoReturnedSchemaComment()
        {
            FlexResultSet fsr = new FlexResultSet();

            var result = new FlexResult();

            fsr.results.Add(result);

            Assert.AreEqual("--No schema for result from query.", FieldScripting.ScriptResultDataAsInsert(result, "#result0", FlexResultSet.SQL2008MaxRowsInValuesClause).ToString());
        }
Ejemplo n.º 7
0
        public void PopulatedColumnList_IsRenderableAsCreateTable()
        {
            var sut = new FlexResult();

            sut.schema = new List <SQLColumn>()
            {
                new SQLColumn()
                {
                    ColumnName = "test", DataType = "int"
                }
            };
            Assert.AreEqual(true, FieldScripting.ResultIsRenderableAsCreateTable(sut));
        }
Ejemplo n.º 8
0
        public void RenderingTimeField_RendersCorrectly()
        {
            var frs = new FlexResultSet();

            var dt = new List <SQLColumn>()
            {
                SchemaScriptingTests.FakeColumn("ColIntNotNull", "MyStuff", 32, "int", false, 255, 255),
                SchemaScriptingTests.FakeColumn("ColIntNull", "MyStuff", 32, "int", true, 255, 255),
                SchemaScriptingTests.FakeColumn("ColTimeOfDay", "MyStuff", 32, "time", true, 255, 255)
            };

            var result = new FlexResult()
            {
                schema = dt,
                data   = new List <object[]>()
                {
                    new object[] { 99, 111, new TimeSpan(0, 00, 00, 00, 001) },
                    new object[] { 42, null, new TimeSpan(23, 59, 30) },
                }
            };

            frs.results.Add(result);

            var tempFileName = Guid.NewGuid().ToString() + ".txt";

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), "", SqlRunParameters.TO_XML_SPREADSHEET, tempFileName);

            XmlSpreadsheetRenderer.renderAsXMLSpreadsheet(frs, srp);

            var xmlSpreadsheetContent = srp.getOutputStreamAsString(tempFileName);

            Assert.IsTrue(xmlSpreadsheetContent.Length > 1000, "expected more than 1000 characters of output");

            Assert.IsTrue(xmlSpreadsheetContent.Contains(">99<"));
            Assert.IsTrue(xmlSpreadsheetContent.Contains(">111<"));
            Assert.IsTrue(xmlSpreadsheetContent.Contains(">1899-12-31T00:00:00.001<"));
            Assert.IsTrue(xmlSpreadsheetContent.Contains(">42<"));
            Assert.IsTrue(xmlSpreadsheetContent.Contains(">1899-12-31T23:59:30.000<"));

            XmlDocument doc = null;

            Assert.DoesNotThrow(() => {
                doc = new XmlDocument();
                doc.LoadXml(xmlSpreadsheetContent);
            }, "expected no exception");

            Assert.IsNotNull(doc, "expected valid XML");
        }
Ejemplo n.º 9
0
        public void ResultSet_WithNoReturnedData_ResultsInNoReturnedDataComment()
        {
            FlexResultSet fsr = new FlexResultSet();

            var dt = SchemaScriptingTests.FakeSchemaDataTable();

            dt.LoadDataRow(SchemaScriptingTests.FakeColumn("IntNotNull", "MyStuff", 32, "int", false, 255, 255), false);
            dt.LoadDataRow(SchemaScriptingTests.FakeColumn("IntNull", "MyStuff", 32, "int", true, 255, 255), false);

            FlexResult result = new FlexResult();

            fsr.results.Add(result);
            fsr.results[0].schema = dt;
            fsr.results[0].data   = new List <object[]>();

            Assert.AreEqual("--No rows were returned from the query.", FieldScripting.ScriptResultDataAsInsert(result, "#result0", FlexResultSet.SQL2008MaxRowsInValuesClause).ToString());
        }
Ejemplo n.º 10
0
        public void ResultSet_WithNoReturnedData_ResultsInNoReturnedDataComment()
        {
            FlexResultSet fsr = new FlexResultSet();

            var dt = SchemaScriptingTests.FakeSchemaDataTable();

            dt.LoadDataRow(SchemaScriptingTests.FakeColumn("IntNotNull", "MyStuff", 32, "int", false, 255, 255), false);
            dt.LoadDataRow(SchemaScriptingTests.FakeColumn("IntNull", "MyStuff", 32, "int", true, 255, 255), false);

            FlexResult result = new FlexResult();

            fsr.results.Add(result);
            fsr.results[0].schema = dt;
            fsr.results[0].data = new List<object[]>();

            Assert.AreEqual("--No rows were returned from the query.", FieldScripting.ScriptResultDataAsInsert(result, "#result0", FlexResultSet.SQL2008MaxRowsInValuesClause).ToString());
        }
Ejemplo n.º 11
0
        public void EscapedNamesLeadingToACollisionAreHandledCorrectly()
        {
            var resultSet = new FlexResultSet();
            var result = new FlexResult();
            result.schema = new List<SQLColumn>() {
                new SQLColumn() { ColumnName = "test_1", DataType = "varchar" },
                new SQLColumn() { ColumnName = "test?1", DataType = "varchar" }
            };
            result.data = new List<object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");
            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
            {
            public string test_1 { get; set; }
            public string test_1_2 { get; set; }
            }
            ";
            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 12
0
        public void AnonymousColumnsAreHandledCorrectly()
        {
            var resultSet = new FlexResultSet();
            var result = new FlexResult();
            result.schema = new List<SQLColumn>() {
                new SQLColumn() { ColumnName = "", DataType = "varchar" },
                new SQLColumn() { ColumnName = "", DataType = "int" }
            };
            result.data = new List<object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");
            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
            {
            public string anonymousProperty { get; set; }
            public int anonymousProperty_2 { get; set; }
            }
            ";
            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 13
0
        public void NullabilityWorksCorrectly()
        {
            var resultSet = new FlexResultSet();
            var result    = new FlexResult();

            result.schema = new List <SQLColumn>()
            {
                new SQLColumn()
                {
                    ColumnName = "a", DataType = "varchar", AllowNulls = true
                },
                new SQLColumn()
                {
                    ColumnName = "b", DataType = "int", AllowNulls = true
                },
                new SQLColumn()
                {
                    ColumnName = "c", DataType = "smalldatetime", AllowNulls = true
                }
            };
            result.data = new List <object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");

            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
{
    public string a { get; set; }
    public int? b { get; set; }
    public DateTime? c { get; set; }
}
";

            Assert.AreEqual(expected, srp.resultsText.ToString());
        }
Ejemplo n.º 14
0
        public void NullColumnList_NotRenderableAsCreateTable()
        {
            var sut = new FlexResult();

            Assert.AreEqual(false, FieldScripting.ResultIsRenderableAsCreateTable(sut));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Reads a FlexQuery by API.
        /// </summary>
        /// <param name="token">token provided by IB</param>
        /// <param name="queryId">ID of the FlexQuery (not the name)</param>
        /// <param name="dumpFile">if set, the data returned from IB will be dumped to file</param>
        /// <param name="retry">if GetStatement returns warning 1019 (... Please try again shortly), retry defines how many times it will be tried again</param>
        /// <param name="retryDelay">delay between two tries in milliseconds</param>
        /// <returns></returns>
        public async Task <FlexResult> GetByApi(string token, string queryId, string dumpFile = null, int?retry = null, int retryDelay = 3000)
        {
            if (retryDelay <= 0)
            {
                throw new ArgumentOutOfRangeException("retryDelay");
            }

            using (var client = new HttpClient())
            {
                FlexResult requestResult = await SendRequest(client, token, queryId, dumpFile).ConfigureAwait(false);

                if (!requestResult.IsSuccess)
                {
                    return(requestResult);
                }

                string referenceCode = requestResult.ReferenceCode;

                int retryCounter = 0;
                if (retry.HasValue && retry.Value > 0)
                {
                    retryCounter = retry.Value;
                }

                FlexResult result = null;

                bool tryAgain = true;
                while (tryAgain)
                {
                    result = await GetStatement(client, token, referenceCode, dumpFile).ConfigureAwait(false);

                    if (!result.IsSuccess && result.ErrorCode.HasValue && result.ErrorCode.Value == 1019)
                    {
                        // warning is: 'Statement generation in progress. Please try again shortly. '

                        System.Diagnostics.Debug.Print("IbFlexReader.Reader.GetByApi: Retry");

                        // retry getting data?
                        if (retryCounter > 0)
                        {
                            // yes
                            retryCounter--;
                            // wait a little bit
                            await Task.Delay(retryDelay).ConfigureAwait(false);
                        }
                        else
                        {
                            // no
                            tryAgain = false;
                        }
                    }
                    else
                    {
                        // data received
                        tryAgain = false;
                    }
                }

                return(result);
            }
        }
Ejemplo n.º 16
0
        public void handle_duplicate_column_names()
        {
            var resultSet = new FlexResultSet();
            var result = new FlexResult();
            result.schema = new List<SQLColumn>() {
                new SQLColumn() { ColumnName = "testa", DataType = "int" },
                new SQLColumn() { ColumnName = "testa", DataType = "varchar" }
            };
            result.data = new List<object[]>();
            resultSet.results.Add(result);

            var srp = new SqlRunParameters(new SqlConnectionStringBuilder(), SqlRunParameters.TO_CSHARP, "");
            CSharpRenderer.renderAsCSharp(resultSet, srp);
            var expected = @"public class Result0
            {
            public int testa { get; set; }
            public string testa_2 { get; set; }
            }
            ";
            Assert.AreEqual(srp.resultsText.ToString(), expected);
        }
Ejemplo n.º 17
0
 public void PopulatedColumnList_IsRenderableAsCreateTable()
 {
     var sut = new FlexResult();
     sut.schema = new List<SQLColumn>() { new SQLColumn() { ColumnName = "test", DataType = "int" }};
     Assert.AreEqual(true, FieldScripting.ResultIsRenderableAsCreateTable(sut));
 }
Ejemplo n.º 18
0
 public void NullColumnList_NotRenderableAsCreateTable()
 {
     var sut = new FlexResult();
     Assert.AreEqual(false, FieldScripting.ResultIsRenderableAsCreateTable(sut));
 }
Ejemplo n.º 19
0
 public void EmptyColumnList_NotRenderableAsCreateTable()
 {
     var sut = new FlexResult();
     sut.schema = new List<SQLColumn>();
     Assert.AreEqual(false, FieldScripting.ResultIsRenderableAsCreateTable(sut));
 }