private bool PopulateEmptyDatabase(GenConnection con, String databaseType)
        {
            DDL DDL;

            if (databaseType == "MySql")
                if (GlobalSettings.ApplicationSettings.DatabaseVersion == "5.6")
                    DDL = new MySql_5_6_DDL();
                else
                    DDL = new MySql_DDL();
            else if (databaseType == "Jet")
                DDL = new Jet_DDL();
            else if (databaseType == "SQLite")
                DDL = new SQLite_DDL();
            else if (databaseType == "SQL Server")
                DDL = new SQLServer_DDL();
            else
                throw new Exception("Unexpected database type: " + databaseType);

            bool success = true;

            if (success && !RelationExists(con, "devicetype"))
                success &= CreateRelation(DDL.CurrentTable_devicetype, con);
            if (success && !RelationExists(con, "device"))
                success &= CreateRelation(DDL.CurrentTable_device, con);
            if (success && !RelationExists(con, "devicefeature"))
                success &= CreateRelation(DDL.CurrentTable_devicefeature, con);
            if (success && !RelationExists(con, "devicereading_energy"))
                success &= CreateRelation(DDL.CurrentTable_devicereading_energy, con);
            if (success && !RelationExists(con, "devicedayoutput_v"))
                success &= CreateRelation(DDL.CurrentView_devicedayoutput_v, con);
            if (success && !RelationExists(con, "pvoutputlog"))
                success &= CreateRelation(DDL.CurrentTable_pvoutputlog, con);

            if (success && !RelationExists(con, "version"))
                success &= CreateRelation(DDL.CurrentTable_version, con);

            if (success)
                UpdateVersion("2", "0", "0", "0", con);

            return success;
        }
        private DDL SelectDDL(String databaseType)
        {
            DDL DDL;

            if (databaseType == "MySql")
                if (GlobalSettings.ApplicationSettings.DatabaseVersion == "5.6")
                    DDL = new MySql_5_6_DDL();
                else
                    DDL = new MySql_DDL();
            else if (databaseType == "Jet")
                DDL = new Jet_DDL();
            else if (databaseType == "SQLite")
                DDL = new SQLite_DDL();
            else if (databaseType == "SQL Server")
                DDL = new SQLServer_DDL();
            else
                throw new Exception("Unexpected database type: " + databaseType);
            return DDL;
        }
        public bool UpdateTo_1_5_0_2(GenConnection con, String databaseType)
        {
            DDL DDL;
            int res;

            res = Version.CompareVersion("1", "5", "0", "2");
            if (res >= 0)
                return false;

            bool success = true;

            if (databaseType == "SQL Server")
            {
                DDL = new SQLServer_DDL();

                GlobalSettings.LogMessage("UpdateTo_1_5_0_2", "Updating database structure to suit version 1.5.0.2", LogEntryType.Information);

                success &= AlterRelation(((SQLServer_DDL)DDL).Alter_cmsdata_1502, con);
            }

            if (success)
                UpdateVersion("1", "5", "0", "2", con);

            return success;
        }