7 #include "../agent/externs.h"
13 static PGresult *result = NULL;
15 static long pfile_pk = -1;
24 char *upload_filename =
"test_1.orig.tar.gz";
25 int upload_mode = 104;
26 char *upload_origin =
"test_1.orig.tar.gz";
32 LOG_FATAL(
"Unable to connect to database");
37 memset(
SQL,
'\0',MAXSQL);
38 snprintf(
SQL,MAXSQL,
"INSERT INTO upload (upload_filename,upload_mode,upload_origin) VALUES ('%s', %d, '%s');",
39 upload_filename, upload_mode, upload_origin);
43 printf(
"Insert upload information ERROR!\n");
49 memset(
SQL,
'\0',MAXSQL);
50 snprintf(
SQL,MAXSQL,
"SELECT upload_pk FROM upload WHERE upload_filename = '%s';",
55 tmp = PQgetvalue(result,0,0);
70 memset(
SQL,
'\0',MAXSQL);
71 snprintf(
SQL,MAXSQL,
"BEGIN;");
75 printf(
"Remove pfile database information ERROR!\n");
81 memset(
SQL,
'\0',MAXSQL);
82 snprintf(
SQL,MAXSQL,
"DELETE FROM uploadtree WHERE upload_fk = %ld;",
upload_pk);
86 printf(
"Remove pfile database information ERROR!\n");
92 memset(
SQL,
'\0',MAXSQL);
93 snprintf(
SQL,MAXSQL,
"DELETE FROM upload WHERE upload_pk = %ld;",
upload_pk);
97 printf(
"Remove pfile database information ERROR!\n");
103 memset(
SQL,
'\0',MAXSQL);
104 snprintf(
SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pfile_pk);
108 printf(
"Remove pfile database information ERROR!\n");
114 memset(
SQL,
'\0',MAXSQL);
115 snprintf(
SQL,MAXSQL,
"COMMIT;");
119 printf(
"Perpare pfile information ERROR!\n");
137 struct stat Stat = {0};
138 ParentInfo PI = {0, 1287725739, 1287725739, 0, 0};
139 ContainerInfo CITest = {
"../testdata/test_1.orig.tar.gz",
"./test-result/",
140 "test_1.orig.tar.gz",
"test_1.orig.tar.gz.dir", 1, 1, 0, 0, Stat, PI, 0, 0, 0, 0, 0, 0};
142 char *Fuid =
"383A1791BA72A77F80698A90F22C1B7B04C59BEF.720B5CECCC4700FC90D628FCB45490E3.1aa248f65785e15aa9da4fa3701741d85653584544ab4003ef45e232a761a2f1.1312";
144 CU_ASSERT_EQUAL(result, 1);
156 struct stat Stat = {0};
157 ParentInfo PI = {0, 1287725739, 1287725739, 0, 0};
158 ContainerInfo CITest = {
"../testdata/test_1.orig.tar.gz",
"./test-result/",
159 "test_1.orig.tar.gz",
"test_1.orig.tar.gz.dir", 1, 1, 0, 0, Stat, PI, 0, 0, 0, 0, 0, 0};
162 CU_ASSERT_EQUAL(result, 0);
char SQL[256]
SQL query to execute.
PGconn * pgConn
Database connection.
char * Upload_Pk
Upload pk in DB.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
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...
Structure for storing information about a particular file.
int DBInsertClean()
clean the database
CU_TestInfo DBInsertUploadTree_testcases[]
DB insertion test cases (uploadtree)
char * DBConfFile
DB conf file location.
CU_TestInfo DBInsertPfile_testcases[]
DB insertion test cases (pfile)
int DBInsertInit()
initialize
void testDBInsertUploadTree()
test DBInsertUploadTree function
void testDBInsertPfile()
test DBInsertPfile function
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.