Post by gromiczek on Jan 5, 2022 19:00:54 GMT
I've created a database using the class method in SimpleSQL and am also inserting records via the class, however, the integers that should have default values (NumSegments and Alive) are showing up as 0 when I select and read them back out of the database. How can I fix this problem? Thanks for your help and for such a great tool.
Here is the class I'm using to create the db:
public class MotifData
{
[PrimaryKey, AutoIncrement]
public int MotifID { get; set; }
[NotNull]
public int ParentID1 { get; set; }
[NotNull]
public int ParentID2 { get; set; }
[MaxLength(100), NotNull]
public string VenueBorn { get; set; }
[Default(5)]
public int NumSegments { get; set; }
[NotNull]
public DateTime DateTimeBorn { get; set; }
public DateTime DateTimeDied { get; set; }
[Default(1)]
public int Alive { get; set; }
[MaxLength(100), NotNull]
public string CurrentVenue { get; set; }
}
Here is the class and method I'm using to create the data for new records:
public class MotifDataCreator : MonoBehaviour
{
//DateTime utcDate = DateTime.UtcNow;
string currentVenue = "MyComputer";
public MotifData CreateNewMotifData()
{
MotifData newMotif = new MotifData();
/*newMotif.MotifID is automatically incremented by the database.*/
newMotif.ParentID1 = 0;
newMotif.ParentID2 = 0;
newMotif.VenueBorn = currentVenue;
//newMotif.NumSegments defaults to 5
newMotif.DateTimeBorn = DateTime.UtcNow;
//newMotif.DateTimeDied is not set yet. It reads 1/1/0001 at 12am when "null"
//newMotif.Alive defaults to 1
newMotif.CurrentVenue = currentVenue;
return newMotif;
}
}
Here is the class I'm using to create the db:
public class MotifData
{
[PrimaryKey, AutoIncrement]
public int MotifID { get; set; }
[NotNull]
public int ParentID1 { get; set; }
[NotNull]
public int ParentID2 { get; set; }
[MaxLength(100), NotNull]
public string VenueBorn { get; set; }
[Default(5)]
public int NumSegments { get; set; }
[NotNull]
public DateTime DateTimeBorn { get; set; }
public DateTime DateTimeDied { get; set; }
[Default(1)]
public int Alive { get; set; }
[MaxLength(100), NotNull]
public string CurrentVenue { get; set; }
}
Here is the class and method I'm using to create the data for new records:
public class MotifDataCreator : MonoBehaviour
{
//DateTime utcDate = DateTime.UtcNow;
string currentVenue = "MyComputer";
public MotifData CreateNewMotifData()
{
MotifData newMotif = new MotifData();
/*newMotif.MotifID is automatically incremented by the database.*/
newMotif.ParentID1 = 0;
newMotif.ParentID2 = 0;
newMotif.VenueBorn = currentVenue;
//newMotif.NumSegments defaults to 5
newMotif.DateTimeBorn = DateTime.UtcNow;
//newMotif.DateTimeDied is not set yet. It reads 1/1/0001 at 12am when "null"
//newMotif.Alive defaults to 1
newMotif.CurrentVenue = currentVenue;
return newMotif;
}
}