public static Database GetOrCreateEmptyDatabase(Client client, string dbName) { Database db = null; try { db = client.GetDatabase(dbName); } catch (SDBPException e) { if (e.Status == Status.SDBP_BADSCHEMA) { db = client.CreateDatabase(dbName); return(db); } } if (db == null) { return(null); } foreach (Table table in db.GetTables()) { table.DeleteTable(); } return(db); }
public static bool DBCompare(Database DB1, Database DB2) { bool res = true; Table cmp_tbl; byte[] cmp_val; // DB1 -> DB2 // call the function vice versa too, to be sure in result List <Table> tables = DB1.GetTables(); foreach (Table tbl in tables) { if (null == (cmp_tbl = DB2.GetTable(tbl.Name))) { Console.WriteLine(tbl.Name + " table is not in database " + DB2.Name); res = false; } else { Console.WriteLine("Comparing table " + tbl.Name); // check for table data foreach (KeyValuePair <byte[], byte[]> kv in tbl.GetKeyValueIterator(new ByteRangeParams())) { cmp_val = cmp_tbl.Get(kv.Key); if (null == cmp_val) { Console.WriteLine("Key \"" + kv.Key.ToString() + "\" is not in table " + tbl.Name); res = false; continue; } if (!Utils.ByteArraysEqual(kv.Value, cmp_val)) { Console.WriteLine("Values for key \"" + kv.Key.ToString() + "\" doesn't match:"); Console.WriteLine(kv.Value.ToString()); Console.WriteLine(cmp_val.ToString()); res = false; continue; } } } } return(res); }