Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active November 12, 2015 18:21
Show Gist options
  • Save bzdgn/1295216c9dbd5beae0e7 to your computer and use it in GitHub Desktop.
Save bzdgn/1295216c9dbd5beae0e7 to your computer and use it in GitHub Desktop.
BoilerPlate Database Sample with Struct On C++
/* cl: cl /nologo /W4 bpdb.cpp */
/* gcc: g++ bpdb.cpp -Wall -Wextra -pedantic -std=c++11 -o bpdb */
#include <stdio.h>
#define OPEN 1
#define CLOSED 0
struct 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