MCPcopy Index your code
hub / github.com/dropbox/godropbox / String

Method String

database/sqlbuilder/statement.go:386–466  ·  view source on GitHub ↗

Return the properly escaped SQL statement, against the specified database

(database string)

Source from the content-addressed store, hash-verified

384
385// Return the properly escaped SQL statement, against the specified database
386func (q *selectStatementImpl) String(database string) (sql string, err error) {
387 if !validIdentifierName(database) {
388 return "", errors.New("Invalid database name specified")
389 }
390
391 buf := new(bytes.Buffer)
392 _, _ = buf.WriteString("SELECT ")
393
394 if err = writeComment(q.comment, buf); err != nil {
395 return
396 }
397
398 if q.distinct {
399 _, _ = buf.WriteString("DISTINCT ")
400 }
401
402 if q.projections == nil || len(q.projections) == 0 {
403 return "", errors.Newf(
404 "No column selected. Generated sql: %s",
405 buf.String())
406 }
407
408 for i, col := range q.projections {
409 if i > 0 {
410 _ = buf.WriteByte(',')
411 }
412 if col == nil {
413 return "", errors.Newf(
414 "nil column selected. Generated sql: %s",
415 buf.String())
416 }
417 if err = col.SerializeSqlForColumnList(buf); err != nil {
418 return
419 }
420 }
421
422 _, _ = buf.WriteString(" FROM ")
423 if q.table == nil {
424 return "", errors.Newf("nil table. Generated sql: %s", buf.String())
425 }
426 if err = q.table.SerializeSql(database, buf); err != nil {
427 return
428 }
429
430 if q.where != nil {
431 _, _ = buf.WriteString(" WHERE ")
432 if err = q.where.SerializeSql(buf); err != nil {
433 return
434 }
435 }
436
437 if q.group != nil {
438 _, _ = buf.WriteString(" GROUP BY ")
439 if err = q.group.SerializeSql(buf); err != nil {
440 return
441 }
442 }
443

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewfFunction · 0.92
validIdentifierNameFunction · 0.85
writeCommentFunction · 0.85
StringMethod · 0.65
SerializeSqlMethod · 0.65

Tested by

no test coverage detected