public void Guid_Arg() { var db = new MightyOrm(TestConstants.ReadWriteTestConnection); var guid = Guid.NewGuid(); dynamic item; using (var command = db.CreateCommand("SELECT @0 AS val", null, guid)) { #if NETCOREAPP // For some reason .NET Core provider doesn't have DbType.Guid support even though .NET Framework provider does Assert.AreEqual(DbType.String, command.Parameters[0].DbType); #else Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType); #endif item = db.Single(command); } // The output from the provider is a bunch of bytes either way, so we stick with the provider // default here (especially since it is the same in both cases). #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETCOREAPP3_1 // This changed from `byte[]` to `string` somewhere between System.Data.SQLite 1.0.105 and 1.0.111 Assert.AreEqual(typeof(string), item.val.GetType()); #else Assert.AreEqual(typeof(byte[]), item.val.GetType()); #endif Assert.AreEqual(guid, new Guid(item.val)); }
public static TaskQueueItem getNextTaskQueueItem() { MightyOrm <TaskQueueItem> db = DatabaseConnector.createConnectionTaskQueueItem(); // TaskQueueItem tq = db.Single("SELECT * from TaskQueue"); TaskQueueItem tq = db.Single(""); return(tq); }
public void Guid_Arg() { // SQL Server has true Guid type support var db = new MightyOrm(TestConstants.ReadTestConnection); var guid = Guid.NewGuid(); dynamic item; using (var command = db.CreateCommand("SELECT @0 AS val", null, guid)) { Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType); item = db.Single(command); } Assert.AreEqual(guid, item.val); }
public void Guid_Arg() { // PostgreSQL has true Guid type support var db = new MightyOrm(string.Format(TestConstants.ReadWriteTestConnection, TestConstants.ProviderName)); var guid = Guid.NewGuid(); dynamic item; using (var command = db.CreateCommand("SELECT @0 AS val", null, guid)) { Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType); item = db.Single(command); } Assert.AreEqual(guid, item.val); }
public void Guid_Arg() { // MySQL has native Guid parameter support, but the SELECT output is a string var db = new MightyOrm(string.Format(TestConstants.ReadTestConnection, ProviderName)); var guid = Guid.NewGuid(); dynamic item; using (var command = db.CreateCommand("SELECT @0 AS val", null, guid)) { Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType); item = db.Single(command); } Assert.AreEqual(typeof(string), item.val.GetType()); Assert.AreEqual(guid, new Guid(item.val)); }
public void Update_SingleRow_MappedExpando() { // Apply some quick crazy-ass mapping... to an ExpandoObject :-) // Remember, we're mapping from crazy fake 'class' names to the sensible underlying column names var categories = new MightyOrm( string.Format(TestConstants.WriteTestConnection, ProviderName), "MassiveWriteTests.Categories", primaryKeys: "MYCATEGORYID", columns: "MYCATEGORYID, TheName, ItsADescription", mapper: new SqlNamingMapper(columnNameMapping: (t, c) => c // 'class' names should come first .Map("MYCATEGORYID", "CategoryID") .Map("TheName", "CategoryName") .Map("ItsADescription", "Description"))); // insert something to update first. var inserted = categories.Insert(new { TheName = "Cool stuff", ItsADescription = "You know... cool stuff! Cool. n. stuff." }); int insertedCategoryID = inserted.MYCATEGORYID; Assert.IsTrue(insertedCategoryID > 0); // update it, with a better description inserted.ItsADescription = "This is all jolly marvellous"; Assert.AreEqual(1, categories.Update(inserted), "Update should have affected 1 row"); var updatedRow = categories.Single(new { inserted.MYCATEGORYID }); Assert.IsNotNull(updatedRow); Assert.AreEqual(inserted.MYCATEGORYID, Convert.ToInt32(updatedRow.MYCATEGORYID)); // convert from uint Assert.AreEqual(inserted.ItsADescription, updatedRow.ItsADescription); // reset description to NULL updatedRow.ItsADescription = null; Assert.AreEqual(1, categories.Update(updatedRow), "Update should have affected 1 row"); var newUpdatedRow = categories.Single(new { updatedRow.MYCATEGORYID }); Assert.IsNotNull(newUpdatedRow); Assert.AreEqual(updatedRow.MYCATEGORYID, newUpdatedRow.MYCATEGORYID); Assert.AreEqual(updatedRow.ItsADescription, newUpdatedRow.ItsADescription); }
public static bool isTaskQueueEmpty() { MightyOrm <TaskQueueItem> db = DatabaseConnector.createConnectionTaskQueueItem(); // TaskQueueItem tq = db.Single("SELECT * from TaskQueue"); TaskQueueItem tq = db.Single(""); if (tq == null) { return(true); } else { return(false); } }