Пример #1
0
        internal DatabaseQueries GenerateSubSectionsTable(DataProviders provider)
        {
            SubSection subsection = null;
            bool       found      = false;

            foreach (Questionaire qn in _questionaires.Where(c => c is Questionaire).Cast <Questionaire>())
            {
                foreach (Section section in qn.Sections)
                {
                    var hasSubSections = section.SubSections.Count > 0;
                    if (!hasSubSections)
                    {
                        continue;
                    }

                    subsection = section.SubSections[0];
                    found      = true;
                    break;
                }
                if (found)
                {
                    break;
                }
            }

            if (subsection == null)
            {
                return(null);
            }

            DatabaseQueries databaseQueries = subsection.GenerateTableScript("dsto_subsections", provider);

            return(databaseQueries);
        }
Пример #2
0
 public void Append(DatabaseQueries queries)
 {
     foreach (DatabaseQuery result in queries)
     {
         _queries.Add(result);
     }
 }
Пример #3
0
        public DatabaseQueries CreateForeignKeyConstraints(DataProviders provider)
        {
            DatabaseQueries dbQueries = new DatabaseQueries();

            foreach (DataCollectionObject obj in _questionaires)
            {
                // dbQueries.Append(obj.AddForeignKeyConstraints(provider));
            }
            return(dbQueries);
        }
Пример #4
0
        public DatabaseQueries GenerateDatabase(DataProviders provider, EnumLists importedLists = null)
        {
            DatabaseQueries queries = new DatabaseQueries();

            if (importedLists == null)
            {
                foreach (var list in _enumLists)
                {
                    queries.Append(list.GenerateDatabase(provider));
                }
            }
            else
            {
                EnumList importedList = null;
                //Get lists to create and update
                foreach (var list in _enumLists)
                {
                    importedList = importedLists.ByKey(list.Key);
                    if (importedList == null)
                    {
                        //Create the list
                        queries.Append(list.GenerateDatabase(provider));
                    }
                    else
                    {
                        //update the selected list table
                        //if the lists have changed then update
                        if (list.CompareTo(importedList) == 0)
                        {
                            queries.Append(list.GenerateDatabase(provider, importedList));
                        }
                    }
                }

                //Get lists to delete
                EnumList toDelete = null;
                foreach (var list in importedLists)
                {
                    toDelete = ByKey(list.Key);
                    if (toDelete == null)
                    {
                        //Call delete query generator
                        queries.Add(list.GenerateDatabaseDrop(provider));
                    }
                }
            }

            return(queries);
        }
Пример #5
0
        public DatabaseQueries Insert()
        {
            DatabaseQueries dbQueries = new DatabaseQueries();

            DatabaseQuery dbQuery = new DatabaseQuery();

            dbQuery.FriendlyMessage = "inserting into dsto_section";

            string query = string.Empty;

            query += string.Format("INSERT INTO dsto_questionaire (guid,name,yref_questionaire) values('{0}','{1}')", Key, Name, Parent.Parent.Key);
            dbQuery.SqlStatement = query;
            dbQuery.Name         = TableName;
            dbQuery.Message      = Messages.InsertRecord;
            dbQueries.Add(dbQuery);


            return(dbQueries);
        }
Пример #6
0
        internal DatabaseQueries GenerateSectionsXQuestionTable(DataProviders provider)
        {
            DatabaseQueries databaseQueries = new DatabaseQueries();
            DatabaseQuery   dbQuery         = new DatabaseQuery();

            dbQuery.Name    = "dsto_sectionXquestion";
            dbQuery.Message = Messages.CreateTable;
            var query = "create table dsto_sectionXquestion\n";

            query += "(\n";
            query += "oid int identity(1,1) primary key,";
            query += "guid uniqueidentifier default newid(),";
            query += "created_on datetime getdate(),";
            query += "created_by varchar(50),";
            query += "lastupdated_by varchar(50),";
            query += "lastupdated_on datetime,";
            query += "yref_question uniqueidentifier references [dsto_questions]([guid]),";
            query += "yref_section uniqueidentifier references [dsto_sections]([guid])";
            dbQuery.SqlStatement = query;
            return(databaseQueries);
        }
Пример #7
0
        internal DatabaseQueries AddForeignKeyConstraints()
        {
            DatabaseQueries queries = new DatabaseQueries();

            //string questionQuery = string.Empty;

            //string answerQuery = string.Empty;

            ////ConnectionSettings settings = Configuration.DataStores.Default.Settings;

            //DataProviders provider = settings.Provider;

            ////question key
            //switch (provider)
            //{
            //    case DataProviders.SQL:
            //        questionQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES questions_table(oid)";
            //        answerQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES {AnswerList.TableName}(oid)";
            //        break;
            //    case DataProviders.SQLite:
            //        questionQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES questions_table(oid)";
            //        answerQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES {AnswerList.TableName}(oid)";
            //        break;
            //    case DataProviders.MYSQL:
            //        questionQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES questions_table(oid)";
            //        answerQuery = $"ADD ALTER {TableName} ADD CONSTRAINT FK_X_questions_table FOREIGN KEY REFERENCES {AnswerList.TableName}(oid)";
            //        break;
            //    default:
            //        break;
            //}

            //for(int i=1;i<=2;i++)
            //{
            //    //DatabaseQuery query = new DatabaseQuery();
            //    //query.SqlStatement
            //}

            return(queries);
        }
Пример #8
0
        public DatabaseQueries GenerateDatabase(DataProviders provider, Questionaires importedDataObjects = null)
        {
            DatabaseQueries queries = new DatabaseQueries();

            if (importedDataObjects == null)
            {
                foreach (Questionaire dataObject in _questionaires)
                {
                    queries.Append(dataObject.GenerateDatabase(provider));
                }
            }
            else
            {
                //first drop
                DataCollectionObject configObj = null;

                foreach (Questionaire form in importedDataObjects)
                {
                    configObj = ByKey(form.Key);
                    if (configObj == null)
                    {
                        //drop it
                        queries.Append(form.DropTable());
                    }
                }


                ////first check the cached config and add a data object thats missing
                foreach (DataCollectionObject form in _questionaires)
                {
                    var importedDataObject = importedDataObjects.ByKey(form.Key);
                    if (importedDataObject == null)
                    {
                        queries.Append(form.GenerateDatabase(provider));
                    }
                }
            }
            return(queries);
        }
Пример #9
0
        internal DatabaseQueries GenerateSectionsTable(DataProviders provider)
        {
            Section section = null;

            foreach (Questionaire qn in _questionaires.Where(c => c is Questionaire).Cast <Questionaire>())
            {
                var hasSections = qn.Sections.Count() > 0;
                if (!hasSections)
                {
                    continue;
                }
                section = qn.Sections[0];
                break;
            }
            if (section == null)
            {
                return(null);
            }
            DatabaseQueries databaseQueries = section.GenerateTableScript("dsto_sections", provider);

            return(databaseQueries);
        }