I'm a little bit irritated. This works now with my small table, which name is of course not 'myTable'
I don't know what I changed...
So I have only another problem with my larger table:
CREATE TABLE `test-daten` (
`d_event` char(16) COLLATE latin1_german1_ci DEFAULT NULL,
`d_time` int(11) NOT NULL,
`d_ts` int(16) DEFAULT NULL,
`ref` varchar(50) COLLATE latin1_german1_ci DEFAULT NULL,
`d_dir` varchar(16) COLLATE latin1_german1_ci DEFAULT NULL,
`d_src_if` varchar(16) COLLATE latin1_german1_ci DEFAULT NULL,
`d_dst_if` varchar(16) COLLATE latin1_german1_ci DEFAULT NULL,
`d_src_cgpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_src_dgpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_src_cdpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_dst_cgpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_dst_dgpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_dst_cdpn` varchar(35) COLLATE latin1_german1_ci DEFAULT NULL,
`d_bcaps` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_cause` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_xcoder` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_rcoder` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_xstats` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_rstats` varchar(32) COLLATE latin1_german1_ci DEFAULT NULL,
`d_alert_time` int(11) DEFAULT NULL,
`d_connect_time` int(11) DEFAULT NULL,
`d_disc_time` int(11) DEFAULT NULL,
`d_srvid` varchar(16) COLLATE latin1_german1_ci DEFAULT NULL,
`d_start_time` int(11) DEFAULT NULL,
`d_result` varchar(10) COLLATE latin1_german1_ci NOT NULL,
KEY `Zeitraum` (`d_start_time`,`d_disc_time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci
Here is the content of my function:
var value01 = msg.cdr.event;
var value02 = msg.cdr.time;
var value03 = msg.cdr.ts;
var value05 = msg.cdr.ref;
var value06 = msg.cdr.dir;
var value07 = msg.cdr.src_if;
var value08 = msg.cdr.dst_if;
var value09 = msg.cdr.src_cgpn;
var value10 = msg.cdr.src_dgpn;
var value11 = msg.cdr.src_cdpn;
var value12 = msg.cdr.dst_cgpn;
var value13 = msg.cdr.dst_dgpn;
var value14 = msg.cdr.dst_cdpn;
var value15 = msg.cdr.bcaps;
var value16 = msg.cdr.xcoder;
var value17 = msg.cdr.rcoder;
var value18 = msg.cdr.xstats;
var value19 = msg.cdr.rstats;
var value20 = msg.cdr.alert_time;
var value21 = msg.cd.connect_time;
var value22 = msg.cdr.disc_time;
var value23 = msg.cdr.srv_id;
var value24 = msg.cdr.start_time;
var value25 = msg.cdr.result;
msg.tpoic = "INSERT INTO `test-data` (`d_event`, `d_time`, `d_ts`, `ref`, `d_dir`, `d_src_if`, `d_dst_if`, `d_src_cgpn`, `d_src_dgpn`, `d_src_cdpn`, `d_dst_cgpn`, `d_dst_dgpn`, `d_dst_cdpn`, `d_bcaps`, `d_cause`, `d_xcoder`, `d_rcoder`, `d_xstats`, `d_rstats`, `d_alert_time`, `d_connect_time`, `d_disc_time`, `d_srvid`,`d_start_time`,`d_result`) values ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
msg.payload = [value01, value02, value03, value05, value06, value07,value08, value09, value10, value11, value12, value13, value14, value15, value16, value17, value18, value19, value20, value21, value22, value23, value24, value25];
return msg;
The problem is here, that not all values are delivered in all cases. So I get a type-error:
TypeError: Cannot read property 'connect_time' of undefined
Thats right for me - but not helpful. So I tried to use the Nullish Coalescing Operator:
var value01 = msg.cdr.event ?? null;
But the script-window gives a warning and it does not working. I think it makes no sense or it is not possible to send null-values in this way of creating a SQL-query?
So I guess I have to build it over a check-function?
Niels