Wrap commits in a transaction.

This commit is contained in:
Mahlon E. Smith 2018-02-12 13:25:26 -08:00
parent 2e19a79772
commit 9f4f661eef

View file

@ -129,10 +129,14 @@ proc process( client: Socket, db: DBConn ): void =
return return
var samples = parse_data( raw_data ) var samples = parse_data( raw_data )
if samples.len == 0: return
db.exec sql( "BEGIN" )
for timestamp, sample in samples: for timestamp, sample in samples:
var host = sample[ "hostname" ].get_str var host = sample[ "hostname" ].get_str
sample.delete( "hostname" ) sample.delete( "hostname" )
db.exec sql( INSERT_SQL ), timestamp, host, sample db.exec sql( INSERT_SQL ), timestamp, host, sample
db.exec sql( "COMMIT" )
proc serverloop: void = proc serverloop: void =
## Open a database connection, bind to the listening socket, ## Open a database connection, bind to the listening socket,