19 #include <CUnit/CUnit.h> 40 LOG_FATAL(
"Unable to connect to database");
43 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
71 char SQL[MAXCMD] = {0};
72 PGresult *result = NULL;
73 char mimetype_name[] =
"application/octet-stream";
75 memset(SQL,
'\0', MAXCMD);
76 snprintf(SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = '%s';", mimetype_name);
77 result = PQexec(
pgConn, SQL);
85 memset(SQL,
'\0', MAXCMD);
86 snprintf(SQL, MAXCMD,
"INSERT INTO mimetype (mimetype_name) VALUES ('%s');", mimetype_name);
87 result = PQexec(
pgConn, SQL);
98 memset(SQL,
'\0', MAXCMD);
99 snprintf(SQL, MAXCMD,
"SELECT mimetype_name from mimetype where mimetype_name = ('%s');", mimetype_name);
100 result = PQexec(
pgConn, SQL);
106 int mimetype_id = atoi(PQgetvalue(result, 0, 0));
109 CU_ASSERT_NOT_EQUAL(ret, mimetype_id);
112 memset(SQL,
'\0', MAXCMD);
113 snprintf(SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = '%s';", mimetype_name);
114 result = PQexec(
pgConn, SQL);
126 memset(SQL,
'\0', MAXCMD);
127 snprintf(SQL, MAXCMD,
"SELECT mimetype_name from mimetype where mimetype_name = ('%s');", mimetype_name);
128 result = PQexec(
pgConn, SQL);
135 mimetype_id = atoi(PQgetvalue(result, 0, 0));
138 CU_ASSERT_NOT_EQUAL(ret, mimetype_id);
140 memset(SQL,
'\0', MAXCMD);
141 snprintf(SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = '%s';", mimetype_name);
142 result = PQexec(
pgConn, SQL);
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
PGresult * DBMime
contents of mimetype table
char * DBConfFile
DB conf file location.
PGconn * pgConn
Database connection.
void testDBFindMime()
for function DBFindMime()
int DBFindMime(char *Mimetype)
Find a mime type in the DBMime table.
int DBFindMimeClean()
clean the env
int DBFindMimeInit()
initialize
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
char SQL[256]
SQL query to execute.
magic_t MagicCookie
for Magic
CU_TestInfo testcases_DBFindMime[]
testcases for function DBFindMime
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.