Inheritance: ISchemaBackend
Beispiel #1
0
    static int do_push(ISchemaBackend remote, string dir, VxCopyOpts opts)
    {
        log.print("Pushing schema.\n");
        VxDiskSchema disk = new VxDiskSchema(dir);

        VxSchemaErrors errs = VxSchema.CopySchema(disk, remote, opts);

	int code = 0;
        foreach (var p in errs)
	{
            foreach (var err in p.Value)
            {
                Console.WriteLine("{0} applying {1}: {2} ({3})", 
                    err.level, err.key, err.msg, err.errnum);
                code = 1;
            }
	}
	
	return code;
    }
Beispiel #2
0
    public static int _Main(string[] args)
    {
	// command line options
	VxCopyOpts opts = VxCopyOpts.Verbose;
    
	int verbose = (int)WvLog.L.Info;
	string outfile = null;
        var global_syms = new Dictionary<string,string>();
        var extra = new OptionSet()
            .Add("n|dry-run", delegate(string v) { opts |= VxCopyOpts.DryRun; } )
            .Add("f|force", delegate(string v) { opts |= VxCopyOpts.Destructive; } )
            .Add("v|verbose", delegate(string v) { verbose++; } )
            .Add("g|global-sym=", delegate(string v) 
                { 
                    var splitopts = StringSplitOptions.RemoveEmptyEntries;
                    char[] splitchars = {',', ';', ':'};
                    if (v.ne()) 
                        foreach (var sym in v.Split(splitchars, splitopts))
                            global_syms.Add(sym.ToLower(), null); 
                } )
	    .Add("o|output-file=", delegate(string v) { outfile = v; })
            .Parse(args);

	WvLog.maxlevel = (WvLog.L)verbose;
	
	if (extra.Count < 1)
	{
            ShowHelp();
            return 97;
	}
	
	string cmd = extra[0];
	if (cmd == "pascalgen")
	    return pascalgen_Main(extra, global_syms, outfile);
	
	WvIni bookmarks = new WvIni(
		    wv.PathCombine(wv.getenv("HOME"), ".wvdbi.ini"));
	
	string moniker = extra.Count > 1 
	    ? extra[1] : bookmarks.get("Defaults", "url", null);
        string dir     = extra.Count > 2 ? extra[2] : ".";
	
	if (cmd == "dfix")
        {
            VxDiskSchema disk = new VxDiskSchema(dir);
            bool consider_rules = true;
            if (consider_rules)
                return disk.FixSchemaData(disk.GetReplaceRules(),
                                          disk.GetFieldsToSkip());
            else
                return disk.FixSchemaData(null,null);
        }
	
	if (moniker.e())
	{
	    ShowHelp();
	    return 96;
	}
	
	// look up a bookmark if it exists, else use the provided name as a
	// moniker
	moniker = bookmarks.get("Bookmarks", moniker, moniker);

	// provide a default username/password if they weren't provided
	// FIXME: are there URLs that should have a blank username/password?
	WvUrl url = new WvUrl(moniker);
	if (url.user.e())
	    url.user = bookmarks.get("Defaults", "user");
	if (url.password.e())
	    url.password = bookmarks.get("Defaults", "password");
	    
	using (var backend = GetBackend(url))
	{
	    bookmarks.set("Defaults", "url", url.ToString(true));
	    bookmarks.maybeset("Defaults", "user", url.user);
	    bookmarks.maybeset("Defaults", "password", url.password);
	    
	    string p = url.path.StartsWith("/") 
		? url.path.Substring(1) : url.path;
	    bookmarks.set("Bookmarks", p, url.ToString(true));
	    
	    try {
		bookmarks.save();
	    } catch (IOException) {
		// not a big deal if we can't save our bookmarks.
	    }
	    
	    if (cmd == "remote")
		return 0; // just saved the bookmark, so we're done
	    else if (cmd == "pull")
		do_pull(backend, dir, opts);
	    else if (cmd == "push")
		do_push(backend, dir, opts);
	    else if (cmd == "dpull")
		do_dpull(backend, dir, opts);
	    else if (cmd == "dpush")
		do_dpush(backend, dir, opts);
	    else
	    {
		Console.Error.WriteLine("\nUnknown command '{0}'\n", cmd);
		ShowHelp();
	    }
	}
	
	return 0;
    }
Beispiel #3
0
    static void do_pascalgen(string classname, string dir, 
        Dictionary<string,string> global_syms, string outfile)
    {
        if (!classname.StartsWith("T"))
        {
            Console.Error.Write("Classname must start with T.\n");
            return;
        }
	
	Console.Error.Write("Generating Pascal file...\n");
	
        // Replace leading 'T' with a 'u'
        string unitname = "u" + classname.Remove(0, 1);

        VxDiskSchema disk = new VxDiskSchema(dir);
        VxSchema schema = disk.Get(null);

        var types = new List<string>();
        var iface = new List<string>();
        var impl = new List<string>();
        var setters = new List<string>();

        var keys = schema.Keys.ToList();
        keys.Sort(StringComparer.Ordinal);
        foreach (var key in keys)
        {
            var elem = schema[key];
            if (elem.type != "Procedure")
                continue;

            var sp = new StoredProcedure(elem.text);

            var pargs = new List<PascalArg>();
            foreach (SPArg arg in sp.args)
                pargs.Add(new PascalArg(elem.name, arg));

            var decls = new List<string>();
            var impls = new List<string>();
            var ctors = new List<string>();
            foreach (PascalArg parg in pargs)
            {
                if (!global_syms.ContainsKey(parg.varname.ToLower()))
                {
                    decls.Add(parg.GetDecl());
                    impls.Add(parg.GetDefine());
                    ctors.Add(parg.GetCtor());
                }
                else
                {
                    string old = global_syms[parg.varname.ToLower()];
                    if (old.ne() && old.ToLower() != parg.pascaltype.ToLower())
                    {
                        log.print("Definition for global '{0}' differs!  " + 
                            "old '{1}', new '{2}'\n", 
                            parg.varname, old, parg.pascaltype);
                    }
                    else
                    {
                        // The global declaration supplants the local
                        // declaration and implementation, but not the ctor.
                        global_syms[parg.varname.ToLower()] = parg.pascaltype;
                        ctors.Add(parg.GetCtor());
                    }
                }
            }

            // Factory function that produces builder objects
            iface.Add(wv.fmt("function {0}\n"
                + "       ({1}): _T{0};\n",
                elem.name, decls.join(";\n        ")));

            // Actual implementation of the factory function
            impl.Add(wv.fmt(
                "function {0}.{1}\n"
                + "       ({2}): _T{1};\n"
                + "begin\n"
                + "    result := _T{1}.Create(db)\n"
                + "        {3};\n"
                + "end;\n\n",
                classname, elem.name, 
                impls.join(";\n        "),
                ctors.join("\n        ")
                ));

            var memberdecls = new List<string>();
            var methoddecls = new List<string>();
            foreach (PascalArg parg in pargs)
            {
                memberdecls.Add(parg.GetMemberDecl());
                methoddecls.Add(parg.GetMethodDecl());
            }

            // Declaration for per-procedure builder class
            types.Add("_T" + elem.name + " = class(TPwDataCmd)\n"
                + "  private\n"
                + "    " + memberdecls.join("\n    ") + "\n"
                + "  public\n"
                + "    function MakeRawSql: string; override;\n"
                + "    " + methoddecls.join("\n    ") + "\n"
                + "  end;\n"
                );

            // Member functions of the builder classes

            var argstrs = new List<string>();
            var argcalls = new List<string>();
            foreach (PascalArg parg in pargs)
            {
                argstrs.Add(wv.fmt("'{0}'", parg.varname));
                argcalls.Add(parg.call);
            }

            setters.Add(wv.fmt(
                "function _T{0}.MakeRawSql: string;\n"
                + "begin\n"
                + "    result := TPwDatabase.ExecStr('{0}',\n"
                + "       [{1}],\n"
                + "       [{2}]);\n"
                + "end;\n\n",
                elem.name, 
                argstrs.join( ",\n        "), 
                argcalls.join(",\n        ")));

            foreach (PascalArg parg in pargs)
                setters.Add(parg.GetSetters());
        }

        var sb = new StringBuilder();
        sb.Append("(*\n"
            + " * THIS FILE IS AUTOMATICALLY GENERATED BY sm.exe\n"
            + " * DO NOT EDIT!\n"
            + " *)\n"
            + "unit " + unitname + ";\n\n");

        var global_syms_keys = global_syms.Keys.ToList();
        global_syms_keys.Sort();
        var globalfields = new List<string>();
        var globalprops = new List<string>();
        foreach (var sym in global_syms_keys)
        {
            string type = global_syms[sym];
            if (type.e())
            {
                log.print(WvLog.L.Error, 
                    "Global symbol '{0}' is never used in any procedure!\n", 
                    sym);
                return;
            }
            globalfields.Add(wv.fmt("p_{0}: {1};", sym, type));
            globalprops.Add(wv.fmt("property {0}: {1}  read p_{0} write p_{0};",
                sym, type));
        }

        sb.Append("interface\n\n"
            + "uses Classes, uPwData;\n"
            + "\n"
            + "{$M+}\n"
            + "type\n"
            + "  " + types.join("\n  ")
            + "  \n"
            + "  " + classname + " = class(TComponent)\n"
            + "  private\n"
            + "    fDb: TPwDatabase;\n"
            + "    " + globalfields.join("\n    ") + "\n"
            + "  published\n"
            + "    property db: TPwDatabase  read fDb write fDb;\n"
            + "    " + globalprops.join("\n    ") + "\n"
            + "  public\n"
            + "    constructor Create(db: TPwDatabase); reintroduce;\n"
            + "    " + iface.join("    ")
            + "  end;\n\n");

        sb.Append("implementation\n"
            + "\n"
            + "constructor " + classname + ".Create(db: TPwDatabase);\n"
            + "begin\n"
	    + "    inherited Create(db);\n"
            + "    self.db := db;\n"
            + "end;\n"
            + "\n"
            + impl.join("")
            );

        sb.Append(setters.join(""));

        sb.Append("\n\nend.\n");

	if (outfile.e())
	    Console.Write(sb.ToString());
	else
	{
	    Console.Error.Write("Writing file: {0}\n", outfile);
	    using (var f = new FileStream(outfile,
			  FileMode.Create, FileAccess.Write))
	    {
		f.write(sb.ToUTF8());
	    }
	}
	
	Console.Error.Write("Done.\n");
    }
Beispiel #4
0
    public string CsvFix(string tablename, string csvtext)
    {
        List<string> result = new List<string>();
        WvCsv csvhandler = new WvCsv(csvtext);
        string coltype, colsstr;
        List<string> values = new List<string>();
        List<string> cols = new List<string>();
        List<string> allcols = new List<string>();
        int[] fieldstoskip = new int[skipfields.Count];
        
        for (int i=0; i < skipfields.Count; i++)
            fieldstoskip[i] = -1;

        Dictionary<string,string> coltypes = new Dictionary<string,string>();
        VxDiskSchema disk = new VxDiskSchema(exportdir);
        VxSchema schema = disk.Get(null);
        
        Console.WriteLine("Fixing data of table ["+tablename+"]");
        string[] csvcolumns = (string[])csvhandler.GetLine()
                                        .ToArray(Type.GetType("System.String"));
        for (int i=0; i<csvcolumns.Length; i++)
            csvcolumns[i] = csvcolumns[i].ToLower();

        int ii = 0;
        foreach (KeyValuePair<string,VxSchemaElement> p in schema)
        {
            if (!(p.Value is VxSchemaTable))
                continue;
                
            if (((VxSchemaTable)p.Value).name.ToLower() != tablename.ToLower())
                continue;

            foreach (VxSchemaTableElement te in ((VxSchemaTable)p.Value))
            {
                if (te.GetElemType() != "column")
                    continue;
                    
                if (csvcolumns.Contains(te.GetParam("name").ToLower()))
                    coltypes.Add(te.GetParam("name").ToLower(),
                                 te.GetParam("type"));
        
                allcols.Add(te.GetParam("name").ToLower());
                if (csvcolumns.Contains(te.GetParam("name").ToLower()))
                {
                    if (skipfields.Contains(te.GetParam("name").ToLower()))
                        fieldstoskip[skipfields.IndexOf(
                                    te.GetParam("name").ToLower())] = ii;
                    else if (skipfields.Contains(
                                    tablename.ToLower()+"."+
                                    te.GetParam("name").ToLower()))
                        fieldstoskip[skipfields.IndexOf(
                                    tablename.ToLower()+"."+
                                    te.GetParam("name").ToLower())] = ii;
                    else
                        cols.Add(te.GetParam("name"));
                }

                ii++;
            }
        }
        colsstr = "\"" + cols.join("\",\"") + "\"\n";
        
        if (!csvhandler.hasMore())
            return colsstr;
        
        while (csvhandler.hasMore())
        {
            string[] asarray = (string[])csvhandler.GetLine()
                                       .ToArray(Type.GetType("System.String"));

            if (asarray.Length != csvcolumns.Length)
                return "";
                
            values.Clear();
            
            for (int i=0;i<asarray.Length;i++)
            {
                if (Array.IndexOf(fieldstoskip,i)>=0)
                    continue;

                if (replaces.ContainsKey(csvcolumns[i]))
                    asarray[i] = replaces[csvcolumns[i]];
                    
                if (replaces.ContainsKey(tablename.ToLower() + "." +
                                         csvcolumns[i]))
                    asarray[i] = replaces[tablename.ToLower() + "." +
                                          csvcolumns[i]].ToLower();

                if (coltypes.ContainsKey(csvcolumns[i]) && 
                    (coltypes[csvcolumns[i]] != null))
                    coltype = coltypes[csvcolumns[i]];
                else
                    coltype = "";
                    
                if (asarray[i] == null)
                    values.Add("");
                else if ((coltype == "varchar") ||
                         (coltype == "datetime") ||
                         (coltype == "char") ||
                         (coltype == "nchar") ||
                         (coltype == "text"))
                {
                    // Double-quote chars for SQL safety
                    string esc = asarray[i].Replace("\"", "\"\"");
                    
                    //indication that single quotes are already doubled
                    if (esc.IndexOf("''") < 0)
                        esc = esc.Replace("'", "''");
                        
                    if (WvCsv.RequiresQuotes(esc))
                        values.Add('"' + esc + '"');
                    else
                        values.Add(esc);
                }
                else if (coltype == "image")
                {
                    string temp = asarray[i].Replace("\n","");
                    string tmp = "";
                    while (temp.Length > 0)
                    {
                        if (temp.Length > 75)
                        {
                            tmp += temp.Substring(0,76) + "\n";
                            temp = temp.Substring(76);
                        }
                        else
                        {
                            tmp += temp + "\n";
                            break;
                        }
                    }
                    values.Add("\""+tmp+"\"");
                }
                else
                    values.Add(asarray[i]);
            }
            result.Add(values.join(",") + "\n");
        }

        result.Sort(StringComparer.Ordinal);

        return colsstr+result.join("");
    }
Beispiel #5
0
    // Adds the contents of extradir to the provided schema and sums.
    // Throws an ArgumentException if the directory contains an entry that
    // already exists in schema or sums.
    public static void AddFromDir(string extradir, VxSchema schema, 
        VxSchemaChecksums sums)
    {
        VxDiskSchema disk = new VxDiskSchema(extradir);

        disk.ReadExportedDir(schema, sums);
    }
Beispiel #6
0
    public void TestSubmoduleExceptions()
    {
        VxSchema schema1 = new VxSchema();
        VxSchemaChecksums sums1 = new VxSchemaChecksums();

        VxSchema schema2 = new VxSchema();
        VxSchemaChecksums sums2 = new VxSchemaChecksums();

        schema1.Add("Procedure", "Func1", "Random contents", false);
        sums1.AddSum("Procedure/Func1", 1);
        schema2.Add("Procedure", "Func1", "Random contents 2", false);
        sums2.AddSum("Procedure/Func1", 2);

        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema disk = new VxDiskSchema(tmpdir);

            disk.Put(schema2, sums2, VxPutOpts.None);

            try {
                WVEXCEPT(VxDiskSchema.AddFromDir(tmpdir, schema1, sums1))
            } catch (System.ArgumentException e) {
                WVPASSEQ(e.Message, "Conflicting schema key: Procedure/Func1");
            }
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
    }
Beispiel #7
0
    public void TestCopySchema()
    {
        SchemaCreator sc = new SchemaCreator(this);
        sc.Create();

        string msg2 = "Hello, world, this used to be Func1!";
        string func1q2 = "create procedure Func1 as select '" + msg2 + "'\n";

        VxSchema origschema = dbus.Get();
        VxSchemaChecksums origsums = dbus.GetChecksums();

        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema disk = new VxDiskSchema(tmpdir);

            // Test that the copy function will create new elements
            VxSchema.CopySchema(dbus, disk);

            VxSchema newschema = disk.Get(null);
            VxSchemaChecksums newsums = disk.GetChecksums();

            WVPASS(1);
            TestSchemaEquality(origschema, newschema);
            WVPASS(2);
            TestChecksumEquality(origsums, newsums);
            WVPASS(3);

            // Test that the copy function updates changed elements, and
            // deletes old ones.
            origschema["Procedure/Func1"].text = func1q2;

            dbus.Put(origschema, null, VxPutOpts.None);
            dbus.DropSchema("Table/Tab2");
            origschema.Remove("Table/Tab2");
            origsums = dbus.GetChecksums();

            VxSchema.CopySchema(dbus, disk);
            newschema = disk.Get(null);
            newsums = disk.GetChecksums();

            WVPASS(4);
            TestSchemaEquality(origschema, newschema);
            WVPASS(5);
            TestChecksumEquality(origsums, newsums);
            WVPASS(6);
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
        sc.Cleanup();
    }
Beispiel #8
0
    public void TestReadChecksums()
    {
        SchemaCreator sc = new SchemaCreator(this);
        sc.Create();

        string tmpdir = GetTempDir();

        DirectoryInfo tmpdirinfo = new DirectoryInfo(tmpdir);
        try
        {
            tmpdirinfo.Create();

            VxSchema schema = dbus.Get();
            VxSchemaChecksums sums = dbus.GetChecksums();
            VxDiskSchema backend = new VxDiskSchema(tmpdir);
            backend.Put(schema, sums, VxPutOpts.None);

            VxSchemaChecksums fromdisk = backend.GetChecksums();

            foreach (KeyValuePair<string, VxSchemaChecksum> p in sums)
                WVPASSEQ(p.Value.GetSumString(), 
			 fromdisk[p.Key].GetSumString());
            WVPASSEQ(sums.Count, fromdisk.Count);

            // Test that changing a file invalidates its checksums, and that
            // we skip directories named "DATA"
            using (StreamWriter sw = File.AppendText(
			     wv.PathCombine(tmpdir, "Table", "Tab1")))
            {
                sw.WriteLine("Ooga Booga");
            }

            Directory.CreateDirectory(Path.Combine(tmpdir, "DATA"));
            File.WriteAllText(wv.PathCombine(tmpdir, "DATA", "Decoy"),
                "Decoy file, shouldn't have checksums");

            VxSchemaChecksums mangled = backend.GetChecksums();

            // Check that the decoy file didn't get read
            WVFAIL(mangled.ContainsKey("DATA/Decoy"));

            // Check that the mangled checksums exist, but are empty.
            WVASSERT(mangled.ContainsKey("Table/Tab1"));
            WVASSERT(mangled["Table/Tab1"].GetSumString() != 
                sums["Table/Tab1"].GetSumString());
            WVPASSEQ(mangled["Table/Tab1"].GetSumString(), "");

            // Check that everything else is still sensible
            foreach (KeyValuePair<string, VxSchemaChecksum> p in sums)
            {
                if (p.Key != "Table/Tab1")
                    WVPASSEQ(p.Value.GetSumString(), 
                        mangled[p.Key].GetSumString());
            }
        }
        finally
        {
            tmpdirinfo.Delete(true);
            sc.Cleanup();
        }
	WVASSERT(!tmpdirinfo.Exists);
    }
Beispiel #9
0
    public void TestSubmoduleSupport()
    {
        VxSchema schema1 = new VxSchema();
        VxSchemaChecksums sums1 = new VxSchemaChecksums();

        VxSchema schema2 = new VxSchema();
        VxSchemaChecksums sums2 = new VxSchemaChecksums();

        schema1.Add("Table", "Tab1", "column: name=random\n", false);
        sums1.AddSum("Table/Tab1", 1);
        schema2.Add("Table", "Tab2", "column: name=ignored\n", false);
        sums2.AddSum("Table/Tab2", 2);

        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema disk = new VxDiskSchema(tmpdir);

            disk.Put(schema2, sums2, VxPutOpts.None);

            VxDiskSchema.AddFromDir(tmpdir, schema1, sums1);

            WVPASSEQ(sums1["Table/Tab1"].GetSumString(), "0x00000001");
            WVPASSEQ(schema1["Table/Tab1"].name, "Tab1");
            WVPASSEQ(schema1["Table/Tab1"].type, "Table");
            WVPASSEQ(schema1["Table/Tab1"].text, "column: name=random\n");
            WVPASSEQ(schema1["Table/Tab1"].encrypted, false);

            WVPASSEQ(sums1["Table/Tab2"].GetSumString(), "0x00000002");
            WVPASSEQ(schema1["Table/Tab2"].name, "Tab2");
            WVPASSEQ(schema1["Table/Tab2"].type, "Table");
            WVPASSEQ(schema1["Table/Tab2"].text, "column: name=ignored\n");
            WVPASSEQ(schema1["Table/Tab2"].encrypted, false);
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
    }
Beispiel #10
0
    public void TestExportSchema()
    {
        SchemaCreator sc = new SchemaCreator(this);

        string tmpdir = GetTempDir();

        DirectoryInfo tmpdirinfo = new DirectoryInfo(tmpdir);
        try
        {
            tmpdirinfo.Create();

            // Establish a baseline for the number of existing elements.
            VxSchema schema = dbus.Get();
            VxSchemaChecksums sums = dbus.GetChecksums();

            VxDiskSchema disk = new VxDiskSchema(tmpdir);
            disk.Put(schema, sums, VxPutOpts.None);

            var base_filecounts = GetFileCounts(tmpdir);

            // Clobber the directory and start fresh.
            tmpdirinfo.Delete(true);
            tmpdirinfo.Create();

            // Now create our test schema and do the real tests.
            sc.Create();

            // Check that having mangled checksums fails
            schema = dbus.Get();
            sums = new VxSchemaChecksums();

            disk = new VxDiskSchema(tmpdir);
            try {
                WVEXCEPT(disk.Put(schema, sums, VxPutOpts.None));
            } catch (Wv.Test.WvAssertionFailure e) {
                throw e;
            } catch (System.Exception e) {
                WVPASS(e is ArgumentException);
                WVPASS(e.Message.StartsWith("Missing checksum for "));
                log.print(e.ToString() + "\n");
            }

            // Check that the normal exporting works.
            schema = dbus.Get();
            sums = dbus.GetChecksums();

            WVPASSEQ(schema.Count, sums.Count);
            disk.Put(schema, sums, VxPutOpts.None);

            int backup_generation = 0;
            VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation,
                base_filecounts);

            // Check that we read back the same stuff
            VxSchema schemafromdisk = disk.Get(null);
            VxSchemaChecksums sumsfromdisk = disk.GetChecksums();

            WVPASS(1);

            TestSchemaEquality(schema, schemafromdisk);
            TestChecksumEquality(sums, sumsfromdisk);

            WVPASS(2);

            // Doing it twice doesn't change anything.
            disk.Put(schema, sums, VxPutOpts.None);

            VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, 
                base_filecounts);

            WVPASS(3);

            // Check backup mode
            disk.Put(schema, sums, VxPutOpts.IsBackup);
            backup_generation++;

            VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, 
                base_filecounts);

            WVPASS(4);

            // Check backup mode again
            disk.Put(schema, sums, VxPutOpts.IsBackup);
            backup_generation++;

            VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, 
                base_filecounts);

            WVPASS(5);
        }
        finally
        {
            tmpdirinfo.Delete(true);
            sc.Cleanup();
        }
	WVASSERT(!tmpdirinfo.Exists);
    }
Beispiel #11
0
    public void TestDropSchemaFromDisk()
    {
        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema backend = new VxDiskSchema(tmpdir);

            VxSchema schema = new VxSchema();
            schema.Add("Table", "Foo", "column: name=foo,type=int\n", false);
            schema.Add("Table", "Bar", "column: name=bar,type=int\n", false);
            schema.Add("Procedure", "Func1", "Func1 contents", false);
            schema.Add("ScalarFunction", "Func2", "Func2 contents", false);

            VxSchemaChecksums sums = new VxSchemaChecksums();
            sums.AddSum("Table/Foo", 1);
            sums.AddSum("Table/Bar", 2);
            sums.AddSum("Procedure/Func1", 3);
            sums.AddSum("ScalarFunction/Func2", 5);

            backend.Put(schema, sums, VxPutOpts.None);

            WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Foo")));
            WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar")));
            WVPASS(File.Exists(Path.Combine(tmpdir, "Procedure/Func1")));
            WVPASS(File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2")));

            VxSchema newschema = backend.Get(null);
            VxSchemaChecksums newsums = backend.GetChecksums();

            WVPASSEQ(newschema.Count, schema.Count);
            WVPASSEQ(newsums.Count, sums.Count);
            WVPASS(newschema.ContainsKey("Table/Foo"));
            WVPASS(newschema.ContainsKey("Table/Bar"));
            WVPASS(newschema.ContainsKey("Procedure/Func1"));
            WVPASS(newschema.ContainsKey("ScalarFunction/Func2"));

            string[] todrop = { "Table/Foo" };
            backend.DropSchema(todrop);

            WVPASS(!File.Exists(Path.Combine(tmpdir, "Table/Foo")))
            WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar")))
            WVPASS(File.Exists(Path.Combine(tmpdir, "Procedure/Func1")))
            WVPASS(File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2")))

            newschema = backend.Get(null);
            newsums = backend.GetChecksums();
            WVPASSEQ(newschema.Count, 3);
            WVPASSEQ(newsums.Count, 3);
            WVPASS(!newschema.ContainsKey("Table/Foo"));
            WVPASS(newschema.ContainsKey("Table/Bar"));
            WVPASS(newschema.ContainsKey("Procedure/Func1"));
            WVPASS(newschema.ContainsKey("ScalarFunction/Func2"));

            todrop = new string[] { "Procedure/Func1", "ScalarFunction/Func2" };
            backend.DropSchema(todrop);

            WVPASS(!File.Exists(Path.Combine(tmpdir, "Table/Foo")))
            WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar")))
            WVPASS(!File.Exists(Path.Combine(tmpdir, "Procedure/Func1")))
            WVPASS(!File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2")))

            newschema = backend.Get(null);
            newsums = backend.GetChecksums();
            WVPASSEQ(newschema.Count, 1);
            WVPASSEQ(newsums.Count, 1);
            WVPASS(!newschema.ContainsKey("Table/Foo"));
            WVPASS(newschema.ContainsKey("Table/Bar"));
            WVPASS(!newschema.ContainsKey("Procedure/Func1"));
            WVPASS(!newschema.ContainsKey("ScalarFunction/Func2"));
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
    }
Beispiel #12
0
    public void TestExportEmptySchema()
    {
        string tmpdir = GetTempDir();

        try 
        {
            Directory.CreateDirectory(tmpdir);

            VxSchema schema = new VxSchema();
            VxSchemaChecksums sums = new VxSchemaChecksums();

            // Check that exporting an empty schema doesn't touch anything.
            VxDiskSchema backend = new VxDiskSchema(tmpdir);
            backend.Put(schema, sums, VxPutOpts.None);
            WVPASSEQ(Directory.GetDirectories(tmpdir).Length, 0);
            WVPASSEQ(Directory.GetFiles(tmpdir).Length, 0);
        }
        finally
        {
            Directory.Delete(tmpdir);
        }
	WVASSERT(!Directory.Exists(tmpdir));
    }
Beispiel #13
0
    public void TestDiskPutData()
    {
        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema backend = new VxDiskSchema(tmpdir);

            string filename = "10100-TestTable.sql";
            string datadir = Path.Combine(tmpdir, "DATA");
            string fullpath = Path.Combine(datadir, filename);
            string contents = "Random\nContents\n";

            backend.PutSchemaData("TestTable", contents, 10100);
            WVPASS(Directory.Exists(datadir));
            WVPASS(File.Exists(fullpath));
            WVPASSEQ(File.ReadAllText(fullpath), contents);

            WVPASSEQ(backend.GetSchemaData("TestTable", 10100, "", null, null),
		     contents);
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
    }
Beispiel #14
0
    public void TestApplySchemaDiff()
    {
        log.print("Testing applying diffs through DBus");
        TestApplySchemaDiff(dbus);

        log.print("Testing applying diffs to the disk");

        string tmpdir = GetTempDir();
        try
        {
            Directory.CreateDirectory(tmpdir);
            VxDiskSchema disk = new VxDiskSchema(tmpdir);

            TestApplySchemaDiff(disk);
        }
        finally
        {
            Directory.Delete(tmpdir, true);
        }
	WVPASS(!Directory.Exists(tmpdir));
    }