Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions internal/endtoend/testdata/insert_values/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/endtoend/testdata/insert_values/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ CREATE TABLE foo (a text, b integer);

/* name: InsertValues :exec */
INSERT INTO foo (a, b) VALUES (?, ?);

/* name: InsertMultipleValues :exec */
INSERT INTO foo (a, b) VALUES (?, ?), (?, ?);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ CREATE TABLE foo (a text, b integer);

-- name: InsertValues :exec
INSERT INTO foo (a, b) VALUES ($1, $2);

/* name: InsertMultipleValues :exec */
INSERT INTO foo (a, b) VALUES ($1, $2), ($3, $4);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ CREATE TABLE foo (a text, b integer);

-- name: InsertValues :exec
INSERT INTO foo (a, b) VALUES ($1, $2);

/* name: InsertMultipleValues :exec */
INSERT INTO foo (a, b) VALUES ($1, $2), ($3, $4);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ CREATE TABLE foo (a text, b integer);

-- name: InsertValues :exec
INSERT INTO foo (a, b) VALUES ($1, $2);

/* name: InsertMultipleValues :exec */
INSERT INTO foo (a, b) VALUES ($1, $2), ($3, $4);
21 changes: 21 additions & 0 deletions internal/endtoend/testdata/insert_values/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/endtoend/testdata/insert_values/sqlite/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ CREATE TABLE foo (a text, b integer);

/* name: InsertValues :exec */
INSERT INTO foo (a, b) VALUES (?, ?);

/* name: InsertMultipleValues :exec */
INSERT INTO foo (a, b) VALUES (?, ?), (?, ?);
38 changes: 26 additions & 12 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,27 +882,41 @@ func (c *cc) convertInsert_stmtContext(n *parser.Insert_stmtContext) ast.Node {
insert.SelectStmt = ss
}
} else {
var valuesLists ast.List
var values *ast.List
for _, cn := range n.GetChildren() {
switch cn := cn.(type) {
case antlr.TerminalNode:
switch cn.GetSymbol().GetTokenType() {
case parser.SQLiteParserVALUES_:
values = &ast.List{}
case parser.SQLiteParserOPEN_PAR:
if values != nil {
values = &ast.List{}
}
case parser.SQLiteParserCOMMA:
case parser.SQLiteParserCLOSE_PAR:
if values != nil {
valuesLists.Items = append(valuesLists.Items, values)
}
}
case parser.IExprContext:
if values != nil {
values.Items = append(values.Items, c.convert(cn))
}
}
}

insert.SelectStmt = &ast.SelectStmt{
FromClause: &ast.List{},
TargetList: &ast.List{},
ValuesLists: c.convertExprLists(n.AllExpr()),
ValuesLists: &valuesLists,
}
}

return insert
}

func (c *cc) convertExprLists(lists []parser.IExprContext) *ast.List {
list := &ast.List{Items: []ast.Node{}}
n := len(lists)
inner := &ast.List{Items: []ast.Node{}}
for i := 0; i < n; i++ {
inner.Items = append(inner.Items, c.convert(lists[i]))
}
list.Items = append(list.Items, inner)
return list
}

func (c *cc) convertColumnNames(cols []parser.IColumn_nameContext) *ast.List {
list := &ast.List{Items: []ast.Node{}}
for _, c := range cols {
Expand Down