Merge ActivePostIDS#1 into Master #5
62
BlogDB.c
62
BlogDB.c
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <malloc.h>
|
||||
|
||||
static MYSQL* conn2maria();
|
||||
static int AddPost(char title[], int authorId, char datePosted[], char post[], int tags[], size_t tagSize, MYSQL* con);
|
||||
|
|
@ -709,9 +710,62 @@ bool IsEnabled(int postID, MYSQL* con)
|
|||
return !state;
|
||||
}
|
||||
|
||||
int* ActivePostIDs(int* arr, MYSQL* con)
|
||||
void *ActivePostIDs(MYSQL* con)
|
||||
{
|
||||
|
||||
|
||||
if (con == NULL)
|
||||
{
|
||||
con = conn2maria();
|
||||
}
|
||||
|
||||
// Query the server, if successful continue, else throw error
|
||||
if (mysql_query(con, "SELECT COUNT(*) FROM blog_posts WHERE state=(0)"))
|
||||
{
|
||||
fprintf(stderr, "%s\n", mysql_error(con));
|
||||
mysql_close(con);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Get results
|
||||
MYSQL_RES *result = mysql_store_result(con);
|
||||
int num_fields = mysql_num_fields(result);
|
||||
|
||||
MYSQL_ROW row;
|
||||
int postFound = 1;
|
||||
|
||||
row = mysql_fetch_row(result);
|
||||
|
||||
int count = atoi(row[0]);
|
||||
|
||||
printf("%d\n", count);
|
||||
|
||||
|
||||
// Query the server, if successful continue, else throw error
|
||||
if (mysql_query(con, "SELECT id FROM blog_posts WHERE state=(0)"))
|
||||
{
|
||||
fprintf(stderr, "%s\n", mysql_error(con));
|
||||
mysql_close(con);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
free(result);
|
||||
|
||||
MYSQL_RES *result2 = mysql_store_result(con);
|
||||
|
||||
int *arr = (int *)realloc(arr, sizeof(int) * count);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
row = mysql_fetch_row(result2);
|
||||
arr[i] = atoi(row[0]);
|
||||
}
|
||||
|
||||
//return sizeof(int) * count;
|
||||
//return count;
|
||||
|
||||
return arr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -772,6 +826,12 @@ int main(int argc, char *argv[])
|
|||
//TogglePost(51, con);
|
||||
//printf("%s\n", IsEnabled(51, con) ? "True" : "False");
|
||||
|
||||
int *num;
|
||||
|
||||
ActivePostIDs(con);
|
||||
|
||||
|
||||
|
||||
// =================================
|
||||
|
||||
exit(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue