Skip to content

Commit

Permalink
Continue to add new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zertmark committed Sep 29, 2024
1 parent 070218d commit 0ea3ea0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ void startBot()
telebot_message_t message;
telebot_update_type_e update_types[] = {TELEBOT_UPDATE_TYPE_MESSAGE};
char message_reply[MESSAGE_REPLY_SIZE]= {0};
openDatabase("./databases/path.db");
if (!openDatabase("./databases/path.db"))
{
return;
}
while (1)
{
telebot_update_t *updates;
Expand Down
22 changes: 9 additions & 13 deletions src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,19 @@ int checkTable(const char* d_table, const char* HEADERS)
return 0;
}

if (bufferRowsCount!=0 && (strcmp(buffer[0], HEADERS)==0)
&& checkRows())
{
return 1;
}
return 0;
return (bufferRowsCount!=0 && (strcmp(buffer[0], HEADERS)==0)
&& checkRows());
}
int checkDatabase()
int isDatabaseGood()
{
return checkTable("STACK", TABLE_HEADERS_STRING_STACK) && \
checkTable("FINANCE", TABLE_HEADERS_STRING_FINANCE);
}
void createDatabase(char* path_to_database)
int createDatabase(char* path_to_database)
{

}
void openDatabase(char *path_to_database)
int openDatabase(char *path_to_database)
{
sqlite3_initialize();
if (access(path_to_database, F_OK || W_OK || R_OK) == -1)
Expand All @@ -266,12 +262,12 @@ void openDatabase(char *path_to_database)
{
if (dataBase == NULL)
printf("[ERROR] Not enough memory\nExiting...\n");
return;
return 0;

printf("%s\n", sqlite3_errmsg(dataBase));
return;
return 0;
}

createDatabase(path_to_database);
return (isDatabaseGood()) || createDatabase(path_to_database);
}
static int countRowsResult(sqlite3_stmt *stmt)
{
Expand Down
2 changes: 1 addition & 1 deletion src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

int fieldsAreNotSQLCommands(char **fieldsList, int sizeList);
int fieldAndRowExist(char *dataBaseTableName, char *field, char *field_data);
void openDatabase(char *path_to_database);
int openDatabase(char *path_to_database);
void printBuffer(void);
int executeWriteCommand(char *command_string);
int executeReadCommand(char *command_string);
Expand Down

0 comments on commit 0ea3ea0

Please sign in to comment.