Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active November 12, 2015 18:04
Show Gist options
  • Save bzdgn/122c6b5dc79327dc26c8 to your computer and use it in GitHub Desktop.
Save bzdgn/122c6b5dc79327dc26c8 to your computer and use it in GitHub Desktop.
BoilerPlate Database Sample On C
/* cl: cl /nologo /W4 bpdb.c */
/* gcc: gcc bpdb.c -Wall -Wextra -pedantic -std=c11 -o bpdb */
#include <stdio.h>
#define OPEN 1
#define CLOSED 0
typedef struct
{
int SomeState;
char *filename;
char *statement;
}
Connection;
void OpenConnection(Connection *db, char *filename)
{
db->SomeState = OPEN;
db->filename = filename;
}
void ExecuteConnection(Connection *db, char *statement)
{
db->statement = statement;
}
void CloseConnection(Connection *db)
{
db->SomeState = CLOSED;
}
int main()
{
Connection db;
OpenConnection(&db, "C:\\temp\\sample.db");
ExecuteConnection(&db, "create table People (Id int, Name text)");
CloseConnection(&db);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment