Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Cave-Crawler/Database.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
76 lines (68 sloc)
2.59 KB
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
#include "iostream" | |
#include "sqlite.h" | |
static int callback(void *NotUsed, int argc, char **argv, char **azColName) { | |
int i; | |
for (i = 0; i < argc; i++) { | |
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); | |
} | |
printf("\n"); | |
return 0; | |
} | |
int DbConnectTest(int argc, char** argv) | |
{ | |
char *zErrMsg = 0; | |
int rc; | |
char *sql; | |
sqlite3* db; | |
int exit = 0; | |
exit = sqlite3_open("allDB.db", &db); | |
if (exit) | |
{ | |
std::cerr << "Error opening the Database" << sqlite3_errmsg(db) << std::endl; | |
return(-1); | |
} | |
else | |
std::cout << "Open Database Successfully!!!!" << std::endl; | |
/* Create SQL statement */ | |
sql = "INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION) " \ | |
"VALUES (1, 'Coconut','Heals Player for 20%'); " \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION) " \ | |
"VALUES (2, 'Banana', 'Heals Player for 30%'); " \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION)" \ | |
"VALUES (3, 'Mixed Soup', 'Heals Player for 90%' );" \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION)" \ | |
"VALUES (4, 'Wood Log', 'Used for crafting');"\ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION) " \ | |
"VALUES (5, 'Rock','Used for crafting'); " \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION) " \ | |
"VALUES (6, 'Sword', 'Made from Wood and Rocks, 15 damage'); " \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION)" \ | |
"VALUES (7, 'Bowl', 'Used for crafting soups' );" \ | |
"INSERT INTO ITEMS (ITEM_ID,ITEM_NAME,DESCRIPTION)" \ | |
"VALUES (8, 'Knife', 'Made with wood and rocks , 5 damage');"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(1,10,3,13,15,'pork' )"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(2,15,7,15,10,' gollem' )"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(3,25,10,16,25,'tiger' )"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(4,60,5,10,10,' panda' )"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(5,100,35,10,20,'dinossaur' )"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(6,15,6,16,20,'wild pork')"\ | |
"INSERT INTO ENEMY (ENEMY_ID,MAX_HP,ATTACK,ATTACK_SPEED,MOVE_SPEED,ENEMY_NAME)"\ | |
"VALUES(7,10,30,10,20,'skeleton)"\ | |
/* Execute SQL statement */ | |
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); | |
if (rc != SQLITE_OK) { | |
fprintf(stderr, "SQL error: %s\n", zErrMsg); | |
sqlite3_free(zErrMsg); | |
} | |
else { | |
fprintf(stdout, "Records created successfully\n"); | |
} | |
sqlite3_close(db); | |
return(0); | |
} | |