MCPcopy
hub / github.com/sqlc-dev/sqlc / convertInsert_stmtContext

Method convertInsert_stmtContext

internal/engine/sqlite/convert.go:960–1035  ·  view source on GitHub ↗
(n *parser.Insert_stmtContext)

Source from the content-addressed store, hash-verified

958}
959
960func (c *cc) convertInsert_stmtContext(n *parser.Insert_stmtContext) ast.Node {
961 tableName := identifier(n.Table_name().GetText())
962 rel := &ast.RangeVar{
963 Relname: &tableName,
964 }
965 if n.Schema_name() != nil {
966 schemaName := n.Schema_name().GetText()
967 rel.Schemaname = &schemaName
968 }
969 if n.Table_alias() != nil {
970 tableAlias := identifier(n.Table_alias().GetText())
971 rel.Alias = &ast.Alias{
972 Aliasname: &tableAlias,
973 }
974 }
975
976 insert := &ast.InsertStmt{
977 Relation: rel,
978 Cols: c.convertColumnNames(n.AllColumn_name()),
979 ReturningList: c.convertReturning_caluseContext(n.Returning_clause()),
980 }
981
982 // Check if this is a DEFAULT VALUES insert
983 hasDefaultValues := false
984 for _, child := range n.GetChildren() {
985 if term, ok := child.(antlr.TerminalNode); ok {
986 if term.GetSymbol().GetTokenType() == parser.SQLiteParserDEFAULT_ {
987 hasDefaultValues = true
988 break
989 }
990 }
991 }
992
993 if hasDefaultValues {
994 // For DEFAULT VALUES, set the flag instead of creating an empty values list
995 insert.DefaultValues = true
996 } else if n.Select_stmt() != nil {
997 if ss, ok := c.convert(n.Select_stmt()).(*ast.SelectStmt); ok {
998 ss.ValuesLists = &ast.List{}
999 insert.SelectStmt = ss
1000 }
1001 } else {
1002 var valuesLists ast.List
1003 var values *ast.List
1004 for _, cn := range n.GetChildren() {
1005 switch cn := cn.(type) {
1006 case antlr.TerminalNode:
1007 switch cn.GetSymbol().GetTokenType() {
1008 case parser.SQLiteParserVALUES_:
1009 values = &ast.List{}
1010 case parser.SQLiteParserOPEN_PAR:
1011 if values != nil {
1012 values = &ast.List{}
1013 }
1014 case parser.SQLiteParserCOMMA:
1015 case parser.SQLiteParserCLOSE_PAR:
1016 if values != nil {
1017 valuesLists.Items = append(valuesLists.Items, values)

Callers 1

convertMethod · 0.95

Calls 11

convertColumnNamesMethod · 0.95
convertMethod · 0.95
GetTextMethod · 0.80
identifierFunction · 0.70
Table_nameMethod · 0.65
Schema_nameMethod · 0.65
Table_aliasMethod · 0.65
AllColumn_nameMethod · 0.65
Returning_clauseMethod · 0.65
Select_stmtMethod · 0.65

Tested by

no test coverage detected