Ejemplo n.º 1
0
func (si *SchemaInfo) Open(connFactory dbconnpool.CreateConnectionFunc, schemaOverrides []SchemaOverride, cachePool *CachePool, strictMode bool) {
	si.connPool.Open(connFactory)
	// Get time first because it needs a connection from the pool.
	curTime := si.mysqlTime()

	conn := getOrPanic(si.connPool)
	defer conn.Recycle()

	if strictMode && !conn.(*dbconnpool.PooledDBConnection).VerifyStrict() {
		panic(NewTabletError(FATAL, "Could not verify strict mode"))
	}

	si.cachePool = cachePool
	tables, err := conn.ExecuteFetch(base_show_tables, maxTableCount, false)
	if err != nil {
		panic(NewTabletError(FATAL, "Could not get table list: %v", err))
	}

	si.tables = make(map[string]*TableInfo, len(tables.Rows))
	// TODO(sougou): Fix this in the parser.
	si.tables["dual"] = &TableInfo{Table: schema.NewTable("dual")}
	si.tables["DUAL"] = &TableInfo{Table: schema.NewTable("DUAL")}
	for _, row := range tables.Rows {
		tableName := row[0].String()
		tableInfo, err := NewTableInfo(
			conn,
			tableName,
			row[1].String(), // table_type
			row[2],          // create_time
			row[3].String(), // table_comment
			si.cachePool,
		)
		if err != nil {
			panic(NewTabletError(FATAL, "Could not get load table %s: %v", tableName, err))
		}
		si.tables[tableName] = tableInfo
	}
	if schemaOverrides != nil {
		si.overrides = schemaOverrides
		si.override()
	}
	si.lastChange = curTime
	// Clear is not really needed. Doing it for good measure.
	si.queries.Clear()
	si.ticks.Start(func() { si.Reload() })
}
Ejemplo n.º 2
0
func createTableInfo(name string, cols map[string]string, pKeys []string) TableInfo {
	table := schema.NewTable(name)
	for colName, colType := range cols {
		table.AddColumn(colName, colType, sqltypes.Value{}, "")
	}
	tableInfo := TableInfo{Table: table}
	tableInfo.SetPK(pKeys)
	return tableInfo
}
Ejemplo n.º 3
0
func loadTableInfo(conn dbconnpool.PoolConnection, tableName string) (ti *TableInfo, err error) {
	ti = &TableInfo{Table: schema.NewTable(tableName)}
	if err = ti.fetchColumns(conn); err != nil {
		return nil, err
	}
	if err = ti.fetchIndexes(conn); err != nil {
		return nil, err
	}
	return ti, nil
}