Skip to content

why would you lie like that? #194

@farnoy

Description

@farnoy

Written in Go
Enjoy TiDB as much as we love Go. We believe Go code is both easy and enjoyable to work with. Go makes us improve TiDB fast and makes it easy to dive into the codebase.

func executeLine(tx *sql.Tx, txnLine string) error {
    if tidb.IsQuery(txnLine) {
        rows, err := tx.Query(txnLine)
        if err != nil {
            return errors.Trace(err)
        }
        defer rows.Close()
        cols, err := rows.Columns()
        if err != nil {
            return errors.Trace(err)
        }

        values := make([][]byte, len(cols))
        scanArgs := make([]interface{}, len(values))
        for i := range values {
            scanArgs[i] = &values[i]
        }

        var datas [][]string
        for rows.Next() {
            err := rows.Scan(scanArgs...)
            if err != nil {
                return errors.Trace(err)
            }

            data := make([]string, len(cols))
            for i, value := range values {
                if value == nil {
                    data[i] = "NULL"
                } else {
                    data[i] = string(value)
                }
            }

            datas = append(datas, data)
        }

        // For `cols` and `datas[i]` always has the same length,
        // no need to check return validity.
        result, _ := printer.GetPrintResult(cols, datas)
        fmt.Printf("%s", result)

        if err := rows.Err(); err != nil {
            return errors.Trace(err)
        }
    } else {
        // TODO: rows affected and last insert id
        _, err := tx.Exec(txnLine)
        if err != nil {
            return errors.Trace(err)
        }
    }
    return nil
}

Literally the first file I opened.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions