Skip to content

Commit 873de36

Browse files
committed
if / if to if / else refactor
1 parent 7270997 commit 873de36

File tree

3 files changed

+87
-99
lines changed

3 files changed

+87
-99
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM store/oracle/database-instantclient:12.2.0.1
2-
ADD scripts/preparecontainer.sh /
3-
RUN bash /preparecontainer.sh
4-
ADD scripts/build.sh /
5-
RUN chmod +x /build.sh
6-
CMD /build.sh
1+
FROM store/oracle/database-instantclient:12.2.0.1
2+
ADD scripts/preparecontainer.sh /
3+
RUN bash /preparecontainer.sh
4+
ADD scripts/build.sh /
5+
RUN chmod +x /build.sh
6+
CMD /build.sh

create_function_toddog.sql

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@ show err
55

66
prompt create function f_metrictoddog
77
CREATE OR REPLACE FUNCTION f_metrictoddog (
8-
name IN VARCHAR2,
9-
metric IN BINARY_INTEGER,
10-
kind IN VARCHAR2,
11-
tag IN VARCHAR2)
8+
name IN VARCHAR2,
9+
metric IN BINARY_INTEGER,
10+
kind IN VARCHAR2,
11+
tag IN VARCHAR2)
1212
RETURN VARCHAR2 AS LANGUAGE C
1313
NAME "metrictoddog"
1414
LIBRARY libtoddog
1515
WITH CONTEXT
1616
PARAMETERS (
17-
CONTEXT,
18-
name STRING,
19-
name INDICATOR short,
20-
metric INT,
21-
metric INDICATOR short,
22-
kind STRING,
23-
kind INDICATOR short,
24-
tag STRING,
25-
tag INDICATOR short,
26-
RETURN INDICATOR short,
27-
RETURN LENGTH short,
28-
RETURN STRING);
17+
CONTEXT,
18+
name STRING,
19+
name INDICATOR short,
20+
metric INT,
21+
metric INDICATOR short,
22+
kind STRING,
23+
kind INDICATOR short,
24+
tag STRING,
25+
tag INDICATOR short,
26+
RETURN INDICATOR short,
27+
RETURN LENGTH short,
28+
RETURN STRING);
2929
/
3030
show err
3131

3232
CREATE OR REPLACE FUNCTION f_gaugetoddog(
33-
name IN VARCHAR2,
34-
metric IN number,
35-
tag IN VARCHAR2)
33+
name IN VARCHAR2,
34+
metric IN number,
35+
tag IN VARCHAR2)
3636
RETURN VARCHAR2 IS
3737
BEGIN
38-
return f_metrictoddog(name,metric,'g',tag);
38+
return f_metrictoddog(name,metric,'g',tag);
3939
END;
4040
/
4141
show err
4242

4343
CREATE OR REPLACE FUNCTION f_counttoddog(
44-
name IN VARCHAR2,
45-
metric IN number,
46-
tag IN VARCHAR2)
44+
name IN VARCHAR2,
45+
metric IN number,
46+
tag IN VARCHAR2)
4747
RETURN VARCHAR2 IS
4848
BEGIN
49-
return f_metrictoddog(name,metric,'c',tag);
49+
return f_metrictoddog(name,metric,'c',tag);
5050
END;
5151
/
5252
show err
@@ -98,5 +98,4 @@ END;
9898
/
9999
show err
100100

101-
102-
exit
101+
exit

src/toddog.c

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,71 @@
33

44
// to send a metric to ddog
55
char *metrictoddog(
6-
OCIExtProcContext *ctx,
7-
char *name, // pointer to name -- name of the metric
8-
short name_i, // null status of name
9-
int *metric, // pointer to metric -- number to be sent to the metric
10-
short metric_i, // null status of metric
11-
char *kind, // pointer to string1
12-
short kind_i, // null status of string1
13-
char *tag, // pointer to string1
14-
short tag_i, // null status of string1
15-
short *ret_i, // pointer to indicator null or not null
16-
short *ret_l // len of return
6+
OCIExtProcContext *ctx,
7+
char *name, // pointer to name -- name of the metric
8+
short name_i, // null status of name
9+
int *metric, // pointer to metric -- number to be sent to the metric
10+
short metric_i, // null status of metric
11+
char *kind, // pointer to string1
12+
short kind_i, // null status of string1
13+
char *tag, // pointer to string1
14+
short tag_i, // null status of string1
15+
short *ret_i, // pointer to indicator null or not null
16+
short *ret_l // len of return
1717
)
1818
{
19-
char *tmp;
20-
short len;
21-
char* metricname;
22-
char* themetric; // to store the metric we will send to datadog
23-
char* thekind; // to store the metric we will send to datadog
24-
25-
// Check for null inputs
26-
if (name_i == OCI_IND_NULL)
27-
{
28-
*ret_i = (short)OCI_IND_NULL;
29-
30-
// PL/SQL has no notion of a NULL ptr, so return a zero-byte string.
31-
tmp = OCIExtProcAllocCallMemory(ctx, 1);
32-
tmp[0] = '\0';
33-
34-
return(tmp);
35-
}
36-
37-
// the main part
38-
39-
strcat(metricname, name);
40-
41-
if (kind_i == OCI_IND_NOTNULL)
42-
{
43-
asprintf(&thekind,"%s",kind);
44-
}
45-
46-
if (kind_i == OCI_IND_NULL)
47-
{
48-
asprintf(&thekind,"%s","g");
49-
}
50-
51-
if (tag_i == OCI_IND_NULL)
52-
{
53-
asprintf(&themetric,"%s:%d|%s|",metricname, metric, thekind);
54-
}
19+
char *tmp;
20+
short len;
21+
char* metricname;
22+
char* themetric; // to store the metric we will send to datadog
23+
char* thekind; // to store the kind we will send to datadog
24+
25+
// Check for null inputs
26+
if (name_i == OCI_IND_NULL)
27+
{
28+
*ret_i = (short)OCI_IND_NULL;
29+
30+
// PL/SQL has no notion of a NULL ptr, so return a zero-byte string.
31+
tmp = OCIExtProcAllocCallMemory(ctx, 1);
32+
tmp[0] = '\0';
5533

56-
if (tag_i == OCI_IND_NOTNULL)
57-
{
58-
asprintf(&themetric,"%s:%d|%s|#%s",metricname, metric, thekind,tag);
59-
}
34+
return(tmp);
35+
}
6036

61-
udp(8125, themetric);
37+
// the main part
38+
strcat(metricname, name);
6239

40+
if (kind_i == OCI_IND_NOTNULL)
41+
{
42+
asprintf(&thekind,"%s",kind);
43+
} else {
44+
asprintf(&thekind,"%s","g"); // no kind, we default to gauge
45+
}
6346

64-
// the reply part
65-
// the text for return
47+
if (tag_i == OCI_IND_NOTNULL)
48+
{
49+
asprintf(&themetric,"%s:%d|%s|#%s",metricname, metric, thekind,tag);
50+
} else {
51+
asprintf(&themetric,"%s:%d|%s|",metricname, metric, thekind);
52+
}
6653

67-
char *reply = "done";
54+
udp(8125, themetric); // we fire the metric to datadog
6855

69-
// Allocate memory for result string, including NULL terminator.
70-
len = strlen(reply);
71-
tmp = OCIExtProcAllocCallMemory(ctx, len + 1);
72-
tmp[0] = '\0';
56+
// the reply part
57+
char *reply = "done"; // as udp is stateless, we assume all went fine
7358

74-
// set the reply
75-
strcat(tmp, reply);
59+
// Allocate memory for result string, including NULL terminator.
60+
len = strlen(reply);
61+
tmp = OCIExtProcAllocCallMemory(ctx, len + 1);
62+
tmp[0] = '\0';
7663

77-
// Set NULL indicator and length.
78-
*ret_i = (short)OCI_IND_NOTNULL;
79-
*ret_l = len;
64+
// set the reply
65+
strcat(tmp, reply);
8066

81-
// Return pointer, which PL/SQL frees later.
82-
return tmp;
83-
}
67+
// Set ret indicator and length.
68+
*ret_i = (short)OCI_IND_NOTNULL;
69+
*ret_l = len;
8470

71+
// Return pointer, which PL/SQL frees later.
72+
return tmp;
73+
}

0 commit comments

Comments
 (0)