bactract

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bactract is an exploration/attempt at extracting data from MS SQL Server bacpac files (BACpac-exTRACT)

Index

Constants

View Source
const (
	NullDatatype     = iota
	BigInt           = iota
	Binary           = iota
	Bit              = iota
	Char             = iota
	Date             = iota
	Datetime         = iota
	DatetimeOffset   = iota
	Datetime2        = iota
	Decimal          = iota
	Float            = iota
	Geography        = iota
	Int              = iota
	Money            = iota
	NChar            = iota
	NText            = iota
	Numeric          = iota
	NVarchar         = iota
	Real             = iota
	SmallDatetime    = iota
	SmallInt         = iota
	SmallMoney       = iota
	SQLVariant       = iota
	Time             = iota
	Text             = iota
	TinyInt          = iota
	UniqueIdentifier = iota
	Varbinary        = iota
	Varchar          = iota
)

Note that this is an incomplete (I think) list of the possible datatypes, however, ya gotta work with what ya got

Variables

This section is empty.

Functions

func BuffFileReader

func BuffFileReader(sz int, filenames []string) *buffFileReader

Types

type Bacpac

type Bacpac struct {
	// contains filtered or unexported fields
}

Bacpac is the base for an unzipped bacpac file

func New

func New(baseDir string) (b Bacpac, err error)

New returns a new Bacpac

func (Bacpac) ExportedTables

func (b Bacpac) ExportedTables() (s []string, err error)

ExportedTables returns the list of data containing tables found in the bacpac

func (Bacpac) GetModel

func (bp Bacpac) GetModel(ef string) (m ExtractedModel, err error)

GetModel extracts the portions of the table definitions needed for properly parsing/extracting the data from the BCP data files.

func (Bacpac) ModelFileName

func (bp Bacpac) ModelFileName() (n string)

ModelFileName returns the path/name for the model xml file

func (Bacpac) SetDebug

func (b Bacpac) SetDebug(debug bool)

type ColumnException

type ColumnException struct {
	SchemaName    string `json:"schemaName"`
	TableName     string `json:"tableName"`
	ColName       string `json:"columnName"`
	DataType      int
	DtStr         string `json:"dataType"`
	Length        int    `json:"length"`
	Scale         int    `json:"scale"`
	Precision     int    `json:"precision"`
	IsNullable    bool   `json:"isNullable"`
	IsAdulterated bool   `json:"isAdulterated"`
}

type ColumnExceptions

type ColumnExceptions struct {
	Columns []ColumnException
}

type DataSchemaModel

type DataSchemaModel struct {
	XMLName                xml.Name `xml:"DataSchemaModel"`
	Text                   string   `xml:",chardata"`
	FileFormatVersion      string   `xml:"FileFormatVersion,attr"`
	SchemaVersion          string   `xml:"SchemaVersion,attr"`
	DspName                string   `xml:"DspName,attr"`
	CollationLcid          string   `xml:"CollationLcid,attr"`
	CollationCaseSensitive string   `xml:"CollationCaseSensitive,attr"`
	Xmlns                  string   `xml:"xmlns,attr"`
	Model                  struct {
		Text    string `xml:",chardata"`
		Element []struct {
			Text          string `xml:",chardata"`
			Type          string `xml:"Type,attr"`
			Disambiguator string `xml:"Disambiguator,attr"`
			Name          string `xml:"Name,attr"`
			Property      []struct {
				Text      string `xml:",chardata"`
				Name      string `xml:"Name,attr"`
				AttrValue string `xml:"Value,attr"`
				Value     struct {
					Text              string `xml:",chardata"`
					QuotedIdentifiers string `xml:"QuotedIdentifiers,attr"`
					AnsiNulls         string `xml:"AnsiNulls,attr"`
				} `xml:"Value"`
			} `xml:"Property"`
			Relationship []struct {
				Text  string `xml:",chardata"`
				Name  string `xml:"Name,attr"`
				Entry []struct {
					Text       string `xml:",chardata"`
					References struct {
						Text           string `xml:",chardata"`
						Name           string `xml:"Name,attr"`
						ExternalSource string `xml:"ExternalSource,attr"`
						Disambiguator  string `xml:"Disambiguator,attr"`
					} `xml:"References"`
					Element struct {
						Text         string `xml:",chardata"`
						Type         string `xml:"Type,attr"`
						Name         string `xml:"Name,attr"`
						Relationship struct {
							Text  string `xml:",chardata"`
							Name  string `xml:"Name,attr"`
							Entry []struct {
								Text       string `xml:",chardata"`
								References struct {
									Text           string `xml:",chardata"`
									Name           string `xml:"Name,attr"`
									ExternalSource string `xml:"ExternalSource,attr"`
								} `xml:"References"`
								Element struct {
									Text     string `xml:",chardata"`
									Type     string `xml:"Type,attr"`
									Name     string `xml:"Name,attr"`
									Property []struct {
										Text  string `xml:",chardata"`
										Name  string `xml:"Name,attr"`
										Value string `xml:"Value,attr"`
									} `xml:"Property"`
									Relationship struct {
										Text  string `xml:",chardata"`
										Name  string `xml:"Name,attr"`
										Entry struct {
											Text       string `xml:",chardata"`
											References struct {
												Text           string `xml:",chardata"`
												ExternalSource string `xml:"ExternalSource,attr"`
												Name           string `xml:"Name,attr"`
											} `xml:"References"`
											Element struct {
												Text         string `xml:",chardata"`
												Type         string `xml:"Type,attr"`
												Relationship struct {
													Text  string `xml:",chardata"`
													Name  string `xml:"Name,attr"`
													Entry struct {
														Text       string `xml:",chardata"`
														References struct {
															Text           string `xml:",chardata"`
															ExternalSource string `xml:"ExternalSource,attr"`
															Name           string `xml:"Name,attr"`
														} `xml:"References"`
													} `xml:"Entry"`
												} `xml:"Relationship"`
												Property []struct {
													Text  string `xml:",chardata"`
													Name  string `xml:"Name,attr"`
													Value string `xml:"Value,attr"`
												} `xml:"Property"`
											} `xml:"Element"`
											Annotation []struct {
												Text     string `xml:",chardata"`
												Type     string `xml:"Type,attr"`
												Name     string `xml:"Name,attr"`
												Property []struct {
													Text  string `xml:",chardata"`
													Name  string `xml:"Name,attr"`
													Value string `xml:"Value,attr"`
												} `xml:"Property"`
											} `xml:"Annotation"`
										} `xml:"Entry"`
									} `xml:"Relationship"`
								} `xml:"Element"`
								Annotation []struct {
									Text     string `xml:",chardata"`
									Type     string `xml:"Type,attr"`
									Name     string `xml:"Name,attr"`
									Property []struct {
										Text  string `xml:",chardata"`
										Name  string `xml:"Name,attr"`
										Value string `xml:"Value,attr"`
									} `xml:"Property"`
								} `xml:"Annotation"`
							} `xml:"Entry"`
						} `xml:"Relationship"`
						Property []struct {
							Text      string `xml:",chardata"`
							Name      string `xml:"Name,attr"`
							AttrValue string `xml:"Value,attr"`
							Value     struct {
								Text              string `xml:",chardata"`
								QuotedIdentifiers string `xml:"QuotedIdentifiers,attr"`
								AnsiNulls         string `xml:"AnsiNulls,attr"`
							} `xml:"Value"`
						} `xml:"Property"`
						AttachedAnnotation struct {
							Text          string `xml:",chardata"`
							Disambiguator string `xml:"Disambiguator,attr"`
						} `xml:"AttachedAnnotation"`
						Annotation struct {
							Text     string `xml:",chardata"`
							Type     string `xml:"Type,attr"`
							Property []struct {
								Text  string `xml:",chardata"`
								Name  string `xml:"Name,attr"`
								Value string `xml:"Value,attr"`
							} `xml:"Property"`
						} `xml:"Annotation"`
					} `xml:"Element"`
					Annotation []struct {
						Text     string `xml:",chardata"`
						Type     string `xml:"Type,attr"`
						Name     string `xml:"Name,attr"`
						Property []struct {
							Text  string `xml:",chardata"`
							Name  string `xml:"Name,attr"`
							Value string `xml:"Value,attr"`
						} `xml:"Property"`
					} `xml:"Annotation"`
				} `xml:"Entry"`
			} `xml:"Relationship"`
			Annotation []struct {
				Text          string `xml:",chardata"`
				Type          string `xml:"Type,attr"`
				Name          string `xml:"Name,attr"`
				Disambiguator string `xml:"Disambiguator,attr"`
				Property      []struct {
					Text  string `xml:",chardata"`
					Name  string `xml:"Name,attr"`
					Value string `xml:"Value,attr"`
				} `xml:"Property"`
			} `xml:"Annotation"`
			AttachedAnnotation []struct {
				Text          string `xml:",chardata"`
				Disambiguator string `xml:"Disambiguator,attr"`
			} `xml:"AttachedAnnotation"`
		} `xml:"Element"`
	} `xml:"Model"`
}

DataSchemaModel is for containing the contents of the model.xml file. Structure generated using https://github.com/miku/zek/ ~/go/bin/zek -p < extracted/model.xml > model.go

type ExtractedColumn

type ExtractedColumn struct {
	ColName    string
	DataType   int
	DtStr      string
	Length     int
	Scale      int
	Precision  int
	IsNullable bool
	IsNull     bool
	Str        string
}

ExtractedColumn contains the data/metadata for a column extracted from a row of data.

type ExtractedModel

type ExtractedModel struct {
	Collation              string
	CollationCaseSensitive bool
	FileFormatVersion      string
	SchemaVersion          string
	DspName                string
	Tables                 map[string]Table
	// contains filtered or unexported fields
}

ExtractedModel contains the model data needed for identifying, and extracting the data from, all the exported tables

type ForeignKey

type ForeignKey struct {
	ConsName   string
	Columns    []string
	RefTable   string
	RefColumns []string
}

type Table

type Table struct {
	Schema  string
	TabName string
	PK      UniqueConstraint
	Columns []TableColumn
	FKs     []ForeignKey
	Unique  []UniqueConstraint
	// contains filtered or unexported fields
}

Table struct contains the definition for an exported database table

func (*Table) DataReader

func (t *Table) DataReader() (reader tReader, err error)

DataReader creates a multi-file-reader on the data files for the specified table

type TableColumn

type TableColumn struct {
	ColName       string
	DataType      int
	DtStr         string
	Length        int
	Scale         int
	Precision     int
	IsNullable    bool
	IsAdulterated bool // flag to indicate if the byte-stream for the column is supected of having been messed with
}

TableColumn struct contains the definition for an exported database column

type UniqueConstraint

type UniqueConstraint struct {
	ConsName string
	Columns  []string
}

type UserDefinedType

type UserDefinedType struct {
	Schema     string
	Name       string
	DataType   int
	DtStr      string
	Length     int
	Scale      int
	Precision  int
	IsNullable bool
}

UserDefinedType struct contains the definition for an exported user defined type. This is used for mapping table columns of type <user defined type> to the underlying base data type

Jump to

Keyboard shortcuts

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