FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
utils.c
Go to the documentation of this file.
1 /*********************************************************************
2 This program is free software; you can redistribute it and/or
3 modify it under the terms of the GNU General Public License
4 version 2 as published by the Free Software Foundation.
5 
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU General Public License for more details.
10 
11 You should have received a copy of the GNU General Public License along
12 with this program; if not, write to the Free Software Foundation, Inc.,
13 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 *********************************************************************/
20 /* include functions to test */
21 #include <testRun.h>
22 
23 /* scheduler includes */
24 #include <database.h>
25 #include <scheduler.h>
26 
27 /* library includes */
28 
33 {
34  char sql[512];
35  int upload_pk, job_pk, jq_pk;
36  PGresult* db_result;
37 
38  sprintf(sql, "INSERT INTO upload (upload_desc,upload_filename,user_fk,upload_mode,upload_origin) "
39  "VALUES('testing upload data', 'testing file', '1', '100', 'testing file')");
40  database_exec(scheduler, sql);
41 
42  /* get upload_pk of just added upload */
43  sprintf(sql, "SELECT currval('upload_upload_pk_seq') as mykey FROM %s", "upload");
44  db_result = database_exec(scheduler, sql);
45  upload_pk = atoi(PQget(db_result, 0, "mykey"));
46  PQclear(db_result);
47 
48  /* Add the upload record to the folder */
49  sprintf(sql, "INSERT INTO foldercontents (parent_fk,foldercontents_mode,child_id) VALUES ('1',2,'%d')", upload_pk);
50  database_exec(scheduler, sql);
51 
52  job_pk = 1;
53  /* Add the job info */
54  sprintf(sql, "INSERT INTO job (job_pk,job_user_fk,job_queued,job_priority,job_name,job_upload_fk) "
55  "VALUES(%d,'1',now(),'0','testing file',%d)", job_pk,upload_pk);
56  database_exec(scheduler, sql);
57 
58  jq_pk = 1;
59  sprintf(sql, "INSERT INTO jobqueue "
60  "(jq_pk,jq_job_fk,jq_type,jq_args,jq_runonpfile,jq_starttime,jq_endtime,jq_end_bits,jq_host) "
61  "VALUES (%d,'%d', 'ununpack', '%d', NULL, NULL, NULL, 0, NULL)", jq_pk, job_pk, upload_pk);
62  database_exec(scheduler, sql);
63 
64  return jq_pk;
65 }
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:32
PGresult * database_exec(scheduler_t *scheduler, const char *sql)
Executes an sql statement for the scheduler.
Definition: database.c:814
const char * upload_pk
Definition: sqlstatements.h:93