From 9f3a211ed9c30fe78282797c044ff08632fe4c55 Mon Sep 17 00:00:00 2001 From: Nash Tsai Date: Wed, 18 Dec 2013 22:55:39 +0800 Subject: [PATCH] code tidy up --- statement.go | 21 --------------------- table.go | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/statement.go b/statement.go index 2ceeee69..fc5187aa 100644 --- a/statement.go +++ b/statement.go @@ -10,27 +10,6 @@ import ( "time" ) -// !nashtsai! treat following var as interal const values, these are used for reflect.TypeOf comparision -var ( - c_EMPTY_STRING = "" - c_BOOL_DEFAULT = false - c_COMPLEX64_DEFAULT = complex64(0) - c_COMPLEX128_DEFAULT = complex128(0) - c_FLOAT32_DEFAULT = float32(0) - c_FLOAT64_DEFAULT = float64(0) - c_INT64_DEFAULT = int64(0) - c_UINT64_DEFAULT = uint64(0) - c_INT32_DEFAULT = int32(0) - c_UINT32_DEFAULT = uint32(0) - c_INT16_DEFAULT = int16(0) - c_UINT16_DEFAULT = uint16(0) - c_INT8_DEFAULT = int8(0) - c_UINT8_DEFAULT = uint8(0) - c_INT_DEFAULT = int(0) - c_UINT_DEFAULT = uint(0) - c_TIME_DEFAULT time.Time = time.Unix(0, 0) -) - // statement save all the sql info for executing SQL type Statement struct { RefTable *Table diff --git a/table.go b/table.go index 976e30f9..aac87528 100644 --- a/table.go +++ b/table.go @@ -115,8 +115,27 @@ var ( uintTypes = sort.StringSlice{"*uint", "*uint16", "*uint32", "*uint8"} ) -var b byte -var tm time.Time +// !nashtsai! treat following var as interal const values, these are used for reflect.TypeOf comparision +var ( + c_EMPTY_STRING string + c_BOOL_DEFAULT bool + c_BYTE_DEFAULT byte + c_COMPLEX64_DEFAULT complex64 + c_COMPLEX128_DEFAULT complex128 + c_FLOAT32_DEFAULT float32 + c_FLOAT64_DEFAULT float64 + c_INT64_DEFAULT int64 + c_UINT64_DEFAULT uint64 + c_INT32_DEFAULT int32 + c_UINT32_DEFAULT uint32 + c_INT16_DEFAULT int16 + c_UINT16_DEFAULT uint16 + c_INT8_DEFAULT int8 + c_UINT8_DEFAULT uint8 + c_INT_DEFAULT int + c_UINT_DEFAULT uint + c_TIME_DEFAULT time.Time +) func Type2SQLType(t reflect.Type) (st SQLType) { switch k := t.Kind(); k { @@ -131,7 +150,7 @@ func Type2SQLType(t reflect.Type) (st SQLType) { case reflect.Complex64, reflect.Complex128: st = SQLType{Varchar, 64, 0} case reflect.Array, reflect.Slice, reflect.Map: - if t.Elem() == reflect.TypeOf(b) { + if t.Elem() == reflect.TypeOf(c_BYTE_DEFAULT) { st = SQLType{Blob, 0, 0} } else { st = SQLType{Text, 0, 0} @@ -141,7 +160,7 @@ func Type2SQLType(t reflect.Type) (st SQLType) { case reflect.String: st = SQLType{Varchar, 255, 0} case reflect.Struct: - if t == reflect.TypeOf(tm) { + if t == reflect.TypeOf(c_TIME_DEFAULT) { st = SQLType{DateTime, 0, 0} } else { st = SQLType{Text, 0, 0} @@ -200,7 +219,7 @@ func SQLType2Type(st SQLType) reflect.Type { case Bool: return reflect.TypeOf(true) case DateTime, Date, Time, TimeStamp, TimeStampz: - return reflect.TypeOf(tm) + return reflect.TypeOf(c_TIME_DEFAULT) case Decimal, Numeric: return reflect.TypeOf("") default: