66 char sqlcmd[2048] =
"", timestr[128];
74 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s "
75 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,"
76 "lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) "
77 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
table, timestr);
79 snprintf(sqlcmd,
sizeof(sqlcmd),
"INSERT INTO %s "
80 "(calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,"
81 "duration,billsec,disposition,amaflags,accountcode) "
82 "VALUES ({ts '%s'},?,?,?,?,?,?,?,?,?,?,?,?,?)",
table, timestr);
85 ODBC_res = SQLAllocHandle(SQL_HANDLE_STMT, obj->
con, &stmt);
87 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
88 ast_verb(11,
"cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
89 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
93 SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
clid), 0, cdr->
clid, 0, NULL);
94 SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
src), 0, cdr->
src, 0, NULL);
95 SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dst), 0, cdr->
dst, 0, NULL);
96 SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dcontext), 0, cdr->
dcontext, 0, NULL);
97 SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
channel), 0, cdr->
channel, 0, NULL);
98 SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
dstchannel), 0, cdr->
dstchannel, 0, NULL);
99 SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastapp), 0, cdr->
lastapp, 0, NULL);
100 SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
lastdata), 0, cdr->
lastdata, 0, NULL);
103 double hrbillsec = 0.0;
111 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrduration, 0, NULL);
112 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 0, 0, &hrbillsec, 0, NULL);
114 SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
duration, 0, NULL);
115 SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
billsec, 0, NULL);
121 SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
disposition, 0, NULL);
122 SQLBindParameter(stmt, 12, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &cdr->
amaflags, 0, NULL);
123 SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
accountcode), 0, cdr->
accountcode, 0, NULL);
126 SQLBindParameter(stmt, 14, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
uniqueid), 0, cdr->
uniqueid, 0, NULL);
127 SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
sizeof(cdr->
userfield), 0, cdr->
userfield, 0, NULL);
130 ODBC_res = SQLExecDirect(stmt, (
unsigned char *)sqlcmd, SQL_NTS);
132 if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
133 ast_verb(11,
"cdr_odbc: Error in ExecDirect: %d\n", ODBC_res);
134 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
char accountcode[AST_MAX_ACCOUNT_CODE]
char dstchannel[AST_MAX_EXTENSION]
static struct ast_flags config
#define ast_test_flag(p, flag)
char dcontext[AST_MAX_EXTENSION]
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
#define ast_verb(level,...)
char lastdata[AST_MAX_EXTENSION]
char dst[AST_MAX_EXTENSION]
char channel[AST_MAX_EXTENSION]
Responsible for call detail data.
char lastapp[AST_MAX_EXTENSION]
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
char src[AST_MAX_EXTENSION]
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
char clid[AST_MAX_EXTENSION]
char * ast_cdr_disp2str(int disposition)
Disposition to a string.
char userfield[AST_MAX_USER_FIELD]