Exemplo n.º 1
0
        public void TestOrderByRetrieval()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first verify that data set is ok for test
            SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(MailingList));

            // get ascending
            sb.AddOrderByField(true, "SenderAddress");
            SqlResult sr = Broker.Execute(sb.GetStatement(true));

            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
                          "Wrong number of rows were selected.");
            IList lists = ObjectFactory.GetCollection(typeof(MailingList), sr);

            Assert.IsNotNull(lists, "Test case invalid if row count is not 3.");
            Assert.IsTrue(lists.Count == 3, "Test case invalid if row count is not 3.");
            l1 = lists[0] as MailingList;
            l2 = lists[2] as MailingList;
            Assert.IsTrue(l1.SenderAddress.StartsWith("ann"), "Test case invalid if row order is wrong.");
            Assert.IsTrue(l2.SenderAddress.StartsWith("inf"), "Test case invalid if row order is wrong.");
            // now fetch the reverse ordered list
            sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
            sb.AddOrderByField(false, "SenderAddress");
            sr = Broker.Execute(sb.GetStatement(true));
            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
                          "Wrong number of rows were selected.");
            IList lists2 = ObjectFactory.GetCollection(typeof(MailingList), sr);

            l1 = lists2[0] as MailingList;
            l2 = lists2[2] as MailingList;
            Assert.IsTrue(l1.SenderAddress.StartsWith("inf"), "Result set was in wrong order.");
            Assert.IsTrue(l2.SenderAddress.StartsWith("ann"), "Result set was in wrong order.");
        }
 public void TestCustomListUsingInConstraint()
 {
     // subselects not supported by the inferior mysql engine - skip test.
     if (!Broker.ProviderName.Equals("MySQL"))
     {
         GentleSqlFactory sf = Broker.GetSqlFactory();
         // first, select the number of expected entries
         SqlBuilder sb  = new SqlBuilder(StatementType.Count, typeof(MailingList));
         string     sql = String.Format("select distinct MemberAddress from {0}",
                                        sf.GetTableName("ListMember"));
         sb.AddConstraint(Operator.In, "SenderAddress", Broker.Execute(sql), "MemberAddress");
         SqlResult sr       = Broker.Execute(sb.GetStatement());
         int       expected = sr.Count;
         // verify list retrieval (using IList data)
         IList lists = MailingList.ListByCustomListConstraint();
         Assert.IsNotNull(lists);
         Assert.AreEqual(expected, lists.Count);
         // verify same result using alternative approach (using SqlResult data)
         sb = new SqlBuilder(StatementType.Select, typeof(Member));
         SqlResult members = sb.GetStatement(true).Execute();
         sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
         // use column name as indexer into SqlResult for list constraints
         sb.AddConstraint(Operator.In, "SenderAddress", members, "MemberAddress");
         SqlStatement stmt = sb.GetStatement(true);
         lists = ObjectFactory.GetCollection(typeof(MailingList), stmt.Execute());
         Assert.IsNotNull(lists);
         Assert.AreEqual(expected, lists.Count);
     }
 }
        /// <summary>
        /// Verify parameter order when using unnamed parameters
        /// </summary>
        public void ExecuteTestUnnamedParameterOrder(string providerName)
        {
            GentleSettings.AnalyzerLevel = AnalyzerLevel.None;
            PersistenceBroker broker = new PersistenceBroker(providerName, "...");
            GentleSqlFactory  sf     = broker.GetSqlFactory();

            if (!sf.HasCapability(Capability.NamedParameters))
            {
                // create parameterized query
                SqlBuilder sb = new SqlBuilder(broker, StatementType.Select, typeof(MailingList));
                sb.AddConstraint(Operator.Equals, "SenderAddress", "SenderAddress");
                sb.AddConstraint(Operator.Equals, "Name", "Name");
                SqlStatement stmt = sb.GetStatement(true);
                foreach (IDataParameter param in stmt.Command.Parameters)
                {
                    Assert.IsTrue(param.ParameterName.IndexOf((string)param.Value) >= 0, "1: Parameter order not correctly maintained.");
                }
                // retry using parameters in reverse order
                sb = new SqlBuilder(broker, StatementType.Select, typeof(MailingList));
                sb.AddConstraint(Operator.Equals, "Name", "Name");
                sb.AddConstraint(Operator.Equals, "SenderAddress", "SenderAddress");
                stmt = sb.GetStatement(true);
                foreach (IDataParameter param in stmt.Command.Parameters)
                {
                    Assert.IsTrue(param.ParameterName.IndexOf((string)param.Value) >= 0, "2: Parameter order not correctly maintained.");
                }
            }
        }
Exemplo n.º 4
0
 protected void GetIdentityInformation(TableMap map)
 {
     if (map != null)
     {
         // also obtain identity column information
         GentleSqlFactory sf = provider.GetSqlFactory();
         try
         {
             string tableName = sf.GetTableName(map.TableName);
             foreach (FieldMap fm in map.Fields)
             {
                 if (fm.IsPrimaryKey)
                 {
                     if (!map.IsView)
                     {
                         SqlResult sr = broker.Execute(String.Format(selectIdentityInfo, tableName, fm.ColumnName));
                         fm.SetIsAutoGenerated(sr.GetInt(0, "IsIdentity") == 1);
                     }
                 }
             }
         }
         catch (Exception e)
         {
             Check.LogWarning(LogCategories.Metadata, "Unable to determine whether PK column of table {0} is an identity column.",
                              map.TableName);
             Check.LogWarning(LogCategories.Metadata, e.Message);
         }
     }
 }
        public void TestMagicValue()
        {
            int nullValue = -1;

            a = new PropertyHolder(0, "MyPH", nullValue, nullValue, 4, 5.0, true, new DateTime(2000, 1, 20),
                                   DateTime.Now, "char", "nchar", "varchar", "nvarchar", "text", "ntext");
            // insert
            a.Persist();
            Assert.AreEqual(a.Name, "MyPH");
            // select raw data
            GentleSqlFactory sf = Broker.GetSqlFactory();
            SqlResult        sr = Broker.Execute("select TInt from " + sf.GetTableName("PropertyHolder"));

            // verify that TInt of nullValue was converted to DB null
            Assert.IsNull(sr[0, "TInt"], "NullValue was not converted to null.");
            // verify select/insert
            b = PropertyHolder.Retrieve(a.Id);
            Assert.IsTrue(b.Id != 0);
            Assert.AreEqual(a.Id, b.Id);
            Assert.AreEqual("MyPH", b.Name);
            Assert.AreEqual(nullValue, b.TInt, "Database NULL was not converted to NullValue.");
            Key key = new Key(typeof(PropertyHolder), true, "Id", a.Id);

            b = Broker.RetrieveInstance(typeof(PropertyHolder), key) as PropertyHolder;
            // verify select/insert
            Assert.IsTrue(b.Id != 0);
            Assert.AreEqual(a.Id, b.Id);
            Assert.AreEqual("MyPH", b.Name);
            Assert.AreEqual(nullValue, b.TInt, "Database NULL was not converted to NullValue.");
            // delete
            b.Remove();
        }
Exemplo n.º 6
0
 public void Init()
 {
     try
     {
         GentleSqlFactory sf = Broker.GetSqlFactory();
         // this will throw an exception because under normal operation it would indicate an error
         runTest = sf.GetDbType(typeof(Guid)) != sf.NO_DBTYPE;
     }
     catch
     {
         runTest = false;
     }
 }
        public void TestRangeConstraintCustom()
        {
            SqlBuilder builder = new SqlBuilder(StatementType.Count, typeof(MailingList));

            builder.AddConstraint(Operator.GreaterThanOrEquals, "Id", 2);
            GentleSqlFactory sf     = Broker.GetSqlFactory();
            string           clause = String.Format("{0} < 3", "ListId");

            builder.AddConstraint(clause);
            int count = GetCount(builder);

            Assert.AreEqual(1, count);
        }
Exemplo n.º 8
0
        public void TestTypeListRetrieval()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first, select the number of expected entries
            SqlBuilder sb       = new SqlBuilder(StatementType.Count, typeof(MailingList));
            SqlResult  sr       = Broker.Execute(sb.GetStatement(true));
            int        expected = sr.Count;
            // verify list retrieval (entire table)
            IList lists = MailingList.ListAll;

            Assert.IsNotNull(lists);
            Assert.AreEqual(expected, lists.Count);
        }
Exemplo n.º 9
0
        public virtual void Init(string providerName)
        {
            ObjectFactory.ClearMaps();
            Broker.ClearPersistenceBroker();
            ObjectFactory.ClearMaps();
            IGentleProvider provider = ProviderFactory.GetProvider(providerName, "");

            Assert.AreEqual(provider.Name, providerName, "Wrong provider returned from factory!");
            sf     = provider.GetSqlFactory();
            broker = new PersistenceBroker(provider);
            sb     = new SqlBuilder(provider);
            // make sure analyzer errors are ignored for this test
            origLevel = GentleSettings.AnalyzerLevel;
            GentleSettings.AnalyzerLevel = AnalyzerLevel.None;
        }
Exemplo n.º 10
0
        public void TestCustomListUsingLikeConstraint()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first, select the number of expected entries
            SqlBuilder sb = new SqlBuilder(StatementType.Count, typeof(MailingList));

            sb.AddConstraint(Operator.Like, "SenderAddress", "%.com");
            SqlResult sr       = Broker.Execute(sb.GetStatement(true));
            int       expected = sr.Count;
            // verify list retrieval
            IList lists = MailingList.ListByDomain(".com");

            Assert.IsNotNull(lists);
            Assert.AreEqual(expected, lists.Count);
        }
Exemplo n.º 11
0
 public void Init()
 {
     try
     {
         GentleSqlFactory sf = Broker.GetSqlFactory();
         // this will throw an exception because under normal operation it would indicate an error
         runTest     = (sf.GetDbType(typeof(Guid)) != sf.NO_DBTYPE) || (sf.GetDbType(typeof(byte[])) != sf.NO_DBTYPE);
         picture     = GetPicture();
         pictureSize = GetSize(picture);
     }
     catch
     {
         runTest = false;
     }
 }
Exemplo n.º 12
0
        public void TestOtherTypeListRetrieval()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // select all lists
            IList lists = MailingList.ListAll;

            foreach (MailingList list in lists)
            {
                // get the expected member count
                SqlBuilder sb = new SqlBuilder(StatementType.Count, typeof(Member));
                sb.AddConstraint(Operator.Equals, "ListId", list.Id);
                SqlResult sr       = Broker.Execute(sb.GetStatement(true));
                int       expected = sr.Count;
                // verify list retrieval (entire table)
                IList members = list.Members;
                Assert.IsNotNull(members);
                Assert.AreEqual(expected, members.Count);
            }
        }
Exemplo n.º 13
0
        public void TestCount()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first, select the number of expected entries
            SqlResult sr = Broker.Execute(String.Format("select count(*) as RecordCount from {0}{1}",
                                                        sf.GetTableName("List"), sf.GetStatementTerminator()));

            Assert.IsNotNull(sr);
            Assert.AreEqual(0, sr.ErrorCode);
            Assert.IsNotNull(sr.Rows);
            Assert.AreEqual(1, sr.Rows.Count);
            object[] row      = (object[])sr.Rows[0];
            int      expected = Convert.ToInt32(row[0]);
            // verify StatementType.Count retrieval
            SqlBuilder sb = new SqlBuilder();

            sr = Broker.Execute(sb.GetStatement(StatementType.Count, typeof(MailingList)));
            Assert.AreEqual(expected, sr.Count);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Please refer to the <see cref="GentleAnalyzer"/> class and the <see cref="IDatabaseAnalyzer"/>
        /// interface it implements a description of this method.
        /// </summary>
        public override void Analyze(string tableName)
        {
            GentleSqlFactory sf = provider.GetSqlFactory();

            try
            {
                bool      isSingleRun = tableName != null;
                string    sql         = isSingleRun ? String.Format("{0} and name = '{1}'", selectTables, tableName) : selectTables;
                SqlResult sr          = broker.Execute(sql, null, null);
                for (int row = 0; row < sr.RowsContained; row++)
                {
                    tableName = sr.GetString(row, 0);
                    // get TableMap for current table
                    TableMap map = GetTableMap(tableName);
                    if (map == null)
                    {
                        map = new TableMap(provider, tableName);
                        maps[tableName.ToLower()] = map;
                    }
                    // get column information
                    UpdateTableMapWithColumnInformation(map);
                    // get foreign key information
                    UpdateTableMapWithForeignKeyInformation(map);
                }
            }
            catch (GentleException fe)
            {
                // ignore errors caused by tables found in db but for which no map exists
                // TODO this should be a config option
                if (fe.Error != Error.NoObjectMapForTable)
                {
                    throw;
                }
            }
            catch (Exception e)
            {
                Check.LogInfo(LogCategories.General, "Using provider {0} and connectionString {1}.",
                              provider.Name, provider.ConnectionString);
                Check.Fail(e, Error.Unspecified, "An error occurred while analyzing the database schema.");
            }
        }
Exemplo n.º 15
0
        public void TestSimpleSql()
        {
            GentleSqlFactory sf  = Broker.GetSqlFactory();
            string           sql = String.Format("select count(*) as RecordCount from {0}{1}",
                                                 sf.GetTableName("List"), sf.GetStatementTerminator());
            SqlBuilder   sb   = new SqlBuilder();
            SqlStatement stmt = sb.GetStatement(sql, StatementType.Select, typeof(MailingList));

            Assert.IsNotNull(stmt, "stmt is null");
            SqlResult sr = Broker.Execute(stmt);

            Assert.IsNotNull(sr);
            Assert.AreEqual(0, sr.ErrorCode);
            Assert.IsNotNull(sr.Rows.Count);
            Assert.AreEqual(1, sr.Rows.Count);
            object[] row      = (object[])sr.Rows[0];
            int      expected = Convert.ToInt32(row[0]);

            // verify StatementType.Count retrieval
            sr = Broker.Execute(sb.GetStatement(StatementType.Count, typeof(MailingList)));
            Assert.AreEqual(expected, sr.Count);
        }
Exemplo n.º 16
0
        public void TestRowLimitRetrieval()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();
            // first verify that data set is ok for test
            IList lists = MailingList.ListAll;

            Assert.IsNotNull(lists, "Test case invalid if row count is below 3.");
            Assert.IsTrue(lists.Count >= 3, "Test case invalid if row count is below 3.");
            // try with 1 row limit
            SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(MailingList));

            sb.SetRowLimit(1);
            SqlResult sr = Broker.Execute(sb.GetStatement(true));

            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
            Assert.AreEqual(1, sr.RowsContained, "Result set was not limited.");
            // try again this time with 2 rows
            sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
            sb.SetRowLimit(2);
            sr = Broker.Execute(sb.GetStatement(true));
            Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
            Assert.AreEqual(2, sr.RowsContained, "Result set was not limited.");
        }
Exemplo n.º 17
0
        public override void Analyze(string tableName)
        {
            GentleSqlFactory sf = provider.GetSqlFactory();

            try
            {
                bool isSingleRun = tableName != null;
                // Create foreign key statement
                SqlStatement fk = broker.GetStatement(StatementType.Select, selectReferences);
                sf.AddParameter(fk.Command, "TableName", (long)FbDbType.VarChar);
                sf.AddParameter(fk.Command, "ColumnName", (long)FbDbType.VarChar);
                // Get tables information
                SqlResult sr = broker.Execute(select);
                // process result set
                for (int i = 0; i < sr.Rows.Count; i++)
                {
                    try
                    {
                        string dbTableName = sr.GetString(i, "TableName").Trim();

                        if (!isSingleRun || tableName.ToLower().Equals(dbTableName.ToLower()))
                        {
                            TableMap map = GetTableMap(dbTableName);
                            if (map == null)
                            {
                                map = new TableMap(provider, dbTableName);
                                maps[dbTableName.ToLower()] = map;
                            }

                            // get column information for this table
                            string   columnName = sr.GetString(i, "ColumnName").Trim();
                            FieldMap fm         = map.GetFieldMapFromColumn(columnName);
                            if (fm == null)
                            {
                                fm = new FieldMap(map, columnName);
                                map.Fields.Add(fm);
                            }
                            FbDbType type = GetFbDbType(
                                sr.GetInt(i, "ColumnDataType"),
                                sr[i, "ColumnSubType"] != null ? sr.GetInt(i, "ColumnSubType") : 0,
                                sr[i, "ColumnScale"] != null ? sr.GetInt(i, "ColumnScale") : 0);
                            fm.SetDbType((long)type);
                            if (sr[i, "NullFlag"] == null)
                            {
                                fm.SetIsNullable(true);
                            }
                            else
                            {
                                fm.SetIsNullable(false);
                            }
                            if (sr[i, "ColumnSize"] != null)
                            {
                                switch (type)
                                {
                                case FbDbType.Binary:
                                case FbDbType.Text:
                                    fm.SetSize(Int32.MaxValue);
                                    break;

                                default:
                                    fm.SetSize(sr.GetInt(i, "ColumnSize"));
                                    break;
                                }
                            }
                            if (sr.GetInt(i, "PrimaryKey") > 0)
                            {
                                fm.SetIsPrimaryKey(true);
                            }
                            if (sr.GetInt(i, "ForeignKey") > 0)
                            {
                                fk.SetParameter("TableName", map.TableName.ToUpper());
                                fk.SetParameter("ColumnName", columnName.ToUpper());

                                SqlResult res = fk.Execute();
                                fm.SetForeignKeyTableName(res.GetString(0, "FKTableName").Trim());
                                fm.SetForeignKeyColumnName(res.GetString(0, "FKColumnName").Trim());
                            }
                        }
                    }
                    catch (GentleException fe)
                    {
                        // ignore errors caused by tables found in db but for which no map exists
                        // TODO this should be a config option
                        if (fe.Error != Error.NoObjectMapForTable)
                        {
                            throw fe;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Check.Fail(e, Error.Unspecified, "An error occurred while analyzing the database schema.");
            }
        }
Exemplo n.º 18
0
		public virtual void Init( string providerName )
		{
			ObjectFactory.ClearMaps();
			Broker.ClearPersistenceBroker();
			ObjectFactory.ClearMaps();
			IGentleProvider provider = ProviderFactory.GetProvider( providerName, "" );
			Assert.AreEqual( provider.Name, providerName, "Wrong provider returned from factory!" );
			sf = provider.GetSqlFactory();
			broker = new PersistenceBroker( provider );
			sb = new SqlBuilder( provider );
			// make sure analyzer errors are ignored for this test
			origLevel = GentleSettings.AnalyzerLevel;
			GentleSettings.AnalyzerLevel = AnalyzerLevel.None;
		}
Exemplo n.º 19
0
        public void TestPaging()
        {
            GentleSqlFactory sf = Broker.GetSqlFactory();

            if (sf.HasCapability(Capability.Paging))
            {
                // first verify that data set is ok for test
                IList lists = MailingList.ListAll;
                Assert.IsNotNull(lists, "Test case invalid if row count is below 3.");
                Assert.IsTrue(lists.Count >= 3, "Test case invalid if row count is below 3.");
                // try with 1 row limit
                SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(MailingList));
                sb.SetRowLimit(1);
                SqlResult sr = Broker.Execute(sb.GetStatement(true));
                // verify result
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 1 was not limited.");
                MailingList ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // get next result
                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 2 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // get next result
                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 3 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[2] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");
                // try the previous again
                sr = sr.Previous();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 4 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Try Page Numbers..
                sr = sr.Page(2);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 5 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Page(1);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 6 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Next();
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 7 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[1] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                sr = sr.Page(3);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 8 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[2] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Test for Page 0 - should return first page
                sr = sr.Page(0);
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained > 0, "No rows were selected.");
                Assert.AreEqual(1, sr.RowsContained, "Result set 9 was not limited.");
                ml = ObjectFactory.GetInstance(typeof(MailingList), sr) as MailingList;
                Assert.AreEqual((lists[0] as MailingList).Id, ml.Id, "Wrong row(s) retrieved.");

                //Test for invalid page - should return no rows
                sr = sr.Page(1 + (lists.Count / sr.Statement.RowLimit));
                Assert.IsTrue(sr.ErrorCode == 0 && sr.RowsContained == 0);
            }
        }
        /// <summary>
        /// Please refer to the <see cref="GentleAnalyzer"/> class and the <see cref="IDatabaseAnalyzer"/>
        /// interface it implements a description of this method.
        /// </summary>
        public override void Analyze(string tableName)
        {
            GentleSqlFactory sf = provider.GetSqlFactory();

            try
            {
                bool isSingleRun = tableName != null;
                // don't quote reserved words here (table name is just a string parameter)
                string    sql = isSingleRun ? select + String.Format(selectSingle, tableName) : select;
                SqlResult sr  = broker.Execute(sql, null, null);
                // process result set using columns:
                // TableName, ColumnName, Type, Size, IsNullable, DefaultValue,
                // ConstraintName, ConstraintReference, ConstraintType,
                // UpdateRule, DeleteRule, TableType
                for (int i = 0; i < sr.Rows.Count; i++)
                {
                    try
                    {
                        string dbTableName = sr.GetString(i, "tablename");
                        if (!isSingleRun || tableName.ToLower().Equals(dbTableName.ToLower()))
                        {
                            TableMap map = GetTableMap(dbTableName);
                            if (map == null)
                            {
                                map = new TableMap(provider, dbTableName);
                                maps[dbTableName.ToLower()] = map;
                            }
                            map.IsView = sr.GetString(i, "TableType") == "VIEW";
                            // get column information for this table
                            string   columnName = sr.GetString(i, "ColumnName");
                            FieldMap fm         = map.GetFieldMapFromColumn(columnName);
                            if (fm == null)
                            {
                                fm = new FieldMap(map, columnName);
                                map.Fields.Add(fm);
                            }
                            // get basic column information
                            fm.SetDbType(sr.GetString(i, "Type"), false);                                 // sql server is always false
                            fm.SetIsNullable(GetBoolean(sr.GetString(i, "IsNullable")));
                            fm.SetIsAutoGenerated(sr.GetString(i, "DefaultValue").Length > 0 ? true : false);
                            if (sr[i, "Size"] != null && fm.DbType != (long)SqlDbType.Text)
                            {
                                fm.SetSize(sr.GetInt(i, "Size"));
                            }
                            // get column constraint infomation
                            if (sr[i, "ConstraintName"] != null)
                            {
                                string type = sr.GetString(i, "ConstraintType");
                                if (type.ToLower().Equals("primary key"))
                                {
                                    fm.SetIsPrimaryKey(true);
                                }
                                else if (type.ToLower().Equals("foreign key"))
                                {
                                    string conref = sr.GetString(i, "ConstraintReference");
                                    if (conref.StartsWith("IDX"))
                                    {
                                        string fkRef = sr.GetString(i, "ConstraintName");
                                        if (fkRef != null && fkRef.StartsWith("FK"))
                                        {
                                            conref = fkRef;
                                        }
                                    }
                                    SqlResult res = broker.Execute(String.Format(selectReferences, conref), null, null);
                                    if (res.ErrorCode == 0 && res.RowsContained == 1)
                                    {
                                        fm.SetForeignKeyTableName(res.GetString(0, "TableName"));
                                        fm.SetForeignKeyColumnName(res.GetString(0, "ColumnName"));
                                    }
                                    else
                                    {
                                        if (res.RowsContained == 0)
                                        {
                                            // see GOPF-155 for additional information
                                            Check.LogWarning(LogCategories.Metadata,
                                                             "Unable to obtain foreign key information for column {0} of table {1}.",
                                                             fm.ColumnName, map.TableName);
                                        }
                                        else
                                        {
                                            Check.LogWarning(LogCategories.Metadata, "Gentle 1.x does not support composite foreign keys.");
                                        }
                                    }
                                }
                            }
                            if (map.IsView)
                            {
                                // TODO
                                // process backing table members and infer PK/identity info
                                // requires that tables be processed before views!
                                //
                                //string sv = String.Format( selectViewDependencies, map.TableName );
                                //SqlResult res = broker.Execute( sv );
                            }
                        }
                    }
                    catch (GentleException fe)
                    {
                        // ignore errors caused by tables found in db but for which no map exists
                        // TODO this should be a config option
                        if (fe.Error != Error.NoObjectMapForTable)
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Check.LogInfo(LogCategories.General, "Using provider {0} and connectionString {1}.",
                              provider.Name, provider.ConnectionString);
                Check.Fail(e, Error.Unspecified, "An error occurred while analyzing the database schema.");
            }
        }