mysqlinternals

package
Version: v0.0.0-...-d9cb0cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2017 License: MPL-2.0 Imports: 11 Imported by: 1

README

Sqlinternals: github.com/go-sql-driver/mysql support

Build Status

Provide a way to get column metadata for results.

This has to use unsafe, so it can't be used in some contexts.

Documentation lives at godoc.org.

License: MPL2.

Documentation

Index

Constants

View Source
const (
	// unknown type, no information about parameter requirements
	ParamUnknown parameterType = iota
	// requires no parameters in MySQL declaration
	ParamNone
	// requires no parameters or length (int > 0) in MySQL declaration
	ParamMayLength
	// requires length (int > 0) in MySQL declaration
	ParamMustLength

	// requires valid values as parameters in MySQL declaration
	ParamValues
)

Variables

This section is empty.

Functions

func IsBinary

func IsBinary(rowOrRows interface{}) (bool, error)

IsBinary reports whether the row value was retrieved using the binary protocol.

MySQL results retrieved with prepared statements or Query with additional arguments use the binary protocol. The results are typed, the driver will use the closest matching Go type. A plain Query call with only the query itself will not use the binary protocol but the text protocol. The results are all strings in that case.

Types

type Column

type Column interface {

	// Name returns the column name, matching that of a call to Columns() in database/sql
	Name() string

	// MysqlType returns the raw sql type name without parameters and modifiers
	MysqlType() string
	// IsNumber returns true if the column contains numbers (one of integer, decimal or floating point)
	IsNumber() bool
	// IsInteger returns true if the column contains integers
	IsInteger() bool
	// IsFloatingPoint returns true if the column contains floating point numbers
	IsFloatingPoint() bool
	// IsDecimal returns true if the column contains decimal numbers
	IsDecimal() bool
	// IsText returns true if the column contains textual data
	IsText() bool
	// IsBlob returns true if the column contains binary blobs
	IsBlob() bool
	// IsTime returns true if the column contains temporal data
	IsTime() bool

	// IsPrimaryKey returns true if the column is marked as part of a primary key (*).
	IsPrimaryKey() bool
	// IsUniqueKey returns true if the column is marked as part of a unique key (*).
	IsUniqueKey() bool
	// IsMultipleKey returns true if the column is marked as part of a regular key (*).
	IsMultipleKey() bool
	// IsNotNull returns true if the column is marked as NOT NULL (*).
	IsNotNull() bool
	// IsUnsigned returns true if the column is marked as UNSIGNED (*).
	IsUnsigned() bool
	// IsZerofill returns true if the column is marked as ZEROFILL (*).
	IsZerofill() bool
	// IsBinary returns true if the column is marked as BINARY (*).
	IsBinary() bool
	// IsAutoIncrement returns true if the column is marked as AUTO_INCREMENT (*).
	IsAutoIncrement() bool

	// derived from mysqlField.decimals
	Decimals() int

	// MysqlParameters returns the category of parameters the SQL type expects in MysqlDeclaration.
	MysqlParameters() parameterType
	// MysqlDeclaration returns a type declaration usable in a CREATE TABLE statement.
	MysqlDeclaration(params ...interface{}) (string, error)
	// ReflectGoType returns the smallest Go type able to represent all possible regular values.
	// The returned types assume a non-NULL value and may cause problems
	// on conversion (e.g. MySQL DATE "0000-00-00", which is not mappable to Go).
	ReflectGoType() (reflect.Type, error)
	// ReflectSqlType returns a Go type able to contain the SQL type, including null values.
	// The returned types may cause problems on conversion
	// (e.g. MySQL DATE "0000-00-00", which is not mappable to Go).
	// The returned type assumes IsNotNull() to be false when forceNullable is set
	// and attempts to return a nullable type (e.g. sql.NullString instead of string).
	ReflectSqlType(forceNullable bool) (reflect.Type, error)
}

Column represents the column of a MySQL result. The methods below postfixed with (*) return information for MySQL internal flags. Please note that I can't say if these are trustworthy (esp. IsNotNull), they come directly from MySQL. At least for SCHEMA information, MySQL can report false metadata, I don't know if this is different for results.

func Columns

func Columns(rowOrRows interface{}) ([]Column, error)

Columns retrieves a []Column for sql.Rows or sql.Row with type inspection abilities.

The field indices match those of a call to Columns(). Returns an error if the argument is not sql.Rows or sql.Row based on github.com/go-sql-driver/mysql.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto