[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cistron-radius
Subject:    Question about mysql.c in cistron 1.6.4 patch
From:       "Ershad Shafi Chowdhury" <iru () bol-online ! com>
Date:       2001-04-30 12:36:47
[Download RAW message or body]

Hi! Perhaps this is more of a programming or sql question than of a radius
one. I apologize if it is inappropriate, but I am not a programmer. Anyway,
now to my problem. First I should show the sql log. Note that in the INSERT
statement start_time, connect_info is not entered. In the UPDATE statement
it is.

INSERT INTO usertime (id, time_on, name, server, port, port_type
, service_type, protocol, ip, call_to, call_from, InBytes, OutBytes,
term_cause,
 auth) VALUES
('018a0305',0,'noone','202.84.34.7',24,0,2,1,'202.84.34.163','','',0,0,0,1);

UPDATE usertime SET start_time=20010430180930,connect_info='28800' WHERE
id='018a0305' AND server='202.84.34.7' AND name='noone';

I would like the information to be entered in one sql query instead of two.
I can't figure out why the code uses two separate sql queries. I would think
it would be simpler to either enter Connect_info & start_time in the first
statement OR to leave it out completely and use it after "if (rec->start ==
1)" ... The only thing i could come up with was that the radius server would
try to INSERT then if it fails, it won't bother with the rest.

Extract from mysql.c included below ...

       sprintf(buf, "INSERT INTO %s (id, time_on, name, server, port,
port_type
, service_type, protocol, ip, call_to, call_from, InBytes, OutBytes,
term_cause,
 auth) VALUES ('%s',%ld,'%s','%s',%i,%i,%i,%i,'%s','%s','%s',%u,%u,%i,%i)",
               mysql_acct_table,
               rec->id,
               rec->time_used,
               rec->name,
               rec->server,
               rec->port,
               rec->port_type,
               rec->service_type,
               rec->protocol,
               rec->ip,
               rec->call_to,
               rec->call_from,
               rec->inbytes,
               rec->outbytes,
               rec->term_cause,
               rec->auth
               );
               DEBUG("%s",buf);

       if ((mysql_acct != NULL) && (num == 0)) { //Only insert it if its not
there
               if (sqloutfd) {
                  fputs(buf, sqloutfd);
                  fputs(";\n", sqloutfd);
                  fflush(sqloutfd);
               }

               err = my_mysql_query(buf, mysql_acct, MYSQL_ACCT);

               if ((rec->start == 1) && err) {
                       log(L_ERR,"MYSQL Error: Cannot insert");
               }
       }
       if (rec->start == 1) {
               sprintf(buf, "UPDATE %s SET start_time=%s,connect_info='%s'
WHERE id='%s' AND server='%s' AND name='%s'",
                       mysql_acct_table,
                       datebuf,
                       rec->connect_info,
                       rec->id, rec->server, rec->name);

Thanks!

Ershad


- 
List info/subscribe/unsubscribe? See http://www.radius.cistron.nl/list/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic