sql

package
v0.0.0-...-ef58ad5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: GPL-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchRowsAsStructSlice

func FetchRowsAsStructSlice(rows *sql.Rows, rowType interface{}, limit int) (interface{}, error)

FetchRowsAsStructSlice fetches rows - at most limit (unless -1) - as slice of rowType's type. Consult the unit tests for usage examples.

func MysqlSplitStatements

func MysqlSplitStatements(statements string) []string

MysqlSplitStatements takes a string containing multiple SQL statements and splits them into individual statements with limited support for the DELIMITER keyword like implemented by the mysql command line client.

The main purpose of this function is to allow importing a schema file containing stored functions from Go. Such files have to specify an alternative delimiter internally if the function has semicolons in its body, otherwise the mysql command line clients splits the CREATE FUNCTION statement somewhere in the middle. This delimiter handling is not supported by the MySQL server, so when trying to import such a schema file using a different method than the mysql command line client, the delimiter handling has to be reimplemented. This is what this function does.

To avoid an overly complex implementation, this function has some limitations on its input:

  • Specifying a delimiter using a quoted string is NOT supported.
  • Statements are only split if the delimiter appears at the end of a line. This in done in order to avoid accidentally splitting in the middle of string literals and comments.
  • The function does not attempt to handle comments in any way, so there must not be a delimiter at the end of a line within a comment.
  • The delimiter command is only recognized at the beginning of the file or immediately following a delimiter at the end of a previous line, there must not be a comment in between, empty lines are fine.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL