MCPcopy Create free account
hub / github.com/bytebase/bytebase / SQLToWriter

Function SQLToWriter

backend/component/export/sql.go:26–52  ·  view source on GitHub ↗

SQLToWriter streams SQL INSERT statements directly to the writer.

(w io.Writer, engine storepb.Engine, statementPrefix string, result *v1pb.QueryResult)

Source from the content-addressed store, hash-verified

24
25// SQLToWriter streams SQL INSERT statements directly to the writer.
26func SQLToWriter(w io.Writer, engine storepb.Engine, statementPrefix string, result *v1pb.QueryResult) error {
27 for i, row := range result.Rows {
28 if _, err := w.Write([]byte(statementPrefix)); err != nil {
29 return err
30 }
31 for j, value := range row.Values {
32 if j != 0 {
33 if _, err := w.Write([]byte{','}); err != nil {
34 return err
35 }
36 }
37 if _, err := w.Write(convertValueToBytesInSQL(engine, value)); err != nil {
38 return err
39 }
40 }
41 if i != len(result.Rows)-1 {
42 if _, err := w.Write([]byte(");\n")); err != nil {
43 return err
44 }
45 } else {
46 if _, err := w.Write([]byte(");")); err != nil {
47 return err
48 }
49 }
50 }
51 return nil
52}
53
54// SQLStatementPrefix generates the INSERT INTO statement prefix.
55func SQLStatementPrefix(engine storepb.Engine, resourceList []base.SchemaResource, columnNames []string) (string, error) {

Callers 3

exportSQLWithContextMethod · 0.92
exportSQLWithContextFunction · 0.92
SQLFunction · 0.85

Calls 1

convertValueToBytesInSQLFunction · 0.85

Tested by

no test coverage detected