示例#1
0
        /// <summary>
        /// Generates a querie list to create tables.
        /// <para/>
        /// SQL query Example: <para/>
        /// CREATE TABLE table1 (id INTEGER PRIMARY KEY, firstColumn TEXT NOT NULL, secondColumn REAL NOT NULL)
        /// </summary>
        /// <returns>Returns a list of queries to create the local tables.</returns>
        private List <string> CreateTableQueries(ConcurrentDictionary <string, Table> tables)
        {
            try
            {
                List <string> tableQueries = new List <string>();
                foreach (KeyValuePair <string, Table> table in tables)
                {
                    SQLQueryBuilder sqb       = new SQLQueryBuilder();
                    List <string>   paramList = new List <string>();

                    int iter = 0;
                    foreach (KeyValuePair <string, Type> column in table.Value.Columns)
                    {
                        sqb.AddValue(column.Key);
                        if (column.Value == typeof(int))
                        {
                            sqb.TypeInteger();
                        }
                        else if (column.Value == typeof(string))
                        {
                            sqb.TypeText();
                        }
                        else if (column.Value == typeof(double))
                        {
                            sqb.TypeReal();
                        }
                        else if (column.Value == typeof(float))
                        {
                            sqb.TypeReal();
                        }
                        else if (column.Value == typeof(DateTime))
                        {
                            sqb.TypeText();
                        }
                        else
                        {
                            throw new NotSupportedException(column.Value.Name + " Datatype not supported");
                        }

                        if (iter.Equals(0))
                        {
                            sqb.ParamPrimaryKey();
                        }
                        else
                        {
                            sqb.ParamNot().Null();
                        }

                        paramList.Add(sqb.Flush());
                        iter++;
                    }
                    string values = sqb.Brackets_Multiple(paramList, false).Flush();
                    sqb.Create().Table().IfNotExists().AddValue(table.Value.TableName).AddValue(values);
                    tableQueries.Add(sqb.ToString());
                    tableQueries.Add(CreateTriggerTable(table.Value.TableName));
                    tableQueries.Add(InsertStartValueTriggerTable(table.Value.TableName));
                    tableQueries.Add(CreateCounterAddTriger(table.Value.TableName));
                    tableQueries.Add(CreateCounterSubTriger(table.Value.TableName));
                }
                return(tableQueries);
            }
            catch (Exception)
            {
                throw;
            }
        }