Ejemplo n.º 1
0
        public static void ClearTables(NPoco.Database db)
        {
            db.Execute("DELETE FROM persons");
            db.Execute("UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='persons'");

            db.Execute("DELETE FROM marriages");
            db.Execute("UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='marriages'");

            db.Execute("DELETE FROM marriage_sons");
            db.Execute("UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='marriage_sons'");
        }
Ejemplo n.º 2
0
 public GPXGenerator(
     NPoco.Database db,
     List<string> gcList, 
     Version gpxVersion,
     double minLat, double maxLat, double minLon, double maxLon
     )
 {
     _db = db;
     _gcList = gcList;
     _gpxVersion = gpxVersion;
     _minLat = minLat;
     _maxLat = maxLat;
     _minLon = minLon;
     _maxLon = maxLon;
     _index = 0;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="db"></param>
        public void LoadSensors(NPoco.Database db)
        {
            using (new HourGlass(this))
            {
                List<Sensor> data = db.Fetch<Sensor>(_sql.GetQuery(Sql.Query.SQL_SENSORS));

                _sensors = new List<NameValue>();
                foreach (var result in data)
                {
                    NameValue nameValue = new NameValue();
                    nameValue.Name = result.HostName;
                    nameValue.Value = result.Sid.ToString();
                    _sensors.Add(nameValue);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="db"></param>
        public void LoadClassifications(NPoco.Database db)
        {
            using (new HourGlass(this))
            {
                List<SigClass> data = db.Fetch<SigClass>(_sql.GetQuery(Sql.Query.SQL_SIG_CLASS));

                _classifications = new List<NameValue>();
                foreach (var result in data)
                {
                    NameValue nameValue = new NameValue();
                    nameValue.Name = result.Name;
                    nameValue.Value = result.Id.ToString();
                    _classifications.Add(nameValue);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="db"></param>
        public void LoadAcknowledgementClasses(NPoco.Database db)
        {
            using (new HourGlass(this))
            {
                List<AcknowledgmentClass> data = db.Fetch<AcknowledgmentClass>(_sql.GetQuery(Sql.Query.SQL_ACKNOWLEDGEMENT_CLASSES));

                _acknowledgementClasses = new List<NameValue>();
                foreach (var result in data)
                {
                    NameValue nameValue = new NameValue();
                    nameValue.Name = result.Desc;
                    nameValue.Value = result.Id.ToString();
                    _acknowledgementClasses.Add(nameValue);
                }
            }
        }
Ejemplo n.º 6
0
		public static void RecreateData(NPoco.Database db)
		{
			InMemoryCompositeKeyObjects = new List<CompositeKeyObject>();
			InMemoryIdentityObjects = new List<IdentityObject>();
			InMemoryKeyedGuidObjects = new List<KeyedGuidObject>();
			InMemoryKeyedIntObjects = new List<KeyedIntObject>();
			InMemoryListObjects = new List<ListObject>();
			InMemoryNoKeyNonDistinctObjects = new List<NoKeyNonDistinctObject>();
			InMemoryObjectsWithCustomType = new List<ObjectsWithCustomType>();

			// Clear out any old items
			db.Execute("TRUNCATE TABLE CompositeKeyObjects;");
			db.Execute("TRUNCATE TABLE IdentityObjects;");
			db.Execute("TRUNCATE TABLE KeyedGuidObjects;");
			db.Execute("TRUNCATE TABLE KeyedIntObjects;");
			db.Execute("TRUNCATE TABLE ListObjects;");
			db.Execute("TRUNCATE TABLE NoKeyNonDistinctObjects;");
			db.Execute("DBCC CHECKIDENT ('IdentityObjects', RESEED, 0) WITH NO_INFOMSGS;");

			int pos;
			for (var i = 0; i < 15; i += 1 )
			{
				pos = i + 1;

				var cko = new CompositeKeyObject
				{
					Key1ID = (pos / 5) + 1,
					Key2ID = (pos / 3) + 1,
					Key3ID = (pos % 5),
					TextData = "Text" + pos,
					DateEntered = new DateTime(1970, 1, 1).AddYears(pos),
					DateUpdated = DateTime.Now
				};
				db.Insert(cko);
				InMemoryCompositeKeyObjects.Add(cko);

				var io = new IdentityObject
				{
						Name = "Name " + pos,
						Age = (pos % 2 == 0) ? (int?)pos * 3 : null,
						DateOfBirth = new DateTime(1970, 1, 1).AddYears(pos),
						Savings = (pos*100000) / 13,
						DependentCount = (pos % 2 == 1) ? (byte?)pos : null,
						Gender = (pos % 2 == 0) ? "M" : "F",
						IsActive = (pos % 2 == 1)
				};
				db.Insert(io);
				InMemoryIdentityObjects.Add(io);

				var kgo = new KeyedGuidObject
				{
					Id = System.Guid.NewGuid(),
					Name = "Name " + pos,
					Age = (pos % 2 == 0) ? (int?)pos * 3 : null,
					DateOfBirth = new DateTime(1970, 1, 1).AddYears(pos),
					Savings = (pos * 100000) / 13,
					DependentCount = (pos % 2 == 1) ? (byte?)pos : null,
					Gender = (pos % 2 == 0) ? "M" : "F",
					IsActive = (pos % 2 == 1)
				};
				db.Insert(kgo);
				InMemoryKeyedGuidObjects.Add(kgo);

				var kio = new KeyedIntObject
				{
					Id = pos,
					Name = "Name " + pos,
					Age = (pos % 2 == 0) ? (int?)pos * 3 : null,
					DateOfBirth = new DateTime(1970, 1, 1).AddYears(pos),
					Savings = (pos * 100000) / 13,
					DependentCount = (pos % 2 == 1) ? (byte?)pos : null,
					Gender = (pos % 2 == 0) ? "M" : "F",
					IsActive = (pos % 2 == 1)
				};
				db.Insert(kio);
				InMemoryKeyedIntObjects.Add(kio);

				var nkndo = new NoKeyNonDistinctObject
				{
					FullName = "Name " + pos % 2,
					ItemInt = pos % 2,
					OptionalInt = (pos % 2 == 0) ? (int?)42 : null,
					Color = (pos % 2 == 0) ? "Red" : "Blue"
				};
				db.Insert(nkndo);
				InMemoryNoKeyNonDistinctObjects.Add(nkndo);

				var owct = new ObjectsWithCustomType
				{
					Id = "StringId_" + pos.ToString(),
					Name = "Blah",
					MySpecialTypeField = new DateTime(1925 + pos, 2, 15)
				};
				db.Insert(owct);
				InMemoryObjectsWithCustomType.Add(owct);
			}


			InMemoryListObjects.Add(new ListObject { 
				Id = 1,
				ShortName = "LiveLetter",
				Description = "Live with Letter of Intent Only",
				StatusKey = "A",
				SortOrder =1
			});

			InMemoryListObjects.Add(new ListObject
			{
				Id = 2,
				ShortName = "TakesPatients",
				Description = "Will Accept Most Patients",
				StatusKey = "P",
				SortOrder = 10
			});

			InMemoryListObjects.Add(new ListObject
			{
				Id = 3,
				ShortName = "Active",
				Description = "Active",
				StatusKey = "I",
				SortOrder = 20
			});

			InMemoryListObjects.Add(new ListObject
			{
				Id = 4,
				ShortName = "Prospect",
				Description = "Prospect",
				StatusKey = "I",
				SortOrder = 30
			});

			InMemoryListObjects.Add(new ListObject
			{
				Id = 5,
				ShortName = "OnHold",
				Description = "Tracked but not expected to participate",
				StatusKey = "I",
				SortOrder = 90
			});

			foreach (var lo in InMemoryListObjects)
			{
				db.Insert(lo);
			}

		}
Ejemplo n.º 7
0
		public static string VerifyRecordCountMatchForPocoType(Type pocoType, NPoco.Database db)
		{
			if (db == null) return "No database. Run RecreateData";
			string tableName = pocoType.Name + (pocoType.Name.StartsWith("Objects") ? "" : "s");

			//InMemoryCompositeKeyObjects
			var imList = typeof(TestData).GetProperty("InMemory" + tableName).GetValue(null, null);

			int imCount = 0;
			if (imList is IEnumerable)
			{
				var enumerator = ((IEnumerable)imList).GetEnumerator();
				while (enumerator.MoveNext())
				{
					imCount += 1;
				}
			}

			int dbCount = db.ExecuteScalar<int>("SELECT COUNT(*) FROM " + tableName + ";");

			if (imCount != dbCount) return " For test of " + tableName + ": In Memory Count = " + imCount + "; but Db Count = " + dbCount;
			if (imCount == 0) return " For test of " + tableName + ": In Memory and Db have no items."; 
			return "";
		}