# -*- text -*-

##
##  Queries to update the CUI table.
##
postauth_query = "INSERT IGNORE INTO ${cui_table} \
	(clientipaddress, callingstationid, username, cui, lastaccounting) \
        VALUES \
	('%{Client-IP-Address}', '%{Calling-Station-Id}', '%{User-Name}', '%{reply:Chargeable-User-Identity}', NULL) ON DUPLICATE KEY UPDATE lastaccounting='0000-00-00 00:00:00', cui='%{reply:Chargeable-User-Identity}'";

accounting_start_query = "UPDATE ${cui_table} \
	SET \
                lastaccounting = CURRENT_TIMESTAMP \
	WHERE clientipaddress = '%{Client-IP-Address}' \
        AND callingstationid = '%{Calling-Station-Id}' \
        AND username = '%{User-Name}' \
	AND cui = '%{Chargeable-User-Identity}'";
  
accounting_update_query = "UPDATE ${cui_table} \
	SET \
                lastaccounting = CURRENT_TIMESTAMP \
	WHERE clientipaddress = '%{Client-IP-Address}' \
        AND callingstationid = '%{Calling-Station-Id}' \
        AND username = '%{User-Name}' \
	AND cui = '%{Chargeable-User-Identity}'";

accounting_stop_query = "DELETE FROM ${cui_table} WHERE \
	clientipaddress = '%{Client-IP-Address}' \
	AND callingstationid = '%{Calling-Station-Id}' \
	AND username = '%{User-Name}' \
	AND cui = '%{Chargeable-User-Identity}'";
