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

Method convertLiteral

internal/engine/clickhouse/convert.go:387–447  ·  view source on GitHub ↗
(n *chast.Literal)

Source from the content-addressed store, hash-verified

385}
386
387func (c *cc) convertLiteral(n *chast.Literal) *ast.A_Const {
388 switch n.Type {
389 case chast.LiteralString:
390 str := n.Value.(string)
391 return &ast.A_Const{
392 Val: &ast.String{Str: str},
393 Location: n.Pos().Offset,
394 }
395 case chast.LiteralInteger:
396 var ival int64
397 switch v := n.Value.(type) {
398 case int64:
399 ival = v
400 case int:
401 ival = int64(v)
402 case float64:
403 ival = int64(v)
404 case string:
405 ival, _ = strconv.ParseInt(v, 10, 64)
406 }
407 return &ast.A_Const{
408 Val: &ast.Integer{Ival: ival},
409 Location: n.Pos().Offset,
410 }
411 case chast.LiteralFloat:
412 var fval float64
413 switch v := n.Value.(type) {
414 case float64:
415 fval = v
416 case string:
417 fval, _ = strconv.ParseFloat(v, 64)
418 }
419 str := strconv.FormatFloat(fval, 'f', -1, 64)
420 return &ast.A_Const{
421 Val: &ast.Float{Str: str},
422 Location: n.Pos().Offset,
423 }
424 case chast.LiteralBoolean:
425 // ClickHouse booleans are typically 0/1
426 bval := n.Value.(bool)
427 if bval {
428 return &ast.A_Const{
429 Val: &ast.Integer{Ival: 1},
430 Location: n.Pos().Offset,
431 }
432 }
433 return &ast.A_Const{
434 Val: &ast.Integer{Ival: 0},
435 Location: n.Pos().Offset,
436 }
437 case chast.LiteralNull:
438 return &ast.A_Const{
439 Val: &ast.Null{},
440 Location: n.Pos().Offset,
441 }
442 default:
443 return &ast.A_Const{
444 Location: n.Pos().Offset,

Callers 1

convertExprMethod · 0.95

Calls 1

PosMethod · 0.65

Tested by

no test coverage detected