feat(sql): SQL Injection
This commit is contained in:
@@ -4,23 +4,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.secnex.io/secnex/pgson/schema"
|
||||
"git.secnex.io/secnex/pgson/utils"
|
||||
"git.secnex.io/secnex/pgson/sql"
|
||||
)
|
||||
|
||||
func TruncateSQL(s *schema.Table, cascade bool, restartIdentity bool) (string, error) {
|
||||
if s == nil {
|
||||
return "", fmt.Errorf("nil table provided")
|
||||
func TruncateTable(s *schema.Table) (*string, error) {
|
||||
if err := sql.ValidateIdent(s.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.Name == "" || !utils.IsValidIdentifier(s.Name) {
|
||||
return "", fmt.Errorf("invalid table name: %q", s.Name)
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("TRUNCATE TABLE %s", utils.SQLQuoteIdent(s.Name))
|
||||
if restartIdentity {
|
||||
query += " RESTART IDENTITY"
|
||||
}
|
||||
if cascade {
|
||||
query += " CASCADE"
|
||||
}
|
||||
return query, nil
|
||||
ddl := fmt.Sprintf(sql.DDL_TRUNCATE_TABLE, sql.QuoteIdent(s.Name))
|
||||
return &ddl, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user