summaryrefslogtreecommitdiff
path: root/sqlQueries.go
diff options
context:
space:
mode:
Diffstat (limited to 'sqlQueries.go')
-rw-r--r--sqlQueries.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/sqlQueries.go b/sqlQueries.go
index 086e780..af4f469 100644
--- a/sqlQueries.go
+++ b/sqlQueries.go
@@ -7,6 +7,10 @@ import (
"time"
)
+const (
+ TIMEZONE = "UTC"
+)
+
//Retrieves all rawdata older than tim
func fetchRawData(db *sql.DB, tim time.Time) (rDat []RawData, err error) {
@@ -28,18 +32,18 @@ func fetchRawData(db *sql.DB, tim time.Time) (rDat []RawData, err error) {
return
}
- prepUp, err := tx.Prepare("UPDATE raw_data SET process_time = ? where ip_src = ? AND ip_dst = ? AND time = ? AND port = ? and packet_size = ? LIMIT 1")
+ prepUp, err := tx.Prepare("UPDATE raw_data SET process_time = ? where ip_src = ? AND ip_dst = ? AND time = ? AND port = ? and packet_size = ? AND process_time IS NULL LIMIT 1")
if err != nil {
log.Println("Failed to prepare update")
return
}
- loc, err := time.LoadLocation("Local")
+ loc, err := time.LoadLocation(TIMEZONE)
for rows.Next() {
var r RawData
var tim []byte
err = rows.Scan(&r.ipSrc, &r.ipDst, &tim, &r.port, &r.packetSize)
- r.time, err = time.ParseInLocation("2006-02-01 15:04:05", string(tim), loc)
+ r.time, err = time.ParseInLocation("2006-01-02 15:04:05", string(tim), loc)
if err != nil {
log.Println("Failed to scan result of query")
return
@@ -95,14 +99,14 @@ func purgeRawData(tx *sql.Tx, rDat []RawData) (err error) {
return
}
-func insertCleanData(tx *sql.Tx, ipbSrc, ipbDst, volume string, time time.Time, port, occurences int) error {
+func insertCleanData(tx *sql.Tx, ipbSrc, ipbDst, volume string, tim time.Time, port, occurences int) error {
prepStmt, err := tx.Prepare("INSERT INTO clean_data (ipb_src, ipb_dst, time, port, volume, occurences) VALUES ( ? , ? , ? , ? , ? , ?) ON DUPLICATE KEY UPDATE occurences = occurences + ?")
if err != nil {
log.Println("Failed to prepare statement")
return err
}
- _, err = prepStmt.Exec(ipbSrc, ipbDst, time, port, volume, occurences, occurences)
+ _, err = prepStmt.Exec(ipbSrc, ipbDst, tim, port, volume, occurences, occurences)
if err != nil {
log.Println("Failed to execute statement")
return err