From 4192dcc9fc46c826a13441f67a11a824933fa5b6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 3 Sep 2020 20:06:44 +0800 Subject: [PATCH] 1 --- csvreader.go | 20 ++++++++++++++++---- sysutils.go | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/csvreader.go b/csvreader.go index 1eac367..006f131 100644 --- a/csvreader.go +++ b/csvreader.go @@ -3,10 +3,11 @@ package q5 import "io" import "os" import "bufio" +import "strings" type CsvReader struct { columns map[string]int32 - values []XValue + values []string currLine int lines []string @@ -14,7 +15,7 @@ type CsvReader struct { func (this *CsvReader) Load(fileName string) bool { this.columns = map[string]int32{} - this.values = []XValue{} + this.values = []string{} this.currLine = 0 this.lines = []string{} @@ -38,14 +39,25 @@ func (this *CsvReader) NextLine() bool { if this.currLine >= len(this.lines) { return false } + this.values = strings.Split(this.lines[this.currLine], ",") this.currLine++ return true } func (this *CsvReader) GetValue(fieldName string) *XValue { - return nil + index, ok := this.columns[fieldName] + if ok { + if index >= 0 && index < int32(len(this.values)) { + return (&XValue{}).SetString(this.values[index]) + } else { + return &XValue{} + } + } else { + return &XValue{} + } } func (this *CsvReader) KeyExists(fieldName string) bool { - return true + _, ok := this.columns[fieldName] + return ok } diff --git a/sysutils.go b/sysutils.go index 7bb3ef2..3b9c725 100644 --- a/sysutils.go +++ b/sysutils.go @@ -1,5 +1,11 @@ package q5 +import "time" + func GetDaySeconds(seconds int64) int64 { return 0 } + +func GetTickCount() int64 { + return time.Now().UnixNano() / 1e6 +}