Documentation ¶
Overview ¶
Package connector: connect to MySQL, execute raw sql statements, return raw execution result or error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector struct { DSN string Host string Port int Username string Password string DbName string // contains filtered or unexported fields }
Connector: connect to MySQL, execute raw sql statements, return raw execution result or error.
func NewConnector ¶
func NewConnector(host string, port int, username string, password string, dbname string) (*Connector, error)
NewConnector: create Connector. CREATE DATABASE IF NOT EXISTS dbname + USE dbname when dbname != ""
type Result ¶
type Result struct { ColumnNames []string ColumnTypes []string Rows [][]string Err error Time time.Duration // total time }
Result:
query result, for example:
+-----+------+------+ | 1+2 | ID | NAME | -> ColumnNames: 1+2, ID, NAME +-----+------+------+ -> ColumnTypes: BIGINT, INT, TEXT | 3 | 1 | H | -> Rows[0]: 3, 1, H | 3 | 2 | Z | -> Rows[1]: 3, 2, Z | 3 | 3 | Y | -> Rows[2]: 3, 3, Y +-----+------+------+
or error, for example:
Err: ERROR 1054 (42S22): Unknown column 'T' in 'field list'
note that:
len(ColumnNames) = len(ColumnTypes) = len(Rows[i]);
if the statement is not SELECT, then the ColumnNames, ColumnTypes and Rows are empty
func (*Result) GetErrorCode ¶
Click to show internal directories.
Click to hide internal directories.