示例#1
0
func (m *SchemaDb) tableForVariables(table string) (*schema.Table, error) {
	// This table doesn't belong in schema
	ss := m.is.SchemaSources["schema"]
	t := schema.NewTable("variables", ss)
	t.AddField(schema.NewFieldBase("Variable_name", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Value", value.StringType, 64, "string"))
	t.SetColumns(schema.ShowVariablesColumns)
	return t, nil
}
示例#2
0
func (m *CsvDataSource) Table(tableName string) (*schema.Table, error) {
	if m.tblschema != nil {
		return m.tblschema, nil
	}
	m.tblschema = schema.NewTable(tableName, nil)
	for _, col := range m.Columns() {
		m.tblschema.AddField(schema.NewFieldBase(col, value.StringType, 64, "string"))
	}
	m.tblschema.SetColumns(m.Columns())
	return m.tblschema, nil
}
示例#3
0
func (m *SchemaDb) tableForTables() (*schema.Table, error) {
	// This table doesn't belong in schema
	ss := m.is.SchemaSources["schema"]

	//u.Debugf("schema:%p  table create infoschema:%p  ", m.s, m.is)
	t := schema.NewTable("tables", ss)
	t.AddField(schema.NewFieldBase("Table", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Table_type", value.StringType, 64, "string"))

	cols := schema.ShowTableColumns
	for _, col := range DialectWriterCols {
		cols = append(cols, fmt.Sprintf("%s_create", col))
	}
	t.SetColumns(cols)

	ss.AddTable(t)
	rows := make([][]driver.Value, len(m.s.Tables()))
	for i, tableName := range m.s.Tables() {
		rows[i] = []driver.Value{tableName, "BASE TABLE"}
		tbl, err := m.s.Table(tableName)
		if tbl != nil && len(tbl.Columns()) > 0 && len(tbl.Fields) == 0 {
			// I really don't like where this is, needs to be in schema somewhere
			m.inspect(tbl.Name)
		} else {
			//u.Warnf("NOT INSPECTING")
		}
		for _, writer := range DialectWriters {
			if err != nil {
				rows[i] = append(rows[i], "error")
			} else {
				rows[i] = append(rows[i], writer.Table(tbl))
				//u.Debugf("%s", rows[i][len(rows[i])-1])
			}
		}

	}
	//u.Debugf("set rows: %v for tables: %v", rows, m.s.Tables())
	t.SetRows(rows)
	return t, nil
}
示例#4
0
func (m *SchemaDb) tableForDatabases() (*schema.Table, error) {
	ss := m.is.SchemaSources["schema"]

	t := schema.NewTable("databases", ss)
	t.AddField(schema.NewFieldBase("Database", value.StringType, 64, "string"))
	t.SetColumns(schema.ShowDatabasesColumns)
	rows := make([][]driver.Value, 0, len(registry.schemas))
	for db, _ := range registry.schemas {
		rows = append(rows, []driver.Value{db})
	}
	t.SetRows(rows)
	ss.AddTable(t)
	return t, nil
}
示例#5
0
func (m *SchemaDb) tableForTable(table string) (*schema.Table, error) {

	ss := m.is.SchemaSources["schema"]
	tbl, hasTable := m.tableMap[table]
	//u.Debugf("s:%p infoschema:%p creating schema table for %q", m.s, m.is, table)
	if hasTable {
		//u.Infof("found existing table %q", table)
		return tbl, nil
	}
	srcTbl, err := m.s.Table(table)
	if err != nil {
		u.Errorf("no table? err=%v for=%s", err, table)
	}
	if len(srcTbl.Columns()) > 0 && len(srcTbl.Fields) == 0 {
		// I really don't like where/how this gets called
		//    needs to be in schema somewhere?
		m.inspect(table)
	} else {
		//u.Warnf("NOT INSPECTING")
	}
	//u.Infof("found srcTable %v fields?%v", srcTbl.Columns(), len(srcTbl.Fields))
	t := schema.NewTable(table, ss)
	t.AddField(schema.NewFieldBase("Field", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Type", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Collation", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Null", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Key", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Default", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Extra", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Privileges", value.StringType, 64, "string"))
	t.AddField(schema.NewFieldBase("Comment", value.StringType, 64, "string"))
	t.SetColumns(schema.DescribeFullCols)
	rows := srcTbl.AsRows()
	//u.Debugf("found rows: %v", rows)
	t.SetRows(rows)

	ss.AddTable(t)
	m.tableMap[table] = t
	return t, nil
}