<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/2042/1/7/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/MySQL+CDR+Backend?focusedCommentId=13076842#comment-13076842">MySQL CDR Backend</a></h2>
<h4>Comment edited by <a href="https://wiki.asterisk.org/wiki/display/~kwk">Konrad Kleine</a>
:</h4>
<br/>
<h4>Changes (1)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >{code} <br>So what's Asterisk internally called *start* is called *calldate* in MySQL. As you can see from the *.conf* excerpt, the same goes for *callerid* and *clid*. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>If I'm not totally mistaken, *end* and *answer* can be derived from *duration* and *billsec*. In the original description of the CDR fields (see [AST:CDR Fields]) it says this: <br>{quote} <br>* start: Start of call (date/time) <br>* answer: Answer of call (date/time) <br>* end: End of call (date/time) <br>* duration: Total time in system, in seconds (integer), from dial to hangup <br>* billsec: Total time call is up, in seconds (integer), from answer to hangup <br>{quote} <br>In MySQL you only have *duration*, *billsec*, and *start* which is actually called *calldate*. <br> <br>Thus, this should be what you're looking for: <br> <br>*start* = calldate <br>*answer* = start + (duration - billsec) <br>*end* = start + duration <br> <br>In SQL this would look like this: <br>{code:sql} <br>SELECT <br> *, <br> (`calldate`+(`duration`-`billsec`)) AS answer, <br> (`calldate`+`duration`) AS `end` <br>FROM <br> cdr; <br>{code} <br>If you want to create a view to avoid this calculation by hand you can do so with this command: <br>{code:sql} <br>CREATE VIEW cdr_full AS <br>SELECT <br> *, <br> (`calldate`+(`duration`-`billsec`)) AS answer, <br> (`calldate`+`duration`) AS `end` <br>FROM <br> cdr; <br>{code} <br>There is one problem with the column types though: *answer* and *end* in my case are of type *double(23,6)* which is not what we want. To fix this we need to do some casting (Don't know if this is MySQL specific): <br>{code:sql} <br>CREATE VIEW cdr_full AS <br>SELECT <br> *, <br> CAST( `calldate`+(`duration`-`billsec`) AS DATETIME ) as `answer`, <br> CAST( `calldate`+`duration` AS DATETIME ) AS `end` <br>FROM <br> `cdr`; <br>{code} <br>If you want to be perfectly correct, the colum attributes like *NOT NULL* and default values need to be set correctly. <br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>The <b>start</b> is already there, but it's called <b>calldate</b> in MySQL for instance.</p>
<p>If you do a</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: bash; gutter: false"><![CDATA[
grep "^[^;]" /etc/asterisk/cdr_mysql.conf
]]></script>
</div></div>
<p>on an Asterisk 1.8.4 installation amongst other things it reveals:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: bash; gutter: false"><![CDATA[
[columns]
alias start => calldate
alias callerid => clid
]]></script>
</div></div>
<p>So what's Asterisk internally called <b>start</b> is called <b>calldate</b> in MySQL. As you can see from the <b>.conf</b> excerpt, the same goes for <b>callerid</b> and <b>clid</b>.</p>
<p>If I'm not totally mistaken, <b>end</b> and <b>answer</b> can be derived from <b>duration</b> and <b>billsec</b>. In the original description of the CDR fields (see <a href="/wiki/display/AST/CDR+Fields" title="CDR Fields">CDR Fields</a>) it says this:</p>
<blockquote>
<ul>
        <li>start: Start of call (date/time)</li>
        <li>answer: Answer of call (date/time)</li>
        <li>end: End of call (date/time)</li>
        <li>duration: Total time in system, in seconds (integer), from dial to hangup</li>
        <li>billsec: Total time call is up, in seconds (integer), from answer to hangup</li>
</ul>
</blockquote>
<p>In MySQL you only have <b>duration</b>, <b>billsec</b>, and <b>start</b> which is actually called <b>calldate</b>.</p>
<p>Thus, this should be what you're looking for:</p>
<p><b>start</b> = calldate<br/>
<b>answer</b> = start + (duration - billsec)<br/>
<b>end</b> = start + duration</p>
<p>In SQL this would look like this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: sql; gutter: false"><![CDATA[
SELECT
*,
(`calldate`+(`duration`-`billsec`)) AS answer,
(`calldate`+`duration`) AS `end`
FROM
cdr;
]]></script>
</div></div>
<p>If you want to create a view to avoid this calculation by hand you can do so with this command:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: sql; gutter: false"><![CDATA[
CREATE VIEW cdr_full AS
SELECT
*,
(`calldate`+(`duration`-`billsec`)) AS answer,
(`calldate`+`duration`) AS `end`
FROM
cdr;
]]></script>
</div></div>
<p>There is one problem with the column types though: <b>answer</b> and <b>end</b> in my case are of type <b>double(23,6)</b> which is not what we want. To fix this we need to do some casting (Don't know if this is MySQL specific):</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: sql; gutter: false"><![CDATA[
CREATE VIEW cdr_full AS
SELECT
*,
CAST( `calldate`+(`duration`-`billsec`) AS DATETIME ) as `answer`,
CAST( `calldate`+`duration` AS DATETIME ) AS `end`
FROM
`cdr`;
]]></script>
</div></div>
<p>If you want to be perfectly correct, the colum attributes like <b>NOT NULL</b> and default values need to be set correctly.</p>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;">
<a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/MySQL+CDR+Backend?focusedCommentId=13076842#comment-13076842">View Online</a>
|
<a id="reply-13076842" href="https://wiki.asterisk.org/wiki/display/AST/MySQL+CDR+Backend?replyToComment=13076842#comment-13076842">Reply To This</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>