8 #include "../headers/Database.h"
24 if(!Execute(
"SELECT * FROM Info;"))
52 Execute(
"CREATE TABLE Batches( ID INT PRIMARY KEY, BatchName TEXT,BatchEggs INT, BatchType VARCHAR(50), BatchSDate VARCHAR(12),BatchC1Date VARCHAR(12), BatchTDate VARCHAR(12), BatchHDate VARCHAR(12),FertileEggs INT, ChicksHatched INT, BatchComments TEXT, BatchBreed TEXT,BatchGroup TEXT,Incubator VARCHAR(50),IsReminded INT, AdvEnabled INT); ");
55 Execute(
"INSERT INTO Batches VALUES(0, 'Sample Batch',6, 'Chicken', '"+SD.
ToSortable(
"/")+
"','"+CD.
ToSortable(
"/")+
"','"+LD.
ToSortable(
"/")+
"','"+HD.
ToSortable(
"/")+
"',5,4,'Sample Comment','White Rock','None','Default',0,0);");
58 Execute(
"CREATE TABLE Reminders( ID INT PRIMARY KEY,RemindName VARCHAR(50),RemindDate VARCHAR(12), RemindText TEXT,IsReminded INT );");
59 Execute(
"INSERT INTO Reminders VALUES(0,'Sample Reminder','"+SD.
ToSortable(
"/")+
"','This Is a Sample Comment',0);");
62 Execute(
"CREATE TABLE Schedules(ID INT PRIMARY KEY,SchName VARCHAR(50), SchDate varchar(12));");
63 Execute(
"INSERT INTO Schedules VALUES(0,'Sample Hatch Date','"+HD.
ToSortable(
"/")+
"');");
66 Execute(
"CREATE TABLE Types(ID INT PRIMARY KEY,TypeName VARCHAR(50), TypeDays INT);");
67 Execute(
"INSERT INTO Types VALUES(0,'Chicken',21);");
68 Execute(
"INSERT INTO Types VALUES(1,'Turkey',28);");
69 Execute(
"INSERT INTO Types VALUES(2,'Duck',28);");
70 Execute(
"INSERT INTO Types VALUES(3,'Dove',14);");
71 Execute(
"INSERT INTO Types VALUES(4,'Pheasant',24);");
72 Execute(
"INSERT INTO Types VALUES(5,'Bobwhite Quail',23);");
73 Execute(
"INSERT INTO Types VALUES(6,'Coturnix Quail',17);");
74 Execute(
"INSERT INTO Types VALUES(7,'Goose',28);");
75 Execute(
"INSERT INTO Types VALUES(8,'Swan',35);");
76 Execute(
"INSERT INTO Types VALUES(9,'Ostrich',42);");
77 Execute(
"INSERT INTO Types VALUES(10,'Guinea Fowl',28);");
80 Execute(
"CREATE TABLE Breeds(ID INT PRIMARY KEY,BreedName VARCHAR(50), BreedType VARCHAR(50), BreedDays INT);");
81 Execute(
"INSERT INTO Breeds VALUES(0,'White Rock','Chicken',21);");
82 Execute(
"INSERT INTO Breeds VALUES(1,'Rhode Island Red','Chicken',21);");
83 Execute(
"INSERT INTO Breeds VALUES(2,'New Hampshire','Chicken',21);");
84 Execute(
"INSERT INTO Breeds VALUES(3,'Black Australorp','Chicken',21);");
85 Execute(
"INSERT INTO Breeds VALUES(4,'Barred Rock','Chicken',21);");
86 Execute(
"INSERT INTO Breeds VALUES(5,'Delaware','Chicken',21);");
87 Execute(
"INSERT INTO Breeds VALUES(6,'Columbian Wyandotte','Chicken',21);");
88 Execute(
"INSERT INTO Breeds VALUES(7,'Buckeye','Chicken',21);");
89 Execute(
"INSERT INTO Breeds VALUES(8,'Dominique','Chicken',21);");
90 Execute(
"INSERT INTO Breeds VALUES(9,'Black Jersey Giant','Chicken',21);");
91 Execute(
"INSERT INTO Breeds VALUES(10,'White Jersey Giant','Chicken',21);");
92 Execute(
"INSERT INTO Breeds VALUES(11,'Buff Orpington','Chicken',21);");
93 Execute(
"INSERT INTO Breeds VALUES(12,'Royal Palm','Turkey',28);");
94 Execute(
"INSERT INTO Breeds VALUES(13,'Standard Bronze','Turkey',28);");
95 Execute(
"INSERT INTO Breeds VALUES(14,'Blue Slate','Turkey',28);");
96 Execute(
"INSERT INTO Breeds VALUES(15,'Bourbon Red','Turkey',28);");
97 Execute(
"INSERT INTO Breeds VALUES(16,'Narragansett','Turkey',28);");
98 Execute(
"INSERT INTO Breeds VALUES(17,'Black Spanish','Turkey',28);");
99 Execute(
"INSERT INTO Breeds VALUES(18,'White African','Guinea Fowl',28);");
100 Execute(
"INSERT INTO Breeds VALUES(19,'Royal Purple','Guinea Fowl',28);");
101 Execute(
"INSERT INTO Breeds VALUES(20,'Lavendar','Guinea Fowl',28);");
102 Execute(
"INSERT INTO Breeds VALUES(21,'Pearl Grey','Guinea Fowl',28);");
103 Execute(
"INSERT INTO Breeds VALUES(22,'White Pekin','Duck',28);");
104 Execute(
"INSERT INTO Breeds VALUES(23,'Ruen Ducks','Duck',28);");
105 Execute(
"INSERT INTO Breeds VALUES(24,'White Chinese','Goose',28);");
106 Execute(
"INSERT INTO Breeds VALUES(25,'African Goose','Goose',28);");
109 Execute(
"CREATE TABLE Groups( ID INT PRIMARY KEY,GroupName VARCHAR(50),GroupComments TEXT);");
110 Execute(
"INSERT INTO Groups VALUES(0,'None','This Is The Default Group');");
113 Execute(
"CREATE TABLE Notifications( ID INT PRIMARY KEY,NotifyName VARCHAR(50),NotifyDate VARCHAR(12), NotifyDescription TEXT, IsNotified INT);");
116 Execute(
"CREATE TABLE Advanced( ID INT PRIMARY KEY, NumOfEggs INT,Unit INT, Days INT, Tag1 TEXT, Tag2 TEXT, Tag3 TEXT,Fertile TEXT,Pipped TEXT, Result TEXT, ResultDate TEXT,EggComments TEXT, DayWeight TEXT, DayComment TEXT);");
119 Execute(
"CREATE TABLE Settings( ID INT PRIMARY KEY, Key TEXT, Value TEXT);");
120 Execute(
"INSERT INTO Settings VALUES(0,'TillCandle','12');");
121 Execute(
"INSERT INTO Settings VALUES(1,'BeforeHatch','3');");
122 Execute(
"INSERT INTO Settings VALUES(2,'ShowSplash','0');");
123 Execute(
"INSERT INTO Settings VALUES(3,'UseGenNotify','0');");
124 Execute(
"INSERT INTO Settings VALUES(4,'OpenOnClick','0');");
125 Execute(
"INSERT INTO Settings VALUES(5,'OpenOnDismiss','1');");
126 Execute(
"INSERT INTO Settings VALUES(6,'BatchSortState','0');");
127 Execute(
"INSERT INTO Settings VALUES(7,'HideHatched','0');");
128 Execute(
"INSERT INTO Settings VALUES(8,'Tag1','Size,Small,Medium,Large');");
129 Execute(
"INSERT INTO Settings VALUES(9,'Tag2','Shape,Pointed,Round');");
130 Execute(
"INSERT INTO Settings VALUES(10,'Tag3','Color,Brown,Light Brown,Dark Brown,White,Green,Blue,Light,Dark');");
131 Execute(
"INSERT INTO Settings VALUES(11,'ColorRed','181,255,0,255,0,217,0,217,0,255,0');");
132 Execute(
"INSERT INTO Settings VALUES(12,'ColorGreen','170,255,0,255,0,208,0,208,0,255,0');");
133 Execute(
"INSERT INTO Settings VALUES(13,'ColorBlue','150,255,0,255,0,192,0,192,0,255,0');");
134 Execute(
"INSERT INTO Settings VALUES(14,'Incubators','Default');");
135 Execute(
"INSERT INTO Settings VALUES(15,'WeightUnit','0');");
136 Execute(
"INSERT INTO Settings VALUES(16,'CalTextSize','18');");
137 Execute(
"INSERT INTO Settings VALUES(17,'LanguageXML','');");
138 Execute(
"INSERT INTO Settings VALUES(18,'ShowDaysLeft','0');");
139 Execute(
"INSERT INTO Settings VALUES(19,'DateMode','0');");
144 Execute(
"CREATE TABLE Info( ID INT PRIMARY KEY, Key TEXT, Value TEXT);");
145 Execute(
"INSERT INTO Info VALUES(0,'Version','"+
Info.
GetVersion() +
"');");
146 Execute(
"INSERT INTO Info VALUES(1,'Platform','Desktop');");
170 return sqlite3_open(HK_DBPath.c_str(), &HK_DB);
180 SQL =
"SELECT * from Batches;";
184 SQL =
"SELECT * from Batches ORDER BY BatchHDate DESC;";
188 SQL =
"SELECT * from Batches ORDER BY BatchSDate DESC;";
192 SQL =
"SELECT * from Batches ORDER BY BatchType;";
196 SQL =
"SELECT * from Batches ORDER BY BatchBreed;";
200 SQL =
"SELECT * from Batches;";
209 for(
unsigned int A = 0; A < TableData.size(); A++) {
226 Data.
GetInt(
"FertileEggs"),
227 Data.
GetInt(
"ChicksHatched"),
232 Data.
GetInt(
"IsReminded"),
238 if(!Execute(
"SELECT * from Advanced;"))
242 vector<string> Tag1,Tag2,Tag3;
243 vector<string> Fertile,Pipped;
244 vector<string> Result,ResultDate;
245 vector<string> Comments;
246 vector<string> DayWeight, DayComment,Buffer;
253 for(
unsigned int B = 0; B < TableData.size(); B++) {
260 Tag1 = SplitStrings(Data.
GetValue(
"Tag1"),
"&");
261 Tag2 = SplitStrings(Data.
GetValue(
"Tag2"),
"&");
262 Tag3 = SplitStrings(Data.
GetValue(
"Tag3"),
"&");
263 Fertile = SplitStrings(Data.
GetValue(
"Fertile"),
"/");
264 Pipped = SplitStrings(Data.
GetValue(
"Pipped"),
"/");
265 Result = SplitStrings(Data.
GetValue(
"Result"),
"/");
266 ResultDate = SplitStrings(Data.
GetValue(
"ResultDate"),
"&");
267 Comments = SplitStrings(Data.
GetValue(
"EggComments"),
"&");
268 DayWeight = SplitStrings(Data.
GetValue(
"DayWeight"),
"&");
269 DayComment = SplitStrings(Data.
GetValue(
"DayComment"),
"&");
271 for(
unsigned int A = 0; A < Tag1.size();A++) {
280 Buffer = SplitStrings(ResultDate[A],
"/");
281 Date.
SetDate(stoi(Buffer[2]),stoi(Buffer[1]),stoi(Buffer[0]));
288 Buffer = SplitStrings(DayWeight[A],
"/");
292 for(C = 0; C < Buffer.size(); C++) {
293 Weight.
Set(Buffer[C]);
297 Buffer = SplitStrings(DayComment[A],
"|");
298 for(C = 0; C < Buffer.size(); C++)
304 cout<<
"Log: No Matching Batch For Advanced Entry!"<<endl;
317 if(!Execute(
"SELECT * from Breeds ORDER BY BreedType;"))
320 for(
unsigned int A = 0; A < TableData.size(); A++) {
338 if(!Execute(
"SELECT * from Groups;"))
341 for(
unsigned int A = 0; A < TableData.size(); A++) {
358 if(!Execute(
"SELECT * from Notifications ORDER BY NotifyDate DESC;"))
361 for(
unsigned int A = 0; A < TableData.size(); A++) {
381 if(!Execute(
"SELECT * from Reminders ORDER BY RemindDate DESC;"))
384 for(
unsigned int A = 0; A < TableData.size(); A++) {
404 if(!Execute(
"SELECT * from Schedules ORDER BY SchDate DESC;"))
407 for(
unsigned int A = 0; A < TableData.size(); A++) {
425 if(!Execute(
"SELECT * from Types ORDER BY ID;"))
428 for(
unsigned int A = 0; A < TableData.size(); A++) {
445 if(!Execute(
"SELECT * from Settings ORDER BY ID;"))
448 for(
unsigned int A = 0; A < TableData.size(); A++) {
473 fprintf(stderr,
"Can't open database: %s\n", sqlite3_errmsg(HK_DB));
477 sqlite3_stmt *Stmt = NULL;
478 int Result = sqlite3_prepare_v2(HK_DB,SQL.c_str(),-1,&Stmt,NULL);
480 if(Result != SQLITE_OK)
483 int Rows = 0, Columns = 0, Selected = 0, Type;
489 Result = sqlite3_step(Stmt);
490 while (Result != SQLITE_DONE && Result != SQLITE_OK) {
492 Columns = sqlite3_column_count(Stmt);
494 for (Selected = 0; Selected < Columns; Selected++) {
495 Type = sqlite3_column_type(Stmt, Selected);
496 const char * ColumnName = sqlite3_column_name(Stmt, Selected);
498 if (Type == SQLITE_INTEGER) {
501 to_string(sqlite3_column_int(Stmt, Selected))
504 else if (Type == SQLITE_FLOAT) {
507 to_string(sqlite3_column_double(Stmt, Selected))
510 else if (Type == SQLITE_TEXT) {
513 (
const char *) (sqlite3_column_text(Stmt, Selected))
517 printf(
"Not Matching Int Float Or Text");
520 TableData.push_back(RowData);
522 Result = sqlite3_step(Stmt);
525 Result = sqlite3_finalize(Stmt);
526 if(Result != SQLITE_OK)
541 for(
unsigned int A = 0; A < SQL.size(); A++) {
552 vector<string> OutArray;
555 for(
unsigned int a = 0; a < In.length(); a++) {
556 if(In[a] == Split[0]) {
557 OutArray.push_back(Hold);
561 Hold.push_back(In[a]);
563 OutArray.push_back(Hold);
A Class For Managing Multiple HK_Egg Instances.
void AddEgg(HK_Egg Egg)
Adds An HK_Egg To HK_AdvEggs Vector.
void SetID(int ID)
Sets ID.
void Clear()
Clears All Data From This Object.
void SetUnit(int Unit)
Sets Weight Unit Used.
void SetDays(int Days)
Sets Incubation Days.
A Class For Managing Mulitple HK_Batch Objects.
void Add(HK_Batch Batch)
Adds Another HK_Batch.
bool AddAdvanced(HK_Advanced Adv)
Add Advanced Data To The Batch That Has A Matching ID.
HK_Notifications ReadNotify()
Scans Notifications Into A HK_Storage Object.
void SetPath(string Path)
Sets Path To DB.
HK_Database()
Default Constructor. You'll Need To Call SetPath()
HK_KeyValue ReadSettings()
Reads Settings Table Into HK_KeyValue Object.
bool CloseDB()
Close The Database.
vector< HK_KeyValue > GetData()
Returns Table Data.
bool Execute(string SQL)
Executes SQL Statments.
~HK_Database()
Destructor.
HK_Storage ReadSchedules()
Reads Schedules Table Into HK_Storage Object.
vector< string > SplitStrings(string In, string Split)
Splits In By Split And Returns A Vector With Data.
bool CreateBackup(string Path)
Copies HK_DBPath To Path.
HK_Storage ReadRemind()
Reads Reminders Table Into HK_Storage Object.
bool CheckInfo()
Checks Info Table In Database To See If It Matches HK_Info Data.
string GetErrors()
Returns sqlite3_errmsg(HK_DB))
HK_Storage ReadGroups()
Scans Groups Into A HK_Storage Object.
HK_Storage ReadTypes()
Reads Types Table Into HK_Storage Object.
bool CreateDB()
Populates Database With Defaults.
HK_Batches ReadBatches(int Sort)
Scans Batches Into HK_Batches Object.
HK_Storage ReadBreeds()
Scans Breeds Into A HK_Storage Object.
A Class For Managing Dates.
std::string ToSortable(std::string Separator)
Generate A Sortable String For Database.
bool AddDays(int Days)
Adds Days To This HK_Date.
bool SetDate(int Days, int Month, int Year)
Sets Day, Month, and Year.
A Class For Storing And Retieving Data For One Egg.
void SetDate(HK_Date Date)
Sets Result Date.
void SetComments(string Comments)
Sets Egg Comments.
void SetResult(int Result)
Sets Result Status.
void SetTag3(string Tag)
Sets The Third Tag.
void SetTag1(string Tag)
Sets The First Tag.
void SetFertile(int Fertile)
Sets Fertile Status.
void ClearDayData()
Clears And Shrinks The Day Data Arrays.
void AddDayWeight(HK_Weight Weight)
Adds Weight For Another Day.
void AddDayComments(string Comments)
Adds Comments For Another Day.
void SetPipped(int Pipped)
Sets Pip Status.
void SetTag2(string Tag)
Sets The Second Tag.
Simple Platform Independent File Management Functions.
bool CopyFile(string Original, string Target)
A Simple C Function To Copy File From Original To Target.
Version And Other Information For HatchKeeper.
std::string GetVersion()
Returns The Version Of HatchKeeper.
std::string GetPlatform()
Returns The Platform For HatchKeeper.
A Key and Value Type Storage.
void Clear()
Clears All Internal Data And Shrinks The Storage.
void Add(string Key, string Value)
Adds A Key And Value;.
int GetInt(int Selection)
Returns The Selected Setting Value As An Integer.
string GetValue(int Selection)
Returns The Selected Setting Value As A String.
Class For Managing Notifications In Database.
A Class For Storing Values.
void Add(string Name, int ID, HK_Date Date, string Text, int Number)
Adds An Item To Storage.
A Class For Managing Data For One Weight.
void Set(float Weight)
Sets The Weight Value Using A Float.