# HG changeset patch # User Sebastien Decugis # Date 1273469202 -32400 # Node ID a77ed0e30ac96affb0b1b3e7af94b088c3cd2a89 # Parent 2d3a799ad29c23570e07804defec564cb2cdd434 Fix non-working timestamp field diff -r 2d3a799ad29c -r a77ed0e30ac9 extensions/app_acct/acct_db.c --- a/extensions/app_acct/acct_db.c Mon May 10 14:10:51 2010 +0900 +++ b/extensions/app_acct/acct_db.c Mon May 10 14:26:42 2010 +0900 @@ -157,13 +157,12 @@ ADD_EXTEND("\") VALUES ("); if (acct_config->tsfield) { - ADD_EXTEND("'now', "); + ADD_EXTEND("$%d, ", ++idx); } for (li = emptyrecords.all.next; li != &emptyrecords.all; li = li->next) { struct acct_record_item * i = (struct acct_record_item *)(li->o); - idx += 1; - ADD_EXTEND("$%d::%s", idx, diam2db_types_mapping[i->param->avptype]); + ADD_EXTEND("$%d::%s", ++idx, diam2db_types_mapping[i->param->avptype]); if (li->next != &emptyrecords.all) { ADD_EXTEND(", "); @@ -206,6 +205,7 @@ int *val_len; int *val_isbin; int idx = 0; + int size = 0; PGresult *res; struct fd_list *li; @@ -223,10 +223,19 @@ } } + size = acct_config->tsfield ? records->nball + 1 : records->nball; + /* Alloc the arrays of parameters */ - CHECK_MALLOC( val = calloc(records->nball, sizeof(const char *)) ); - CHECK_MALLOC( val_len = calloc(records->nball, sizeof(const int)) ); - CHECK_MALLOC( val_isbin = calloc(records->nball, sizeof(const int)) ); + CHECK_MALLOC( val = calloc(size, sizeof(const char *)) ); + CHECK_MALLOC( val_len = calloc(size, sizeof(const int)) ); + CHECK_MALLOC( val_isbin = calloc(size, sizeof(const int)) ); + + if (acct_config->tsfield) { + val[idx] = "now"; + val_len[idx] = 3; + val_isbin[idx] = 0; + idx++; + } /* Now write all the map'd records in these arrays */ for (li = records->all.next; li != &records->all; li = li->next) { @@ -264,7 +273,7 @@ } /* OK, now execute the SQL statement */ - res = PQexecPrepared(conn, stmt, records->nball, (const char * const *)val, val_len, val_isbin, 1 /* We actually don't care here */); + res = PQexecPrepared(conn, stmt, size, (const char * const *)val, val_len, val_isbin, 1 /* We actually don't care here */); /* Done with the parameters */ free(val);