public static void Main(string[] args) { Lib.Init (); // Create midgard config connection Config cfg = new Config (); cfg.DatabaseType = "SQLite"; cfg.DatabaseName = "midgard_mono_sample"; Connection mgd = new Connection (); if (!mgd.OpenConfig (cfg)) { Console.WriteLine ("Connection failed!"); return; } /* Create base storage if it doesn't exist */ if (Midgard.Storage.CreateBaseStorage(mgd)) Console.WriteLine ("Base Midgard storage created"); /* Create midgard_person storage if it doesn't exist */ if (Midgard.Storage.Exists (mgd, "midgard_person")) { Console.WriteLine ("Storage for midgard_person class exists"); } else { if (Midgard.Storage.Create (mgd, "midgard_person")) Console.WriteLine ("Created new storage for midgard_person class"); else Console.WriteLine ("Failed to create storage for midgard_person class"); } }
public static void Main(string[] args) { Midgard.Lib.Init (); // Create midgard config connection Config cfg = new Config (); cfg.DatabaseType = "SQLite"; cfg.DatabaseName = "midgard"; Connection conn = new Connection (); if (!conn.OpenConfig (cfg)) { Console.WriteLine ("Connection failed!"); return; } Console.WriteLine ("Connection established!"); }
public static void Main(string[] args) { Midgard.Lib.Init (); // Create midgard config connection Config cfg = new Config (); cfg.DatabaseType = "SQLite"; cfg.DatabaseName = "midgard_mono_sample"; Connection mgd = new Connection (); if (!mgd.OpenConfig (cfg)) { Console.WriteLine ("Connection failed!"); return; } GLib.Value val = new GLib.Value(""); Midgard.Object john = new Midgard.Object (mgd, "midgard_person", val); GLib.Value name = new GLib.Value ("John"); john.SetSchemaProperty ("username", name); if (!john.Create()) { Console.WriteLine ("Couldn't create person object. %s", mgd.ErrorString); } else { GLib.Value gval = john.GetSchemaProperty ("guid"); Console.Write ("Created new person object." + (string)gval.Val.ToString() + "\n"); } val = new GLib.Value(""); Midgard.Object alice = new Midgard.Object (mgd, "midgard_person", val); name = new GLib.Value ("Alice"); alice.SetSchemaProperty ("username", name); if (!alice.Create()) { Console.WriteLine ("Couldn't create person object. %s", mgd.ErrorString); } else { GLib.Value gval = alice.GetSchemaProperty ("guid"); Console.Write ("Created new person object." + (string)gval.Val + "\n"); } Console.WriteLine (john); }
public static void Main(string[] args) { Midgard.Lib.Init (); // Create midgard config connection Config cfg = new Config (); cfg.DatabaseType = "SQLite"; cfg.DatabaseName = "midgard_mono_sample"; Connection mgd = new Connection (); if (!mgd.OpenConfig (cfg)) { Console.WriteLine ("Connection failed!"); return; } Midgard.QueryStorage storage = new Midgard.QueryStorage ("midgard_person"); Midgard.QuerySelect select = new Midgard.QuerySelect (mgd, storage); Midgard.QueryProperty prop = new Midgard.QueryProperty ("name", null); GLib.Value value = new GLib.Value ("John"); Midgard.QueryValue val = new Midgard.QueryValue (value); Midgard.QueryConstraint cnstr = new Midgard.QueryConstraint (prop, "=", val, storage); Midgard.QueryProperty prop2 = new Midgard.QueryProperty ("name", null); value = new GLib.Value ("Alice"); Midgard.QueryValue val2 = new Midgard.QueryValue (value); Midgard.QueryConstraint cnstr2 = new Midgard.QueryConstraint (prop2, "=", val, null); //Midgard.QueryGroupConstraint group_constraint = new Midgard.QueryGroupConstraint ("OR", cnstr, cnstr2); //select.SetConstraint (cnstr); select.Execute(); uint nobjects = 0; Midgard.DBObject[] objects = select.ListObjects(out nobjects); }