Created
November 12, 2015 18:22
-
-
Save bzdgn/0be75898299d727584e1 to your computer and use it in GitHub Desktop.
BoilerPlate Database Sample with Class On C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* cl: cl /nologo /W4 bpdb_class.cpp */ | |
/* gcc: g++ bpdb_class.cpp -Wall -Wextra -pedantic -std=c++11 -o bpdb_class */ | |
#include <stdio.h> | |
#define OPEN 1 | |
#define CLOSED 0 | |
class Connection | |
{ | |
private: | |
int SomeState; | |
char *Filename; | |
char *Statement; | |
public: | |
Connection() | |
{ | |
printf("...SomeState = %d\n", this->SomeState); | |
this->SomeState = 0; | |
printf("Connection::Constructor()\n"); | |
printf("...SomeState = %d\n", this->SomeState); | |
} | |
void Open(char *Filename) | |
{ | |
printf("Connection::Open()\n"); | |
this->SomeState = OPEN; | |
this->Filename = Filename; | |
printf("...SomeState = %d\n", this->SomeState); | |
} | |
void Execute(char *Statement) | |
{ | |
printf("Connection::Execute()\n"); | |
this->Statement = Statement; | |
printf("...Statement = %s\n", this->Statement); | |
} | |
void PrintStates() const | |
{ | |
printf("Connection::PrintStates()\n"); | |
printf("...FileName : %s\n", this->Filename); | |
printf("...Statement: %s\n", this->Statement); | |
} | |
void Close() | |
{ | |
this->SomeState = CLOSED; | |
} | |
~Connection() | |
{ | |
printf("Connection::Destructor()\n"); | |
Close(); | |
printf("...SomeState = %d\n", this->SomeState); | |
} | |
}; | |
void ExplicitPrint(Connection const &db) | |
{ | |
db.PrintStates(); | |
} | |
int main() | |
{ | |
Connection db; | |
db.Open("C:\\temp\\sample.db"); | |
db.Execute("create table People (Id int, Name text)"); | |
db.PrintStates(); | |
ExplicitPrint(db); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment