FOSSology  4.4.0
Open Source License Compliance by Open Source Software
sqlstatements.h
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2012 Hewlett-Packard Development Company, L.P.
3  SPDX-FileCopyrightText: © 2015, 2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
16 #ifndef SQLSTATEMENTS_H
17 #define SQLSTATEMENTS_H
18 
23  " SELECT column_name FROM information_schema.columns "
24  " WHERE table_catalog = '%s' "
25  " AND table_schema = 'public' "
26  " AND table_name = ";
27 
31 const char* url_checkout =
32  " SELECT conf_value FROM sysconfig "
33  " WHERE variablename = 'FOSSologyURL';";
34 
38 const char* select_upload_fk =
39  " SELECT job_upload_fk FROM job, jobqueue "
40  " WHERE jq_job_fk = job_pk "
41  " AND jq_pk = %d;";
42 
46 const char* upload_common =
47  " SELECT * FROM jobqueue "
48  " LEFT JOIN job ON jq_job_fk = job_pk"
49  " WHERE job.job_upload_fk = %d;";
50 
54 const char* folder_name =
55  " SELECT folder_name, folder_pk FROM folder "
56  " LEFT JOIN foldercontents ON folder_pk = foldercontents.parent_fk "
57  " LEFT JOIN job ON child_id = job_upload_fk "
58  " LEFT JOIN jobqueue ON jq_job_fk = job_pk "
59  " WHERE jq_pk = %d;";
60 
65 const char* parent_folder_name =
66  " SELECT folder_name, folder_pk FROM folder "
67  " INNER JOIN foldercontents ON folder_pk=foldercontents.parent_fk "
68  " WHERE child_id = %d AND foldercontents_mode = 1;";
69 
73 const char* upload_name =
74  " SELECT upload_filename FROM upload "
75  " LEFT JOIN job ON upload_pk = job_upload_fk "
76  " LEFT JOIN jobqueue ON jq_job_fk = job_pk "
77  " WHERE jq_pk = %d;";
78 
82 const char* upload_pk =
83  " SELECT upload_fk, uploadtree_pk FROM uploadtree "
84  " LEFT JOIN job ON upload_fk = job_upload_fk "
85  " LEFT JOIN jobqueue ON jq_job_fk = job_pk "
86  " WHERE parent IS NULL"
87  " AND jq_pk = %d;";
88 
92 const char* jobsql_email =
93  " SELECT user_name, user_email, email_notify FROM users, upload "
94  " WHERE user_pk = user_fk "
95  " AND upload_pk = %d;";
96 
100 const char* jobsql_email_job =
101  " SELECT user_name, user_email, email_notify FROM users, job, jobqueue "
102  " WHERE user_pk = job_user_fk AND job_pk = jq_job_fk "
103  " AND jq_pk = %d;";
104 
105 /* job queue related sql */
109 const char* basic_checkout =
110  " SELECT jobqueue.* FROM jobqueue INNER JOIN job ON job_pk = jq_job_fk "
111  " WHERE jq_starttime IS NULL AND jq_end_bits < 2 "
112  " AND NOT EXISTS(SELECT * FROM jobdepends, jobqueue jdep "
113  " WHERE jdep_jq_fk=jobqueue.jq_pk "
114  " AND jdep_jq_depends_fk=jdep.jq_pk"
115  " AND NOT(jdep.jq_endtime IS NOT NULL AND jdep.jq_end_bits < 2)) "
116  " ORDER BY job_priority DESC "
117  " LIMIT 10;";
118 
122 const char* jobsql_information =
123  " SELECT user_pk, job_priority, job_group_fk as group_pk FROM users "
124  " LEFT JOIN job ON job_user_fk = user_pk "
125  " WHERE job_pk = '%s';";
126 
130 const char* jobsql_started =
131  " UPDATE jobqueue "
132  " SET jq_starttime = now(), "
133  " jq_schedinfo ='%s.%d', "
134  " jq_endtext = 'Started' "
135  " WHERE jq_pk = '%d';";
136 
140 const char* jobsql_complete =
141  " UPDATE jobqueue "
142  " SET jq_endtime = now(), "
143  " jq_end_bits = jq_end_bits | 1, "
144  " jq_schedinfo = null, "
145  " jq_endtext = 'Completed' "
146  " WHERE jq_pk = '%d';";
147 
151 const char* jobsql_restart =
152  " UPDATE jobqueue "
153  " SET jq_endtext = 'Restarted', "
154  " jq_starttime = ( CASE "
155  " WHEN jq_starttime = CAST('9999-12-31' AS timestamp with time zone) "
156  " THEN null "
157  " ELSE jq_starttime "
158  " END ) "
159  " WHERE jq_pk = '%d';";
160 
164 const char* jobsql_failed =
165  " UPDATE jobqueue "
166  " SET jq_endtime = now(), "
167  " jq_end_bits = jq_end_bits | 2, "
168  " jq_schedinfo = null, "
169  " jq_endtext = '%s' "
170  " WHERE jq_pk = '%d';";
171 
175 const char* jobsql_processed =
176  " Update jobqueue "
177  " SET jq_itemsprocessed = %d "
178  " WHERE jq_pk = '%d';";
179 
183 const char* jobsql_paused =
184  " UPDATE jobqueue "
185  " SET jq_endtext = 'Paused', "
186  " jq_starttime = ( CASE "
187  " WHEN jq_starttime IS NULL "
188  " THEN CAST('9999-12-31' AS timestamp with time zone) "
189  " ELSE jq_starttime "
190  " END ) "
191  " WHERE jq_pk = '%d';";
192 
196 const char* jobsql_log =
197  " UPDATE jobqueue "
198  " SET jq_log = '%s' "
199  " WHERE jq_pk = '%d';";
200 
204 const char* jobsql_priority =
205  " UPDATE job "
206  " SET job_priority = '%d' "
207  " WHERE job_pk IN ( "
208  " SELECT jq_job_fk FROM jobqueue "
209  " WHERE jq_pk = '%d');";
210 
214 const char* jobsql_anyrunnable =
215  " SELECT * FROM jobqueue "
216  " WHERE jq_starttime IS NULL AND jq_end_bits < 2 "
217  " AND NOT EXISTS(SELECT * FROM jobdepends, jobqueue jdep "
218  " WHERE jdep_jq_fk=jobqueue.jq_pk "
219  " AND jdep_jq_depends_fk=jdep.jq_pk"
220  " AND NOT(jdep.jq_endtime IS NOT NULL AND jdep.jq_end_bits < 2))"
221  " AND jq_job_fk = (SELECT jq_job_fk FROM jobqueue queue WHERE queue.jq_pk = %d)";
222 
226 const char* jobsql_jobendbits =
227  " SELECT jq_pk, jq_end_bits FROM jobqueue "
228  " WHERE jq_job_fk = ( "
229  " SELECT jq_job_fk FROM jobqueue "
230  " WHERE jq_pk = %d "
231  " );";
232 
236 const char* jobsql_resetqueue =
237  "UPDATE jobqueue "
238  " SET jq_starttime=null, "
239  " jq_endtext=null, "
240  " jq_schedinfo=null "
241  " WHERE jq_endtime is NULL;";
242 
246 const char* jobsql_jobinfo =
247  " SELECT * FROM jobqueue "
248  " WHERE jq_job_fk = ( "
249  " SELECT jq_job_fk FROM jobqueue "
250  " WHERE jq_pk = %d "
251  " );";
252 
256 const char* smtp_values =
257  " SELECT conf_value, variablename FROM sysconfig "
258  " WHERE variablename LIKE 'SMTP%';";
259 
260 #endif /* SQLSTATEMENTS_H */
261 
const char * upload_pk
Definition: sqlstatements.h:82
const char * jobsql_started
const char * check_scheduler_tables
Definition: sqlstatements.h:22
const char * jobsql_paused
const char * jobsql_failed
const char * upload_common
Definition: sqlstatements.h:46
const char * jobsql_information
const char * jobsql_jobinfo
const char * parent_folder_name
Definition: sqlstatements.h:65
const char * jobsql_processed
const char * jobsql_log
const char * jobsql_resetqueue
const char * basic_checkout
const char * upload_name
Definition: sqlstatements.h:73
const char * smtp_values
const char * url_checkout
Definition: sqlstatements.h:31
const char * jobsql_restart
const char * jobsql_anyrunnable
const char * jobsql_complete
const char * folder_name
Definition: sqlstatements.h:54
const char * jobsql_priority
const char * jobsql_email
Definition: sqlstatements.h:92
const char * jobsql_jobendbits
const char * jobsql_email_job
const char * select_upload_fk
Definition: sqlstatements.h:38