Ejemplo n.º 1
0
        public static string TableSchemaDifference(CompareSideType sideType, TableName tableName1, TableName tableName2)
        {
            string sql;

            if (tableName2.Exists())
            {
                TableSchemaCompare compare = new TableSchemaCompare(tableName1, tableName2)
                {
                    SideType = sideType
                };
                sql = compare.Compare();
            }
            else
            {
                sql = tableName1.GenerateCreateTableClause(appendGO: true);
            }

            return(sql);
        }
Ejemplo n.º 2
0
        public void ExportCreate()
        {
            if (tname != null)
            {
                cout.WriteLine("start to generate CREATE TABLE script: {0}", dname);
                using (var writer = SqlFileName.CreateStreamWriter(cmd.Append))
                {
                    writer.WriteLine(tname.GenerateIfDropClause());
                    writer.WriteLine(tname.GenerateCreateTableClause(appendGO: true));
                }
                cout.WriteLine("completed to generate script on file: {0}", SqlFileName);
                return;
            }


            if (dname != null)
            {
                if (cmd.wildcard != null)
                {
                    var         md     = new MatchedDatabase(dname, cmd);
                    TableName[] tnames = md.TableNames();
                    if (tnames.Length > 0)
                    {
                        Stack <string> stack = new Stack <string>();
                        Queue <string> queue = new Queue <string>();
                        foreach (var tname in tnames)
                        {
                            cout.WriteLine("start to generate CREATE TABLE script: {0} ", tname);
                            stack.Push(tname.GenerateIfDropClause());
                            queue.Enqueue(tname.GenerateCreateTableClause(appendGO: true));
                        }

                        using (var writer = SqlFileName.CreateStreamWriter(cmd.Append))
                        {
                            while (stack.Count > 0)
                            {
                                writer.WriteLine(stack.Pop());
                            }

                            while (queue.Count > 0)
                            {
                                writer.WriteLine(queue.Dequeue());
                            }
                        }
                    }
                    else
                    {
                        cerr.WriteLine("warning: no table is matched");
                        return;
                    }
                }
                else
                {
                    cout.WriteLine("start to generate CREATE TABLE script: {0}", dname);
                    using (var writer = SqlFileName.CreateStreamWriter(cmd.Append))
                    {
                        writer.WriteLine(dname.GenerateClause());
                    }
                }

                cout.WriteLine("completed to generate script on file: {0}", SqlFileName);
                return;
            }

            cerr.WriteLine("warning: table or database is not seleted");
        }