diff --git a/clickhouse/clickhouse.go b/clickhouse/clickhouse.go index 7795e20..34b6353 100644 --- a/clickhouse/clickhouse.go +++ b/clickhouse/clickhouse.go @@ -35,6 +35,15 @@ type Serve struct { } func (s *Serve) Connect() error { + var err error + if s == nil || s.conn == nil { + err = errors.New("conn is null") + } else { + err = s.conn.Ping() + } + if err == nil { + return nil + } switch s.DriveMode { case 1: s.conn, s.Error = s.DriveServe(s.Serve) @@ -60,19 +69,15 @@ func (s *Serve) Close() error { } func (s *Serve) query(command string, args ...interface{}) (*sql.Rows, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Query(command, args...) } func (s *Serve) exec(command string, args ...interface{}) (sql.Result, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Exec(command, args...) } diff --git a/gsql.go b/gsql.go index c684c17..ddd3dc6 100644 --- a/gsql.go +++ b/gsql.go @@ -157,7 +157,6 @@ func (s *Serve) GetORM() *ORM { case <-orm.chanComplete: return case <-time.After(time.Second * time.Duration(s.Timeout)): - orm.Close() orm.Dispose() } }(c) diff --git a/mssqls/mssql.go b/mssqls/mssql.go index 7926f12..7ba4003 100644 --- a/mssqls/mssql.go +++ b/mssqls/mssql.go @@ -35,6 +35,15 @@ type Serve struct { } func (s *Serve) Connect() error { + var err error + if s == nil || s.conn == nil { + err = errors.New("conn is null") + } else { + err = s.conn.Ping() + } + if err == nil { + return nil + } switch s.DriveMode { case 1: s.conn, s.Error = s.DriveServe(s.Serve) @@ -60,19 +69,15 @@ func (s *Serve) Close() error { } func (s *Serve) query(command string, args ...interface{}) (*sql.Rows, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Query(command, args...) } func (s *Serve) exec(command string, args ...interface{}) (sql.Result, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Exec(command, args...) } diff --git a/mysqls/mysql.go b/mysqls/mysql.go index 4f88084..8566544 100644 --- a/mysqls/mysql.go +++ b/mysqls/mysql.go @@ -35,6 +35,15 @@ type Serve struct { } func (s *Serve) Connect() error { + var err error + if s == nil || s.conn == nil { + err = errors.New("conn is null") + } else { + err = s.conn.Ping() + } + if err == nil { + return nil + } switch s.DriveMode { case 1: s.conn, s.Error = s.DriveServe(s.Serve) @@ -60,19 +69,15 @@ func (s *Serve) Close() error { } func (s *Serve) query(command string, args ...interface{}) (*sql.Rows, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Query(command, args...) } func (s *Serve) exec(command string, args ...interface{}) (sql.Result, error) { - if s.conn == nil { - if err := s.Connect(); err != nil { - return nil, err - } + if err := s.Connect(); err != nil { + return nil, err } return s.conn.Exec(command, args...) }