MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / main

Function main

examples/error-demo/main.go:24–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22)
23
24func main() {
25 fmt.Println("==========================================================")
26 fmt.Println("GoSQLX Enhanced Error Messages Demonstration")
27 fmt.Println("==========================================================")
28 fmt.Println()
29
30 // Example 1: Simple typo in single-line SQL
31 fmt.Println("Example 1: Common Typo Detection")
32 fmt.Println("----------------------------------------------------------")
33 sql1 := "SELECT * FORM users WHERE age > 18"
34 err1 := errors.ExpectedTokenError("FROM", "FORM", models.Location{Line: 1, Column: 10}, sql1)
35 fmt.Println(err1.Error())
36 fmt.Println()
37
38 // Example 2: Multi-line SQL with invalid number
39 fmt.Println("Example 2: Multi-line SQL with Invalid Number")
40 fmt.Println("----------------------------------------------------------")
41 sql2 := `SELECT id, name, email
42FROM users
43WHERE age > 18.45.6
44ORDER BY name`
45 err2 := errors.InvalidNumberError("18.45.6", models.Location{Line: 3, Column: 13}, sql2)
46 fmt.Println(err2.Error())
47 fmt.Println()
48
49 // Example 3: Unterminated string
50 fmt.Println("Example 3: Unterminated String Literal")
51 fmt.Println("----------------------------------------------------------")
52 sql3 := "SELECT * FROM users WHERE name = 'John"
53 err3 := errors.UnterminatedStringError(models.Location{Line: 1, Column: 34}, sql3)
54 fmt.Println(err3.Error())
55 fmt.Println()
56
57 // Example 4: Missing clause in complex query
58 fmt.Println("Example 4: Missing Required Clause")
59 fmt.Println("----------------------------------------------------------")
60 sql4 := `SELECT u.id, u.name, o.total
61 users u
62JOIN orders o ON u.id = o.user_id
63WHERE u.active = true`
64 err4 := errors.MissingClauseError("FROM", models.Location{Line: 2, Column: 5}, sql4)
65 fmt.Println(err4.Error())
66 fmt.Println()
67
68 // Example 5: Incomplete statement
69 fmt.Println("Example 5: Incomplete SQL Statement")
70 fmt.Println("----------------------------------------------------------")
71 sql5 := "SELECT * FROM users WHERE"
72 err5 := errors.IncompleteStatementError(models.Location{Line: 1, Column: 26}, sql5)
73 fmt.Println(err5.Error())
74 fmt.Println()
75
76 // Example 6: Unexpected character
77 fmt.Println("Example 6: Unexpected Character")
78 fmt.Println("----------------------------------------------------------")
79 sql6 := "SELECT * FROM users WHERE age > 18 & active = 1"
80 err6 := errors.UnexpectedCharError('&', models.Location{Line: 1, Column: 36}, sql6)
81 fmt.Println(err6.Error())

Callers

nothing calls this directly

Calls 10

ExpectedTokenErrorFunction · 0.92
InvalidNumberErrorFunction · 0.92
UnterminatedStringErrorFunction · 0.92
MissingClauseErrorFunction · 0.92
IncompleteStatementErrorFunction · 0.92
UnexpectedCharErrorFunction · 0.92
SuggestKeywordFunction · 0.92
GetMistakeExplanationFunction · 0.92
FormatMistakeExampleFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected