FOSSology  4.4.0
Open Source License Compliance by Open Source Software
utils.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © Fossology contributors
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
11 /* include functions to test */
12 #include <testRun.h>
13 
14 /* scheduler includes */
15 #include <database.h>
16 #include <scheduler.h>
17 
18 /* library includes */
19 
24 {
25  char sql[512];
26  int upload_pk, job_pk, jq_pk;
27  PGresult* db_result;
28 
29  sprintf(sql, "INSERT INTO upload (upload_desc,upload_filename,user_fk,upload_mode,upload_origin) "
30  "VALUES('testing upload data', 'testing file', '1', '100', 'testing file')");
31  database_exec(scheduler, sql);
32 
33  /* get upload_pk of just added upload */
34  sprintf(sql, "SELECT currval('upload_upload_pk_seq') as mykey FROM %s", "upload");
35  db_result = database_exec(scheduler, sql);
36  upload_pk = atoi(PQget(db_result, 0, "mykey"));
37  PQclear(db_result);
38 
39  /* Add the upload record to the folder */
40  sprintf(sql, "INSERT INTO foldercontents (parent_fk,foldercontents_mode,child_id) VALUES ('1',2,'%d')", upload_pk);
41  database_exec(scheduler, sql);
42 
43  job_pk = 1;
44  /* Add the job info */
45  sprintf(sql, "INSERT INTO job (job_pk,job_user_fk,job_queued,job_priority,job_name,job_upload_fk) "
46  "VALUES(%d,'1',now(),'0','testing file',%d)", job_pk,upload_pk);
47  database_exec(scheduler, sql);
48 
49  jq_pk = 1;
50  sprintf(sql, "INSERT INTO jobqueue "
51  "(jq_pk,jq_job_fk,jq_type,jq_args,jq_runonpfile,jq_starttime,jq_endtime,jq_end_bits,jq_host) "
52  "VALUES (%d,'%d', 'ununpack', '%d', NULL, NULL, NULL, 0, NULL)", jq_pk, job_pk, upload_pk);
53  database_exec(scheduler, sql);
54 
55  return jq_pk;
56 }
PGresult * database_exec(scheduler_t *scheduler, const char *sql)
Executes an sql statement for the scheduler.
Definition: database.c:803
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:23
const char * upload_pk
Definition: sqlstatements.h:82